From 725394ba03987b213cac96d82a348d1201590697 Mon Sep 17 00:00:00 2001 From: crk Date: Mon, 17 Apr 2023 22:19:39 +0800 Subject: [PATCH] =?UTF-8?q?bl808:=20=E4=BD=BF=E7=94=A8Warning=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AFPrintf,=20=E5=AE=8C=E6=88=90=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E6=A0=A1=E9=AA=8C=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在检验magic的时候使用了Warning函数。完整结构体、clock和flash的校验和。 Signed-off-by: crk --- BL808Image.bt | 63 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/BL808Image.bt b/BL808Image.bt index 97f75c7..7869eb7 100644 --- a/BL808Image.bt +++ b/BL808Image.bt @@ -23,6 +23,7 @@ struct HAL_CPU_CFG; struct HAL_PATCH_CFG; typedef struct { + local int64 start = FTell(); uint32 magic ; uint32 revision; HAL_FLASH_CONFIG flashCfg; @@ -35,24 +36,35 @@ typedef struct { uint32 flashCfgTableLen ; local quad off = FTell(); - if(flashCfgTableAddr < FileSize() && flashCfgTableAddr + flashCfgTableLen <= FileSize()) { - FSeek(flashCfgTableAddr); - ubyte flashCfgTable[flashCfgTableLen] ; - } else { - Warning("flashCfgTable appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); + if(flashCfgTableAddr < FileSize() && flashCfgTableAddr + flashCfgTableLen <= FileSize()) { + FSeek(flashCfgTableAddr); + ubyte flashCfgTable[flashCfgTableLen] ; + } else { + Warning("flashCfgTable appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); } FSeek(off); HAL_PATCH_CFG patch_on_read[4] ; HAL_PATCH_CFG patch_on_jump[4] ; uint32 reserved[5]; + local int64 end = FTell(); + local uint32 checksum = Checksum(CHECKSUM_CRC32,start,end - start); uint32 crc32 ; + if(checksum != crc32) { + Warning("invalid crc32 for HAL_BOOTHEADER!"); + } } HAL_BOOTHEADER; typedef struct { uint32 magic ; + local int64 start = FTell(); SPI_FLASH_CFG_TYPE cfg; + local int64 end = FTell(); + local uint32 checksum = Checksum(CHECKSUM_CRC32,start,end - start); uint32 crc32 ; + if(checksum != crc32) { + Warning("invalid crc32 for HAL_FLASH_CONFIG!"); + } } HAL_FLASH_CONFIG; // source: bouffalo boot2 project @@ -133,8 +145,14 @@ typedef struct { typedef struct { uint32 magic ; + local int64 start = FTell(); HAL_SYS_CLK_CONFIG cfg; + local int64 end = FTell(); + local uint32 checksum = Checksum(CHECKSUM_CRC32,start,end - start); uint32 crc32 ; + if(checksum != crc32) { + Warning("invalid crc32 for HAL_PLL_CONFIG"); + }; } HAL_PLL_CONFIG; typedef struct { @@ -165,18 +183,37 @@ typedef struct { } HAL_SYS_CLK_CONFIG; typedef struct { - uint32 sign_type : 2 ; uint32 encrypt_type : 2 ; uint32 key_sel : 2 ; uint32 xts_mode : 1 ; uint32 aes_region_lock : 1 ; uint32 no_segment : 1 ; uint32 boot2_enable : 1 ; uint32 boot2_rollback : 1 ; uint32 cpu_master_id : 4 ; uint32 notload_in_bootrom : 1 ; uint32 crc_ignore : 1 ; uint32 hash_ignore : 1 ; uint32 power_on_mm : 1 ; uint32 em_sel : 3 ; uint32 cmds_en : 1 ; uint32 cmds_wrap_mode : 2 ; uint32 cmds_wrap_len : 4 ; uint32 icache_invalid : 1 ; uint32 dcache_invalid : 1 ; uint32 fpga_halt_release : 1 ; + uint32 sign_type : 2 ; + uint32 encrypt_type : 2 ; + uint32 key_sel : 2 ; + uint32 xts_mode : 1 ; + uint32 aes_region_lock : 1 ; + uint32 no_segment : 1 ; + uint32 boot2_enable : 1 ; + uint32 boot2_rollback : 1 ; + uint32 cpu_master_id : 4 ; + uint32 notload_in_bootrom : 1 ; + uint32 crc_ignore : 1 ; + uint32 hash_ignore : 1 ; + uint32 power_on_mm : 1 ; + uint32 em_sel : 3 ; + uint32 cmds_en : 1 ; + uint32 cmds_wrap_mode : 2 ; + uint32 cmds_wrap_len : 4 ; + uint32 icache_invalid : 1 ; + uint32 dcache_invalid : 1 ; + uint32 fpga_halt_release : 1 ; uint32 group_image_offset ; uint32 aes_region_len ; uint32 img_len_cnt ; uint32 hash[8] ; - + local quad off = FTell(); - if(img_len_cnt < FileSize() && img_len_cnt + group_image_offset <= FileSize()) { - FSeek(group_image_offset); - ubyte image[img_len_cnt] ; - } else { - Warning("Segment data appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); + if(img_len_cnt < FileSize() && img_len_cnt + group_image_offset <= FileSize()) { + FSeek(group_image_offset); + ubyte image[img_len_cnt] ; + } else { + Warning("Segment data appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); } FSeek(off); } HAL_BASIC_CONFIG; @@ -207,6 +244,6 @@ HAL_BOOTHEADER BootHeader ; if (BootHeader.magic != 0x504e4642) { - Printf("Invalid Magic.\n"); + Warning("Invalid Magic.\n"); return 1; } -- Gitee