RE: RE: Modify Manufacturer ID and Auxiliary Firmware Revision

https://cern-ipmc-forum.web.cern.ch/t/re-modify-manufacturer-id-and-auxiliary-firmware-revision/343/2

Unfortunately, I’m not the owner or maintainer of this project.

So here is a snippet of code:

/*
 * Convert the compilation (build) date from a string literal of
 * the form "Mmm dd ccyy" to Binary Coded Decimal.
 */
#define __MONTH_H__ ((__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x119 ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x10d ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x120 ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x123 ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x127 ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x12d ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x12b ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x11d ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x128 ? 0x0  : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x126 ? 0x10 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x133 ? 0x10 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x10c ? 0x10 : \
                     0)

#define __MONTH_L__ ((__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x119 ? 0x1 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x10d ? 0x2 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x120 ? 0x3 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x123 ? 0x4 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x127 ? 0x5 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x12d ? 0x6 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x12b ? 0x7 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x11d ? 0x8 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x128 ? 0x9 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x126 ? 0x0 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x133 ? 0x1 : \
                     (__DATE__[0] + __DATE__[1] + __DATE__[2]) == 0x10c ? 0x2 : \
                     0)

#define __CENTURY__ (((__DATE__[7] - '0') << 4) + (__DATE__[8] - '0'))
#define __YEAR__    (((__DATE__[9] - '0') << 4) + (__DATE__[10] - '0'))
#define __DAY__     (((__DATE__[4] - '0') << 4) + (__DATE__[5] - '0'))
#define __MONTH__   (__MONTH_H__ + __MONTH_L__)

#if 0
/*
 * The Auxiliary Firmware Revision Information field is optional. If present,
 * it holds additional information about the firmware revision, such as boot
 * block or internal data structure version numbers.
 * The meanings of the numbers are specific to the vendor identified
 * by Manufacturer ID.
 */
#define CFG_APP_FIRMWARE_AUX_REV1 __CENTURY__
#define CFG_APP_FIRMWARE_AUX_REV2 __YEAR__
#define CFG_APP_FIRMWARE_AUX_REV3 __MONTH__
#define CFG_APP_FIRMWARE_AUX_REV4 __DAY__
#endif

Hello Fatih,

thanks, I tested it myself and checked the line the compiler is
complaining about (see below). Apparently there is a limitation in the C
pre-processor which does not allow strings to be used in an expression:

ipmc-core/app/master/ipmi.c:99: error: token "“Nov 26 2024"” is not valid in pre-processor expressions

I suggest you use a script to generate the hex values for the auxiliary
firmware revision instead of using pre-processor macros, in this case it
will work.

cheers,

Stefan

#if !((CFG_APP_FIRMWARE_AUX_REV1 == 0) &&
(CFG_APP_FIRMWARE_AUX_REV2 == 0) &&
(CFG_APP_FIRMWARE_AUX_REV3 == 0) &&
(CFG_APP_FIRMWARE_AUX_REV4 == 0))

···

On 26/11/2024 09:42, Fatih Bellachia via CERN IPMC wrote:

/* * Convert the compilation (build) date from a string literal of *
the form “Mmm dd ccyy” to Binary Coded Decimal. / #define MONTH_H
((DATE[0] + DATE[1] + DATE[2]) == 0x119 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x10d ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x120 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x123 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x127 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x12d ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x12b ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x11d ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x128 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x126 ? 0x10 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x133 ? 0x10 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x10c ? 0x10 : \ 0)
#define MONTH_L ((DATE[0] + DATE[1] + DATE[2]) ==
0x119 ? 0x1 : \ (DATE[0] + DATE[1] + DATE[2]) == 0x10d ?
0x2 : \ (DATE[0] + DATE[1] + DATE[2]) == 0x120 ? 0x3 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x123 ? 0x4 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x127 ? 0x5 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x12d ? 0x6 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x12b ? 0x7 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x11d ? 0x8 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x128 ? 0x9 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x126 ? 0x0 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x133 ? 0x1 : \
(DATE[0] + DATE[1] + DATE[2]) == 0x10c ? 0x2 : \ 0)
#define CENTURY (((DATE[7] - ‘0’) << 4) + (DATE[8] - ‘0’))
#define YEAR (((DATE[9] - ‘0’) << 4) + (DATE[10] - ‘0’))
#define DAY (((DATE[4] - ‘0’) << 4) + (DATE[5] - ‘0’))
#define MONTH (MONTH_H + MONTH_L) #if 0 /
* The Auxiliary
Firmware Revision Information field is optional. If present, * it
holds additional information about the firmware revision, such as boot

  • block or internal data structure version numbers. * The meanings of
    the numbers are specific to the vendor identified * by Manufacturer
    ID. */ #define CFG_APP_FIRMWARE_AUX_REV1 CENTURY #define
    CFG_APP_FIRMWARE_AUX_REV2 YEAR #define CFG_APP_FIRMWARE_AUX_REV3
    MONTH #define CFG_APP_FIRMWARE_AUX_REV4 DAY #endif