From 4db1d21bd58b08c113e9577bfd85166582ba2275 Mon Sep 17 00:00:00 2001 From: Wang Jikai Date: Tue, 25 Apr 2023 17:27:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bl808:=20=E8=A7=A3=E6=9E=90=E9=97=AA?= =?UTF-8?q?=E5=AD=98=E9=85=8D=E7=BD=AE=E8=A1=A8=E5=92=8C=E6=8C=87=E5=90=91?= =?UTF-8?q?=E7=9A=84=E9=97=AA=E5=AD=98=E9=85=8D=E7=BD=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wang Jikai --- BL808Image.bt | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/BL808Image.bt b/BL808Image.bt index a57062c..d45c5a8 100644 --- a/BL808Image.bt +++ b/BL808Image.bt @@ -21,6 +21,7 @@ struct HAL_SYS_CLK_CONFIG; struct HAL_BASIC_CONFIG; struct HAL_CPU_CFG; struct HAL_PATCH_CFG; +struct FlashConfig; typedef struct { local int64 start = FTell(); @@ -214,6 +215,11 @@ typedef struct { uint32 value ; } HAL_PATCH_CFG; +typedef struct { + uint32 jedec_id ; + uint32 offset ; +} FlashConfig; + /**** PARSING CODE ****/ LittleEndian(); @@ -228,7 +234,35 @@ if (BootHeader.magic != 0x504e4642) if(BootHeader.flashCfgTableAddr < FileSize() && BootHeader.flashCfgTableAddr + BootHeader.flashCfgTableLen <= FileSize()) { FSeek(BootHeader.flashCfgTableAddr); - ubyte flashCfgTable[BootHeader.flashCfgTableLen] ; + local quad num_configs = (BootHeader.flashCfgTableLen - 8) / 8; + typedef struct { + uint32 magic ; + FlashConfig config[num_configs]; + uint32 crc ; + } FlashConfigTable; + FlashConfigTable flashConfigTable ; + local quad off = FTell(); + local quad i, j; + local quad min = 0; + local quad minCurr = ~0; + for (i = 0; minCurr > min; i++) { + // each iteration find smallist + minCurr = ~0; + for (j = 0; j min && flashConfigTable.config[j].offset < minCurr) { + minCurr = flashConfigTable.config[j].offset; + } + } + FSeek(minCurr); + min = minCurr; + if (minCurr == ~0) { + break; + } else { + HAL_FLASH_CONFIG conf ; + minCurr = ~0; + } + } + FSeek(off); } else { Warning("flashCfgTable appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); } -- Gitee From 6d1a4ad9dfba9b95a230df74fa5c01ac589ab6ae Mon Sep 17 00:00:00 2001 From: Wang Jikai Date: Tue, 25 Apr 2023 17:28:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bl808:=20=E5=A2=9E=E5=8A=A0=E9=97=AA?= =?UTF-8?q?=E5=AD=98=E9=85=8D=E7=BD=AE=E7=BB=93=E6=9E=84=E4=BD=93=E7=9A=84?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E7=A0=81=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wang Jikai --- BL808Image.bt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BL808Image.bt b/BL808Image.bt index d45c5a8..044e862 100644 --- a/BL808Image.bt +++ b/BL808Image.bt @@ -238,7 +238,11 @@ if(BootHeader.flashCfgTableAddr < FileSize() && typedef struct { uint32 magic ; FlashConfig config[num_configs]; + local uint32 checksum = Checksum(CHECKSUM_CRC32,startof(config),sizeof(config)); uint32 crc ; + if(checksum != crc) { + Warning("invalid crc32 for FlashConfigTable!"); + } } FlashConfigTable; FlashConfigTable flashConfigTable ; local quad off = FTell(); -- Gitee