diff options
-rw-r--r-- | board/hammer/board.c | 4 | ||||
-rw-r--r-- | common/system.c | 38 | ||||
-rw-r--r-- | include/system.h | 5 |
3 files changed, 21 insertions, 26 deletions
diff --git a/board/hammer/board.c b/board/hammer/board.c index 8b3de4268c..6b7a4029cf 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -303,7 +303,7 @@ int board_get_entropy(void *buffer, int len) /* * Generate a USB serial number from unique chip ID. */ -const char *board_read_serial(void) +__override const char *board_read_serial(void) { static char str[CONFIG_SERIALNO_LEN]; @@ -322,7 +322,7 @@ const char *board_read_serial(void) return str; } -int board_write_serial(const char *serialno) +__override int board_write_serial(const char *serialno) { return 0; } diff --git a/common/system.c b/common/system.c index 39390a9418..2a7059d455 100644 --- a/common/system.c +++ b/common/system.c @@ -1589,33 +1589,27 @@ int system_can_boot_ap(void) #ifdef CONFIG_SERIALNO_LEN /* By default, read serial number from flash, can be overridden. */ -#if defined(CONFIG_FLASH_PSTATE) && defined(CONFIG_FLASH_PSTATE_BANK) -__attribute__((weak)) -const char *board_read_serial(void) -{ - return flash_read_pstate_serial(); -} -#elif defined(CONFIG_OTP) -__attribute__((weak)) -const char *board_read_serial(void) +__overridable const char *board_read_serial(void) { - return otp_read_serial(); + if (IS_ENABLED(CONFIG_FLASH_PSTATE) && + IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) + return flash_read_pstate_serial(); + else if (IS_ENABLED(CONFIG_OTP)) + return otp_read_serial(); + else + return ""; } -#endif -#if defined(CONFIG_FLASH_PSTATE) && defined(CONFIG_FLASH_PSTATE_BANK) -__attribute__((weak)) -int board_write_serial(const char *serialno) -{ - return flash_write_pstate_serial(serialno); -} -#elif defined(CONFIG_OTP) -__attribute__((weak)) -int board_write_serial(const char *serialno) +__overridable int board_write_serial(const char *serialno) { - return otp_write_serial(serialno); + if (IS_ENABLED(CONFIG_FLASH_PSTATE) && + IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) + return flash_write_pstate_serial(serialno); + else if (IS_ENABLED(CONFIG_OTP)) + return otp_write_serial(serialno); + else + return EC_ERROR_UNIMPLEMENTED; } -#endif #endif /* CONFIG_SERIALNO_LEN */ diff --git a/include/system.h b/include/system.h index e1eec86998..17419007db 100644 --- a/include/system.h +++ b/include/system.h @@ -327,13 +327,14 @@ int system_get_chip_unique_id(uint8_t **id); * Optional board-level callback functions to read a unique serial number per * chip. Default implementation reads from flash/otp (flash/otp_read_serial). */ -const char *board_read_serial(void) __attribute__((weak)); +__override_proto const char *board_read_serial(void); /** * Optional board-level callback functions to write a unique serial number per * chip. Default implementation reads from flash/otp (flash/otp_write_serial). */ -int board_write_serial(const char *serial) __attribute__((weak)); +__override_proto int board_write_serial(const char *serial); + /* * Common bbram entries. Chips don't necessarily need to implement * all of these, error will be returned from system_get/set_bbram if |