diff --git a/drivers/bl702_driver/std_drv/inc/bl702_common.h b/drivers/bl702_driver/std_drv/inc/bl702_common.h index 008ed294..923ab3f7 100644 --- a/drivers/bl702_driver/std_drv/inc/bl702_common.h +++ b/drivers/bl702_driver/std_drv/inc/bl702_common.h @@ -49,6 +49,8 @@ #define ARCH_Delay_US BL702_Delay_US #define ARCH_Delay_MS BL702_Delay_MS +#define arch_delay_us BL702_Delay_US +#define arch_delay_ms BL702_Delay_MS void Interrupt_Handler_Register(IRQn_Type irq, pFunc interruptFun); void ASM_Delay_Us(uint32_t core, uint32_t cnt); diff --git a/examples/boot2_iap/bflb_eflash_loader_cmds.c b/examples/boot2_iap/bflb_eflash_loader_cmds.c index a884989f..e521253d 100644 --- a/examples/boot2_iap/bflb_eflash_loader_cmds.c +++ b/examples/boot2_iap/bflb_eflash_loader_cmds.c @@ -490,11 +490,11 @@ static int32_t bflb_eflash_loader_cmd_reset(uint16_t cmd, uint8_t *data, uint16_ bflb_eflash_loader_usart_wait_tx_idle(BFLB_EFLASH_LOADER_IF_TX_IDLE_TIMEOUT); /* add for bl702, will impact on boot pin read */ - hal_hbn_set_status_flag(0x594c440B); + hal_boot2_set_psmode_status(0x594c440B); /* FPGA POR RST NOT work,so add system reset */ bflb_platform_delay_us(10); - hal_sw_system_reset(); + hal_boot2_sw_system_reset(); return ret; } diff --git a/examples/boot2_iap/bflb_eflash_loader_uart.c b/examples/boot2_iap/bflb_eflash_loader_uart.c index ba2befa6..28a00577 100644 --- a/examples/boot2_iap/bflb_eflash_loader_uart.c +++ b/examples/boot2_iap/bflb_eflash_loader_uart.c @@ -37,12 +37,11 @@ #include "bflb_eflash_loader_cmds.h" #include "bflb_eflash_loader.h" #include "bflb_platform.h" +#include "blsp_port.h" #include "partition.h" #include "hal_uart.h" #include "drv_device.h" -#define LOCAL_FILE_NUM (0x0003) -#define UART_CLOCK (40000000) static uint32_t g_detected_baudrate; @@ -58,11 +57,19 @@ enum uart_index_type board_get_debug_uart_index(void) { return 1; } - +void bflb_dump_data(uint8_t * buf, uint32_t size) +{ + for(int i = 0; i fifo_threshold = 16; device_open(download_uart, DEVICE_OFLAG_STREAM_TX); } +#endif + +#if (BLSP_BOOT2_MODE == BOOT2_MODE_DEEP_DEBUG) + uart_register(0, "iap_download"); + download_uart = device_find("iap_download"); + + if (download_uart) { + UART_DEV(download_uart)->fifo_threshold = 16; + device_open(download_uart, DEVICE_OFLAG_STREAM_TX); + } + + uart_register(1, "debug_log"); + struct device *uart = device_find("debug_log"); + + if (uart) { + device_open(uart, DEVICE_OFLAG_STREAM_TX); + } +#endif + } void bflb_eflash_loader_usart_if_enable_int(void) -{ - struct device *uart = device_find("download_uart"); - - if (uart) { - device_close(uart); +{ + if (download_uart) { + device_close(download_uart); device_open(download_uart, DEVICE_OFLAG_STREAM_TX | DEVICE_OFLAG_INT_RX); - device_set_callback(uart, uart0_irq_callback); - device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT | UART_RTO_IT)); + device_set_callback(download_uart, uart0_irq_callback); + device_control(download_uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT | UART_RTO_IT)); } } void bflb_eflash_loader_usart_if_send(uint8_t *data, uint32_t len) { - device_write(download_uart, 0, data, len); + if(download_uart){ + device_write(download_uart, 0, data, len); + } + } int32_t bflb_eflash_loader_usart_if_wait_tx_idle(uint32_t timeout) @@ -146,7 +174,14 @@ static uint32_t *bflb_eflash_loader_usart_if_receive(uint32_t *recv_len, uint16_ static void bflb_eflash_loader_usart_if_deinit() { - struct device *uart = device_find("download_uart"); + struct device *uart; + uart = device_find("iap_download"); + + if (uart) { + device_close(uart); + } + + uart = device_find("debug_log"); if (uart) { device_close(uart); @@ -163,14 +198,14 @@ int32_t bflb_eflash_loader_uart_init() int32_t bflb_eflash_loader_uart_handshake_poll() { - uint8_t buf[128]; + uint8_t buf[UART_FIFO_LEN]; uint32_t i; uint32_t handshake_count = 0; uint32_t rcv_buf_len = 0; //rcv_buf_len = UART_ReceiveData(g_uart_if_id,buf,128); //struct device *download_uart = device_find("download_uart"); if (download_uart) { - rcv_buf_len = device_read(download_uart, 0, buf, 128); + rcv_buf_len = device_read(download_uart, 0, buf, UART_FIFO_LEN); } //while(1) @@ -199,17 +234,28 @@ int32_t bflb_eflash_loader_uart_handshake_poll() /*receive shake hanad signal*/ bflb_eflash_loader_usart_if_send((uint8_t *)"OK", 2); + //ARCH_Delay_MS(400); bflb_platform_delay_ms(400); - /* consume the remaining bytes when shake hand(0x55) if needed */ - rcv_buf_len = device_read(download_uart, 0, buf, 128); //UART_ReceiveData(g_uart_if_id,buf,128); - MSG("bflb_eflash_loader_usart_if_receive len %d\r\n", rcv_buf_len); + rcv_buf_len = device_read(download_uart, 0, buf, UART_FIFO_LEN); //UART_ReceiveData(g_uart_if_id,buf,128); + //MSG("bflb_eflash_loader_usart_if_receive len %d\r\n", rcv_buf_len); /*init rx info */ g_rx_buf_index = 0; g_rx_buf_len = 0; BL_WR_WORD(g_eflash_loader_readbuf[g_rx_buf_index], 0); - bflb_eflash_loader_usart_if_enable_int(); + +#if (BLSP_BOOT2_MODE == BOOT2_MODE_DEBUG) + bflb_platform_print_set(1); + device_unregister("debug_log"); + uart_register(0, "iap_download"); + download_uart = device_find("iap_download"); + if (download_uart) { + UART_DEV(download_uart)->fifo_threshold = 16; + device_open(download_uart, DEVICE_OFLAG_STREAM_TX); + } +#endif + bflb_eflash_loader_usart_if_enable_int(); return BFLB_EFLASH_LOADER_HANDSHAKE_SUSS; } @@ -270,7 +316,11 @@ void bflb_eflash_loader_main() MSG("bflb_eflash_loader_main\r\n"); pt_table_dump(); - pt_table_get_iap_para(&p_iap_param); + ret = pt_table_get_iap_para(&p_iap_param); + if(0 != ret){ + MSG("no valid partition table\r\n"); + return; + } bflb_eflash_loader_cmd_init(); while (1) { diff --git a/examples/boot2_iap/blsp_boot2_iap.c b/examples/boot2_iap/blsp_boot2_iap.c index f01bd53e..b88a6a42 100644 --- a/examples/boot2_iap/blsp_boot2_iap.c +++ b/examples/boot2_iap/blsp_boot2_iap.c @@ -35,86 +35,29 @@ */ #include "bflb_platform.h" +#include "bflb_eflash_loader_uart.h" #include "blsp_port.h" #include "blsp_bootinfo.h" #include "blsp_media_boot.h" -#include "partition.h" #include "blsp_boot_decompress.h" #include "blsp_common.h" +#include "blsp_version.h" +#include "partition.h" #include "softcrc.h" -#include "bflb_eflash_loader_uart.h" #include "hal_uart.h" #include "hal_flash.h" #include "hal_boot2.h" -#include "blsp_version.h" +#include "hal_clock.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ -/** @addtogroup BLSP_BOOT2 - * @{ - */ - -/** @defgroup BLSP_BOOT2_Private_Macros - * @{ - */ - -/*@} end of group BLSP_BOOT2_Private_Macros */ - -/** @defgroup BLSP_BOOT2_Private_Types - * @{ - */ - -/*@} end of group BLSP_BOOT2_Private_Types */ - -/** @defgroup BLSP_BOOT2_Private_Variables - * @{ - */ - -/*@} end of group BLSP_BOOT2_Private_Variables */ - -/** @defgroup BLSP_BOOT2_Global_Variables - * @{ - */ uint8_t g_boot2_read_buf[BFLB_BOOT2_READBUF_SIZE] __attribute__((section(".noinit_data"))); -boot_image_config g_boot_img_cfg[2]; -boot_cpu_config g_boot_cpu_cfg[2] = { - /*CPU0 boot cfg*/ - { - .msp_store_addr = 0, - .pc_store_addr = 0, - .default_xip_addr = 0x23000000, - }, - /*CPU1 boot cfg*/ - { - .msp_store_addr = BFLB_BOOT2_CPU1_APP_MSP_ADDR, - .pc_store_addr = BFLB_BOOT2_CPU1_APP_PC_ADDR, - .default_xip_addr = 0x23000000, - } -}; -boot_efuse_hw_config g_efuse_cfg; +boot2_image_config g_boot_img_cfg[2]; +boot2_efuse_hw_config g_efuse_cfg; uint8_t g_ps_mode = BFLB_PSM_ACTIVE; uint8_t g_cpu_count; uint32_t g_user_hash_ignored = 0; -/*@} end of group BLSP_BOOT2_Global_Variables */ -/** @defgroup BLSP_BOOT2_Private_Fun_Declaration - * @{ - */ - -/*@} end of group BLSP_BOOT2_Private_Fun_Declaration */ - -/** @defgroup BLSP_BOOT2_Private_Functions_User_Define - * @{ - */ - -/*@} end of group BLSP_BOOT2_Private_Functions_User_Define */ - -/** @defgroup BLSP_BOOT2_Private_Functions - * @{ - */ /****************************************************************************/ /** * @brief Boot2 runs error call back function @@ -162,8 +105,8 @@ static void blsp_dump_pt_entry(pt_table_entry_config *pt_entry) * @return 1 for find XZ FW and decompress success, 0 for other cases * *******************************************************************************/ -#if 0 -static int BLSP_Boot2_Check_XZ_FW(pt_table_id_type activeID, pt_table_stuff_config *ptStuff, pt_table_entry_config *ptEntry) +#if BLSP_BOOT2_SUPPORT_DECOMPRESS +static int blsp_boot2_check_xz_fw(pt_table_id_type activeID, pt_table_stuff_config *ptStuff, pt_table_entry_config *ptEntry) { uint8_t buf[6]; @@ -199,6 +142,7 @@ static int BLSP_Boot2_Check_XZ_FW(pt_table_id_type activeID, pt_table_stuff_conf return 0; } #endif + /****************************************************************************/ /** * @brief Boot2 copy firmware from OTA region to normal region * @@ -280,13 +224,23 @@ static int blsp_boot2_deal_one_fw(pt_table_id_type active_id, pt_table_stuff_con } else { blsp_dump_pt_entry(pt_entry); MSG("Check Img\r\n"); - - //if(BLSP_Boot2_Check_XZ_FW(activeID,ptStuff,ptEntry)==1){ - //return 0; - //} +#if BLSP_BOOT2_SUPPORT_DECOMPRESS + if(blsp_boot2_check_xz_fw(active_id,pt_stuff,pt_entry)==1){ + return 0; + } +#endif /* Check if this partition need copy */ if (pt_entry->active_index >= 2) { if (BFLB_BOOT2_SUCCESS == blsp_boot2_do_fw_copy(active_id, pt_stuff, pt_entry)) { + + pt_entry->active_index = !(pt_entry->active_index & 0x01); + pt_entry->age++; + ret = pt_table_update_entry((pt_table_id_type)(!active_id), pt_stuff, pt_entry); + + if (ret != PT_ERROR_SUCCESS) { + MSG_ERR("Update Partition table entry fail, After Image Copy\r\n"); + return BFLB_BOOT2_FAIL; + } return 0; } } @@ -357,12 +311,6 @@ static void blsp_boot2_get_mfg_startreq(pt_table_id_type active_id, pt_table_stu } } -/*@} end of group BLSP_BOOT2_Private_Functions */ - -/** @defgroup BLSP_BOOT2_Public_Functions - * @{ - */ - /****************************************************************************/ /** * @brief Boot2 main function * @@ -385,18 +333,36 @@ int main(void) #ifdef BLSP_BOOT2_ROLLBACK uint8_t roll_backed = 0; #endif + uint8_t mfg_mode_flag = 0; //boot_clk_config clk_cfg; uint8_t flash_cfg_buf[4 + sizeof(SPI_Flash_Cfg_Type) + 4] = { 0 }; + uint32_t crc; + uint8_t *flash_cfg = NULL; + uint32_t flash_cfg_len = 0; - bflb_platform_init(0); - hal_boot2_custom(); + system_mtimer_clock_init(); + peripheral_clock_init(); + +#if (BLSP_BOOT2_MODE == BOOT2_MODE_RELEASE) + bflb_platform_print_set(1); +#endif + +#if (BLSP_BOOT2_MODE == BOOT2_MODE_DEBUG) + bflb_platform_print_set(0); +#endif + +#if (BLSP_BOOT2_MODE == BOOT2_MODE_DEEP_DEBUG) + bflb_platform_print_set(0); + hal_boot2_debug_uart_gpio_init(); +#endif + hal_boot2_uart_gpio_init(); bflb_eflash_loader_uart_init(); - blsp_boot2_pll_init(); + hal_boot2_custom(); flash_init(); - bflb_platform_print_set(blsp_boot2_get_log_disable_flag()); + bflb_platform_deinit_time(); - + if (blsp_boot2_get_feature_flag() == BLSP_BOOT2_CP_FLAG) { MSG("BLSP_Boot2_CP:%s,%s\r\n", __DATE__, __TIME__); } else if (blsp_boot2_get_feature_flag() == BLSP_BOOT2_MP_FLAG) { @@ -406,22 +372,19 @@ int main(void) } #ifdef BL_SDK_VER - MSG("SDK:%s\r\n", BL_SDK_VER); + MSG("sdk:%s\r\n", BL_SDK_VER); #else MSG("MCU SDK:%s\r\n", MCU_SDK_VERSION); MSG("BSP Driver:%s\r\n", BSP_DRIVER_VERSION); MSG("BSP Common:%s\r\n", BSP_COMMON_VERSION); #endif - if (blsp_boot2_dump_critical_flag()) { - //blsp_dump_data(&clk_cfg,16); - } MSG("Get efuse config\r\n"); - efuse_get_boot2_cfg(&g_efuse_cfg); + hal_boot2_get_efuse_cfg(&g_efuse_cfg); /* Reset Sec_Eng for using */ - hal_reset_sec_eng(); + hal_boot2_reset_sec_eng(); if (blsp_boot2_get_feature_flag() != BLSP_BOOT2_SP_FLAG) { /* Get cpu count info */ g_cpu_count = blsp_boot2_get_cpu_count(); @@ -433,14 +396,11 @@ int main(void) g_ps_mode = blsp_read_power_save_mode(); /* Get User specified FW */ - arch_memcpy(user_fw_name, hal_hbn_get_user_specified_fw(), 4); - if (blsp_boot2_8m_support_flag()) { - /* Set flash operation function, read via sbus */ - pt_table_set_flash_operation(flash_erase, flash_write, flash_read); - } else { - /* Set flash operation function, read via xip */ - pt_table_set_flash_operation(flash_erase, flash_write, flash_read); - } + arch_memcpy(user_fw_name, hal_boot2_get_user_fw(), 4); + + + /* Set flash operation function, read via xip */ + pt_table_set_flash_operation(flash_erase, flash_write, flash_read); while (1) { mfg_mode_flag = 0; @@ -463,7 +423,7 @@ int main(void) if (pt_parsed == 0) { continue; } else { - hal_hbn_clr_user_specified_fw(); + hal_boot2_clr_user_fw(); } mfg_mode_flag = 1; user_fw_name[0] = 0; @@ -473,7 +433,7 @@ int main(void) if (pt_parsed == 0) { continue; } else { - hal_hbn_clr_user_specified_fw(); + hal_boot2_clr_user_fw(); } mfg_mode_flag = 1; user_fw_name[0] = 0; @@ -501,8 +461,13 @@ int main(void) /* Pass flash config */ if (pt_entry[0].start_address[pt_entry[0].active_index] != 0) { - flash_read(BLSP_BOOT2_XIP_BASE + pt_entry[0].start_address[pt_entry[0].active_index] + 8, flash_cfg_buf, sizeof(flash_cfg_buf)); + //flash_read(BLSP_BOOT2_XIP_BASE + pt_entry[0].start_address[pt_entry[0].active_index] + 8, flash_cfg_buf, sizeof(flash_cfg_buf)); /* Include magic and CRC32 */ + flash_get_cfg(&flash_cfg,&flash_cfg_len); + arch_memcpy(flash_cfg_buf, "FCFG", 4); + arch_memcpy(flash_cfg_buf+4, flash_cfg, flash_cfg_len); + crc = BFLB_Soft_CRC32(flash_cfg, flash_cfg_len); + arch_memcpy(flash_cfg_buf+4+flash_cfg_len, &crc, sizeof(crc)); blsp_boot2_pass_parameter(flash_cfg_buf, sizeof(flash_cfg_buf)); } @@ -575,8 +540,6 @@ void bfl_main() main(); } -/*@} end of group BLSP_BOOT2_Public_Functions */ -/*@} end of group BLSP_BOOT2 */ -/*@} end of group BL606_BLSP_Boot2 */ + diff --git a/examples/boot2_iap/blsp_boot_decompress.c b/examples/boot2_iap/blsp_boot_decompress.c index 445a5ea9..6e416f25 100644 --- a/examples/boot2_iap/blsp_boot_decompress.c +++ b/examples/boot2_iap/blsp_boot_decompress.c @@ -43,55 +43,12 @@ #include "partition.h" #include "hal_flash.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ +#define BFLB_BOOT2_XZ_MALLOC_BUF_SIZE 64*1024 -/** @addtogroup BLSP_BOOT_DECOMPRESS - * @{ - */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Macros - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Macros */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Types - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Types */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Variables - * @{ - */ static uint8_t g_xz_output[BFLB_BOOT2_READBUF_SIZE] __attribute__((section(".noinit_data"))); -static uint8_t g_malloc_buf[64 * 1024] __attribute__((section(".noinit_data"))); +static uint8_t g_malloc_buf[BFLB_BOOT2_XZ_MALLOC_BUF_SIZE] __attribute__((section(".noinit_data"))); -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Variables */ -/** @defgroup BLSP_BOOT_DECOMPRESS_Global_Variables - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Global_Variables */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Fun_Declaration - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Fun_Declaration */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Functions_User_Define - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Functions_User_Define */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Private_Functions - * @{ - */ /****************************************************************************/ /** * @brief Decompress XZ Firmware @@ -224,11 +181,6 @@ error: return BFLB_BOOT2_FAIL; } -/*@} end of group BLSP_BOOT_DECOMPRESS_Private_Functions */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Public_Functions - * @{ - */ /****************************************************************************/ /** * @brief Update decompressed firmware to flash according to XZ firmware @@ -245,12 +197,13 @@ int32_t blsp_boot2_update_fw(pt_table_id_type active_id, pt_table_stuff_config * uint8_t active_index = pt_entry->active_index; uint32_t new_fw_len; int32_t ret; -#ifdef BLSP_BOOT2_ROLLBACK + /* Try to check Image integrity: try to decompress */ if (BFLB_BOOT2_SUCCESS != blsp_boot2_fw_decompress(pt_entry->start_address[active_index], pt_entry->start_address[!(active_index & 0x01)], 0, &new_fw_len)) { +#ifdef BLSP_BOOT2_ROLLBACK /* Decompress fail, try to rollback to old one */ pt_entry->active_index = !(active_index & 0x01); pt_entry->age++; @@ -260,11 +213,11 @@ int32_t blsp_boot2_update_fw(pt_table_id_type active_id, pt_table_stuff_config * MSG_ERR("Rollback Update Partition table entry fail\r\n"); return BFLB_BOOT2_FAIL; } - +#endif return BFLB_BOOT2_SUCCESS; } -#endif + /* Do decompress */ if (BFLB_BOOT2_SUCCESS == blsp_boot2_fw_decompress(pt_entry->start_address[active_index], @@ -309,8 +262,5 @@ int blsp_boot2_verify_xz_header(uint8_t *buffer) return 0; } -/*@} end of group BLSP_BOOT_DECOMPRESS_Public_Functions */ -/*@} end of group BLSP_BOOT_DECOMPRESS */ -/*@} end of group BL606_BLSP_Boot2 */ diff --git a/examples/boot2_iap/blsp_boot_decompress.h b/examples/boot2_iap/blsp_boot_decompress.h index 60db41b5..01315946 100644 --- a/examples/boot2_iap/blsp_boot_decompress.h +++ b/examples/boot2_iap/blsp_boot_decompress.h @@ -37,43 +37,10 @@ #define __BLSP_BOOT_DECOMPRESS_H__ #include "stdint.h" +#include "partition.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ - -/** @addtogroup BLSP_BOOT_DECOMPRESS - * @{ - */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Public_Types - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Public_Types */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Public_Constants - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Public_Constants */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Public_Macros - * @{ - */ - -/*@} end of group BLSP_BOOT_DECOMPRESS_Public_Macros */ - -/** @defgroup BLSP_BOOT_DECOMPRESS_Public_Functions - * @{ - */ int32_t blsp_boot2_update_fw(pt_table_id_type activeID, pt_table_stuff_config *ptStuff, pt_table_entry_config *ptEntry); int blsp_boot2_verify_xz_header(uint8_t *buffer); -/*@} end of group BLSP_BOOT_DECOMPRESS_Public_Functions */ - -/*@} end of group BLSP_BOOT_DECOMPRESS */ - -/*@} end of group BL606_BLSP_Boot2 */ #endif /* __BLSP_BOOT_DECOMPRESS_H__ */ diff --git a/examples/boot2_iap/blsp_boot_parser.c b/examples/boot2_iap/blsp_boot_parser.c index f608cdec..44953916 100644 --- a/examples/boot2_iap/blsp_boot_parser.c +++ b/examples/boot2_iap/blsp_boot_parser.c @@ -41,60 +41,10 @@ #include "softcrc.h" #include "blsp_port.h" #include "hal_sec_hash.h" -//#include "hal_sec_eng.h" #include "hal_sec_ecdsa.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ -/** @addtogroup BLSP_BOOT_PARSER - * @{ - */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Macros - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Private_Macros */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Types - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Private_Types */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Variables - * @{ - */ -//static uint32_t g_sha_tmp_buf[16] = { 0 }; -//static uint32_t g_padding[16] = { 0 }; -//SEC_Eng_SHA256_Ctx g_sha_ctx; extern uint32_t g_user_hash_ignored; -/*@} end of group BLSP_BOOT_PARSER_Private_Variables */ - -/** @defgroup BLSP_BOOT_PARSER_Global_Variables - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Global_Variables */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Fun_Declaration - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Private_Fun_Declaration */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Functions_User_Define - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Private_Functions_User_Define */ - -/** @defgroup BLSP_BOOT_PARSER_Private_Functions - * @{ - */ - struct device *dev_check_hash; /****************************************************************************/ /** @@ -121,12 +71,6 @@ static uint32_t blsp_boot_parse_is_pkhash_valid(uint8_t cpu_type, uint8_t *pkhas return 0; } -/*@} end of group BLSP_BOOT_PARSER_Private_Functions */ - -/** @defgroup BLSP_BOOT_PARSER_Public_Functions - * @{ - */ - /****************************************************************************/ /** * @brief Check if the input public key is the same as burned in the efuse * @@ -136,7 +80,7 @@ static uint32_t blsp_boot_parse_is_pkhash_valid(uint8_t cpu_type, uint8_t *pkhas * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parse_bootheader(boot_image_config *boot_img_cfg, uint8_t *data) +int32_t blsp_boot_parse_bootheader(boot2_image_config *boot_img_cfg, uint8_t *data) { boot_header_config *header = (boot_header_config *)data; uint32_t crc; @@ -271,7 +215,7 @@ int32_t blsp_boot_parse_bootheader(boot_image_config *boot_img_cfg, uint8_t *dat * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parse_pkey(boot_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own) +int32_t blsp_boot_parse_pkey(boot2_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own) { boot_pk_config *cfg = (boot_pk_config *)data; uint32_t pk_hash[BFLB_BOOT2_PK_HASH_SIZE / 4]; @@ -320,7 +264,7 @@ int32_t blsp_boot_parse_pkey(boot_image_config *g_boot_img_cfg, uint8_t *data, u * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parse_signature(boot_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own) +int32_t blsp_boot_parse_signature(boot2_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own) { boot_sign_config *cfg = (boot_sign_config *)data; uint32_t crc; @@ -357,7 +301,7 @@ int32_t blsp_boot_parse_signature(boot_image_config *g_boot_img_cfg, uint8_t *da * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parse_aesiv(boot_image_config *g_boot_img_cfg, uint8_t *data) +int32_t blsp_boot_parse_aesiv(boot2_image_config *g_boot_img_cfg, uint8_t *data) { boot_aes_config *cfg = (boot_aes_config *)data; @@ -385,7 +329,7 @@ int32_t blsp_boot_parse_aesiv(boot_image_config *g_boot_img_cfg, uint8_t *data) * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parser_check_signature(boot_image_config *g_boot_img_cfg) +int32_t blsp_boot_parser_check_signature(boot2_image_config *g_boot_img_cfg) { int32_t ret = 0; uint64_t startTime = 0; @@ -434,7 +378,7 @@ int32_t blsp_boot_parser_check_signature(boot_image_config *g_boot_img_cfg) * @return boot_error_code type * *******************************************************************************/ -int32_t blsp_boot_parser_check_hash(boot_image_config *g_boot_img_cfg) +int32_t blsp_boot_parser_check_hash(boot2_image_config *g_boot_img_cfg) { uint32_t img_hash_cal[BFLB_BOOT2_HASH_SIZE / 4]; @@ -457,8 +401,7 @@ int32_t blsp_boot_parser_check_hash(boot_image_config *g_boot_img_cfg) return BFLB_BOOT2_SUCCESS; } -/*@} end of group BLSP_BOOT_PARSER_Public_Functions */ -/*@} end of group BLSP_BOOT_PARSER */ -/*@} end of group BL606_BLSP_Boot2 */ + + diff --git a/examples/boot2_iap/blsp_boot_parser.h b/examples/boot2_iap/blsp_boot_parser.h index 860e121f..9c77d15f 100644 --- a/examples/boot2_iap/blsp_boot_parser.h +++ b/examples/boot2_iap/blsp_boot_parser.h @@ -38,46 +38,16 @@ #include "stdint.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ +int32_t blsp_boot_parse_bootheader(boot2_image_config *g_boot_img_cfg, uint8_t *data); +int32_t blsp_boot_parse_pkey(boot2_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own); +int32_t blsp_boot_parse_signature(boot2_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own); +int32_t blsp_boot_parse_aesiv(boot2_image_config *g_boot_img_cfg, uint8_t *data); +int32_t blsp_boot_parser_check_signature(boot2_image_config *g_boot_img_cfg); +int32_t blsp_boot_parser_check_hash(boot2_image_config *g_boot_img_cfg); -/** @addtogroup BLSP_BOOT_PARSER - * @{ - */ -/** @defgroup BLSP_BOOT_PARSER_Public_Types - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Public_Types */ - -/** @defgroup BLSP_BOOT_PARSER_Public_Constants - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Public_Constants */ - -/** @defgroup BLSP_BOOT_PARSER_Public_Macros - * @{ - */ - -/*@} end of group BLSP_BOOT_PARSER_Public_Macros */ - -/** @defgroup BLSP_BOOT_PARSER_Public_Functions - * @{ - */ -int32_t blsp_boot_parse_bootheader(boot_image_config *g_boot_img_cfg, uint8_t *data); -int32_t blsp_boot_parse_pkey(boot_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own); -int32_t blsp_boot_parse_signature(boot_image_config *g_boot_img_cfg, uint8_t *data, uint8_t own); -int32_t blsp_boot_parse_aesiv(boot_image_config *g_boot_img_cfg, uint8_t *data); -int32_t blsp_boot_parser_check_signature(boot_image_config *g_boot_img_cfg); -int32_t blsp_boot_parser_check_hash(boot_image_config *g_boot_img_cfg); - -/*@} end of group BLSP_BOOT_PARSER_Public_Functions */ - -/*@} end of group BLSP_BOOT_PARSER */ - -/*@} end of group BL606_BLSP_Boot2 */ #endif /* __BLSP_BOOT_PARSER_H__ */ + + + diff --git a/examples/boot2_iap/blsp_bootinfo.h b/examples/boot2_iap/blsp_bootinfo.h index f1a44dae..5f1ce0bb 100644 --- a/examples/boot2_iap/blsp_bootinfo.h +++ b/examples/boot2_iap/blsp_bootinfo.h @@ -41,17 +41,7 @@ #include "hal_flash.h" #include "hal_boot2.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ -/** @addtogroup BLSP_BOOTINFO - * @{ - */ - -/** @defgroup BLSP_BOOTINFO_Public_Macros - * @{ - */ #define BFLB_BOOT2_CPU0_MAGIC "BFNP" #define BFLB_BOOT2_CPU1_MAGIC "BFAP" #define BFLB_BOOT2_FLASH_CFG_MAGIC "FCFG" @@ -62,6 +52,7 @@ #define BFLB_BOOT2_READBUF_SIZE 4 * 1024 #define BFLB_FW_IMG_OFFSET_AFTER_HEADER 4 * 1024 + /* Image owner type */ #define BFLB_BOOT2_CPU_0 0 #define BFLB_BOOT2_CPU_1 1 @@ -79,11 +70,8 @@ #define BFLB_PSM_ACTIVE 0 #define BFLB_PSM_HBN 1 -/*@} end of group BLSP_BOOTINFO_Public_Macros */ -/** @defgroup BLSP_BOOTINFO_Public_Types - * @{ - */ + typedef enum { BFLB_BOOT2_SUCCESS = 0x00, @@ -256,7 +244,7 @@ typedef struct uint8_t signature[BFLB_BOOT2_SIGN_MAXSIZE]; //signature in boot header uint8_t signature2[BFLB_BOOT2_SIGN_MAXSIZE]; //signature in boot header -} boot_image_config; +} boot2_image_config; typedef struct { @@ -267,29 +255,15 @@ typedef struct typedef void (*pentry_t)(void); -extern boot_cpu_config g_boot_cpu_cfg[2]; -extern boot_image_config g_boot_img_cfg[2]; -extern boot_efuse_hw_config g_efuse_cfg; +extern boot2_image_config g_boot_img_cfg[2]; +extern boot2_efuse_hw_config g_efuse_cfg; extern uint8_t g_ps_mode; extern uint8_t g_cpu_count; extern uint8_t g_boot2_read_buf[BFLB_BOOT2_READBUF_SIZE]; -/*@} end of group BLSP_BOOTINFO_Public_Types */ -/** @defgroup BLSP_BOOTINFO_Public_Constants - * @{ - */ - -/*@} end of group BLSP_BOOTINFO_Public_Constants */ - -/** @defgroup BLSP_BOOTINFO_Public_Functions - * @{ - */ - -/*@} end of group BLSP_BOOTINFO_Public_Functions */ - -/*@} end of group BLSP_BOOTINFO */ - -/*@} end of group BL606_BLSP_Boot2 */ #endif /* __BLSP_BOOTINFO_H__ */ + + + diff --git a/examples/boot2_iap/blsp_common.c b/examples/boot2_iap/blsp_common.c index ea8c9543..08f974e4 100644 --- a/examples/boot2_iap/blsp_common.c +++ b/examples/boot2_iap/blsp_common.c @@ -46,54 +46,7 @@ #include "hal_boot2.h" #include "bflb_eflash_loader.h" -/** @addtogroup BL606_BLSP_Boot2 - * @{ - */ - -/** @addtogroup BLSP_COMMON - * @{ - */ - -/** @defgroup BLSP_COMMON_Private_Macros - * @{ - */ - -/*@} end of group BLSP_COMMON_Private_Macros */ - -/** @defgroup BLSP_COMMON_Private_Types - * @{ - */ - -/*@} end of group BLSP_COMMON_Private_Types */ - -/** @defgroup BLSP_COMMON_Private_Variables - * @{ - */ - -/*@} end of group BLSP_COMMON_Private_Variables */ - -/** @defgroup BLSP_COMMON_Global_Variables - * @{ - */ -int32_t blsp_boot2_set_encrypt(uint8_t index, boot_image_config *g_boot_img_cfg); - -/*@} end of group BLSP_COMMON_Global_Variables */ - -/** @defgroup BLSP_COMMON_Private_Fun_Declaration - * @{ - */ - -/*@} end of group BLSP_COMMON_Private_Fun_Declaration */ - -/** @defgroup BLSP_COMMON_Private_Functions_User_Define - * @{ - */ - -/*@} end of group BLSP_COMMON_Private_Functions_User_Define */ - -/** @defgroup BLSP_COMMON_Private_Functions - * @{ - */ +int32_t blsp_boot2_set_encrypt(uint8_t index, boot2_image_config *g_boot_img_cfg); /****************************************************************************/ /** * @brief Dump data @@ -132,7 +85,7 @@ void blsp_dump_data(void *datain, int len) int32_t blsp_mediaboot_pre_jump(void) { /* Sec eng deinit*/ - hal_reset_sec_eng(); + hal_boot2_reset_sec_eng(); /* Platform deinit */ bflb_platform_deinit(); @@ -153,16 +106,8 @@ int32_t blsp_mediaboot_pre_jump(void) *******************************************************************************/ void blsp_boot2_exit(void) { - uint32_t i = 0; - blsp_sboot_finish(); - - /* Prepare release Other CPUs anyway */ - /* Deal Other CPU's entry point */ - for (i = 1; i < g_cpu_count; i++) { - BL_WR_WORD(g_boot_cpu_cfg[i].msp_store_addr, 0); - BL_WR_WORD(g_boot_cpu_cfg[i].pc_store_addr, 0); - } + hal_boot2_sboot_finish(); /* Release other CPUs*/ if (g_cpu_count != 1 && !g_boot_img_cfg[0].halt_cpu1) { @@ -190,7 +135,7 @@ void ATTR_TCM_SECTION blsp_boot2_jump_entry(void) uint32_t i = 0; int32_t ret; - blsp_sboot_finish(); + hal_boot2_sboot_finish(); /*Note:enable cache with flash offset, after this, should be no flash directl read, If need read, should take flash offset into consideration */ @@ -205,16 +150,31 @@ void ATTR_TCM_SECTION blsp_boot2_jump_entry(void) if (ret != BFLB_BOOT2_SUCCESS) { return; } - - /* Deal Other CPUs' entry point */ - /* Prepare release CPU1 anyway */ - for (i = 1; i < g_cpu_count; i++) { - if (g_boot_img_cfg[i].img_valid) { - BL_WR_WORD(g_boot_cpu_cfg[i].msp_store_addr, g_boot_img_cfg[i].msp_val); - BL_WR_WORD(g_boot_cpu_cfg[i].pc_store_addr, g_boot_img_cfg[i].entry_point); - } else { - BL_WR_WORD(g_boot_cpu_cfg[i].msp_store_addr, 0); - BL_WR_WORD(g_boot_cpu_cfg[i].pc_store_addr, 0); + /* Set decryption before read MSP and PC*/ + if(0!=g_efuse_cfg.encrypted[0]){ + blsp_boot2_set_encrypt(0,&g_boot_img_cfg[0]); + blsp_boot2_set_encrypt(1,&g_boot_img_cfg[1]); + /* Get msp and pc value */ + for(i=0;i