diff options
-rw-r--r-- | src/include/bootloader/bootloader.H | 126 | ||||
-rw-r--r-- | src/include/bootloader/hbblreasoncodes.H | 4 | ||||
-rw-r--r-- | src/usr/pnor/pnor_utils.C | 49 |
3 files changed, 98 insertions, 81 deletions
diff --git a/src/include/bootloader/bootloader.H b/src/include/bootloader/bootloader.H index 74e2364ee..3c75770de 100644 --- a/src/include/bootloader/bootloader.H +++ b/src/include/bootloader/bootloader.H @@ -39,20 +39,100 @@ #include <kernel/terminate.H> #include <kernel/hbterminatetypes.H> #include <bootloader/bootloaderif.H> +#include <bootloader/bootloader_trace.H> +#include <bootloader/hbblreasoncodes.H> extern "C" void task_end_stub(); extern "C" void enterHBB(uint64_t i_hbb_hrmor, uint64_t i_hbb_offset); -#define assert(expr) \ +#define printk(format...) + +/** + * @brief Handle setting up to terminate Bootloader + * + * @param[in] i_moduleID ID for module where terminate is occurring + * @param[in] i_reasoncode Reason code for why terminating + * @param[in] i_word7 Data for SRC word 7 / @userdata2[0:31] + * (optional, default is 0) + * @param[in] i_word8 Data for SRC word 8 / @userdata2[32:63] + * (optional, default is 0) + * @param[in] i_executeTI Flag for calling terminateExecuteTI + * (optional, default is true) + * @param[in] i_failAddr Address associated with termination + * (SRC word 6 / @userdata1[32:63], + * optional, default is 0) + */ +inline void bl_terminate(uint8_t i_moduleID, + uint16_t i_reasoncode, + uint32_t i_word7 = 0, + uint32_t i_word8 = 0, + bool i_executeTI = true, + uint64_t i_failAddr = 0) +{ + termWriteSRC(TI_BOOTLOADER, + i_reasoncode, + i_failAddr); + + termModifySRC(i_moduleID, + i_word7, + i_word8); + + if(i_executeTI) + { + terminateExecuteTI(); + } +} + +/** + * @brief Macro to assert using bl_terminate + * + * Calls bl_terminate with default module id and reason code for assert + */ +#define __ASSERT() \ +{\ + bl_terminate(Bootloader::MOD_BOOTLOADER_ASSERT,Bootloader::RC_ASSERT);\ +} + +/** + * @brief Macro to assert with custom trace + * + * Calls Bootloader trace and assert macro + */ +#define __ASSERT_W_TRACE(trace) \ +{ \ + BOOTLOADER_TRACE(trace);\ + __ASSERT();\ +} + +/** + * @brief Macro to assert using bl_terminate with custom trace and reason code. + * + * Calls Bootloader trace and provides a custom reason code to bl_terminate + */ +#define __ASSERT_W_TRACE_RC(trace,rc) \ +{ \ + BOOTLOADER_TRACE(trace);\ + bl_terminate(Bootloader::MOD_BOOTLOADER_ASSERT, rc);\ +} + + +// Macro tricks to determine which assert macro to call +#define GET_MACRO(_1,_2,_3,FUNC,...) FUNC + +/** + * @brief Standard assert macro. + * + * Verifies condition, uses GET_MACRO to determine which assert macro to call. + * Supports asserting via bl_terminate with custom trace and/or reason code + */ +#define assert(expr, ...) \ {\ - if (unlikely(!(expr)))\ + if(unlikely(!(expr))) \ {\ - task_end_stub();\ + GET_MACRO(0, ##__VA_ARGS__, __ASSERT_W_TRACE_RC, __ASSERT_W_TRACE, __ASSERT)(__VA_ARGS__) \ }\ } -#define printk(format...) - namespace Bootloader{ /** * @brief Get the current HBBL HRMOR @@ -108,42 +188,6 @@ namespace Bootloader{ uint32_t i_size, MMIOLoadStoreSizes i_ld_st_size); - /** - * @brief Handle setting up to terminate Bootloader - * - * @param[in] i_moduleID ID for module where terminate is occurring - * @param[in] i_reasoncode Reason code for why terminating - * @param[in] i_word7 Data for SRC word 7 / @userdata2[0:31] - * (optional, default is 0) - * @param[in] i_word8 Data for SRC word 8 / @userdata2[32:63] - * (optional, default is 0) - * @param[in] i_executeTI Flag for calling terminateExecuteTI - * (optional, default is true) - * @param[in] i_failAddr Address associated with termination - * (SRC word 6 / @userdata1[32:63], - * optional, default is 0) - */ - inline void bl_terminate(uint8_t i_moduleID, - uint16_t i_reasoncode, - uint32_t i_word7 = 0, - uint32_t i_word8 = 0, - bool i_executeTI = true, - uint64_t i_failAddr = 0) - { - termWriteSRC(TI_BOOTLOADER, - i_reasoncode, - i_failAddr); - - termModifySRC(i_moduleID, - i_word7, - i_word8); - - if(i_executeTI) - { - terminateExecuteTI(); - } - } - /** @enum HbbLengths * @brief List of HBB lengths. * diff --git a/src/include/bootloader/hbblreasoncodes.H b/src/include/bootloader/hbblreasoncodes.H index e071c40b8..392b7e4b3 100644 --- a/src/include/bootloader/hbblreasoncodes.H +++ b/src/include/bootloader/hbblreasoncodes.H @@ -48,9 +48,7 @@ namespace Bootloader MOD_PNORACC_READTOC = 0x03, /**< bl_pnorAccess.C : read TOC */ MOD_PNORACC_GETHBBSECT = 0x04, /**< bl_pnorAccess.C : get HBB sect */ MOD_BOOTLOADER_VERIFY = 0x05, /**< bootloader.C : verifyContainer */ - MOD_BOOTLOADER_PNOR_SECID_TO_STR = 0x06, /**< pnor_utils.C : SectionIdToString */ - MOD_BOOTLOADER_PNOR_CMP_MAGIC_NUM = 0x07 /**< pnor_utils.C : cmpSecurebootMagicNumber */ - + MOD_BOOTLOADER_ASSERT = 0x06, /**< bootloader.H assert */ }; /** diff --git a/src/usr/pnor/pnor_utils.C b/src/usr/pnor/pnor_utils.C index d6e1ffad0..fc68fef6f 100644 --- a/src/usr/pnor/pnor_utils.C +++ b/src/usr/pnor/pnor_utils.C @@ -426,55 +426,30 @@ const char * PNOR::SectionIdToString( uint32_t i_secIdIndex ) static_assert (numEntries == (PNOR::NUM_SECTIONS), "Mismatch between number of SectionIds and correlating strings"); - // Bootloader does not support asserts + // Assert if accessing index out of array. + assert(i_secIdIndex < (PNOR::NUM_SECTIONS), #ifdef BOOTLOADER - if(i_secIdIndex >= (PNOR::NUM_SECTIONS)) - { - PNOR_UTIL_TRACE(BTLDR_TRC_UTILS_PNOR_SECID_OUT_OF_RANGE); - /*@ - * @errortype - * @moduleid Bootloader::MOD_BOOTLOADER_PNOR_SECID_TO_STR - * @reasoncode Bootloader::RC_PNOR_SECID_OUT_OF_RANGE - * @userdata1 Section ID requested - * @userdata2 Max index of Section id to string array - * @devdesc No String associated with PNOR section ID - * @custdesc A problem occurred while running processor - * boot code. - */ - bl_terminate(Bootloader::MOD_BOOTLOADER_PNOR_SECID_TO_STR, - Bootloader::RC_PNOR_SECID_OUT_OF_RANGE, - i_secIdIndex, - numEntries); - } + BTLDR_TRC_UTILS_PNOR_SECID_OUT_OF_RANGE, + Bootloader::RC_PNOR_SECID_OUT_OF_RANGE #else - // Assert if accessing index out of array. - assert(i_secIdIndex < (PNOR::NUM_SECTIONS), "SectionIdToString PNOR section id out of range"); + "SectionIdToString PNOR section id out of range" #endif + ); return SectionIdToStringArr[i_secIdIndex]; } bool PNOR::cmpSecurebootMagicNumber(const uint8_t* i_vaddr) { - // Bootloader does not support asserts + // Assert if accessing index out of array. + assert(i_vaddr != nullptr, #ifdef BOOTLOADER - if(i_vaddr == nullptr) - { - PNOR_UTIL_TRACE(BTLDR_TRC_UTILS_CMP_MAGIC_NUM_NULLPTR); - /*@ - * @errortype - * @moduleid Bootloader::MOD_BOOTLOADER_PNOR_CMP_MAGIC_NUM - * @reasoncode Bootloader::RC_PNOR_NULLPTR - * @devdesc Requested address to compare is a nullptr - * @custdesc A problem occurred while running processor - * boot code. - */ - bl_terminate(Bootloader::MOD_BOOTLOADER_PNOR_CMP_MAGIC_NUM, - Bootloader::RC_PNOR_NULLPTR); - } + BTLDR_TRC_UTILS_CMP_MAGIC_NUM_NULLPTR, + Bootloader::RC_PNOR_NULLPTR #else - assert(i_vaddr != nullptr, "cmpSecurebootMagicNumber requested address to compare is a nullptr "); + "cmpSecurebootMagicNumber requested address to compare is a nullptr" #endif + ); return memcmp(&ROM_MAGIC_NUMBER, i_vaddr, sizeof(ROM_MAGIC_NUMBER))==0; } |