diff --git a/BL702Image.bt b/BL702Image.bt new file mode 100644 index 0000000000000000000000000000000000000000..b55eb086c0159f5739bf470ddc63951b2a1d5754 --- /dev/null +++ b/BL702Image.bt @@ -0,0 +1,212 @@ +//------------------------------------------------ +//--- 010 Editor v12.0.1 Binary Template +// +// File: BL702Image +// Authors: Junxing Zhu +// Version: 0.0.0 +// Purpose: +// Category: +// File Mask: +// ID Bytes: +// History: +//------------------------------------------------ +RequiresVersion( 12 ); + +/**** STRUCTURES ****/ +struct HAL_BOOTHEADER; +struct HAL_FLASH_CONFIG; +struct SPI_FLASH_CFG_TYPE; +struct HAL_PLL_CONFIG; +struct HAL_SYS_CLK_CONFIG; +struct HAL_BASIC_CONFIG; + +typedef struct { + local int64 start = FTell(); + uint32 magic ; + uint32 revision; + HAL_FLASH_CONFIG flashCfg; + HAL_PLL_CONFIG clkCfg; + HAL_BASIC_CONFIG basicCfg; + uint32 reserved[2] ; + 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 ; + SPI_FLASH_CFG_TYPE cfg; + local uint32 checksum = Checksum(CHECKSUM_CRC32,startof(cfg),sizeof(cfg)); + uint32 crc32 ; + if(checksum != crc32) { + Warning("invalid crc32 for HAL_FLASH_CONFIG!"); + } +} HAL_FLASH_CONFIG; + +// source: bouffalo boot2 project +typedef struct { + ubyte ioMode ; + ubyte cReadSupport ; + ubyte clkDelay ; + ubyte clkInvert ; + ubyte resetEnCmd ; + ubyte resetCmd ; + ubyte resetCreadCmd ; + ubyte resetCreadCmdSize ; + ubyte jedecIdCmd ; + ubyte jedecIdCmdDmyClk ; + ubyte enter32BitsAddrCmd ; + ubyte exit32BitsAddrCmd ; + ubyte sectorSize ; + ubyte mid ; + uint16 pageSize ; + ubyte chipEraseCmd ; + ubyte sectorEraseCmd ; + ubyte blk32EraseCmd ; + ubyte blk64EraseCmd ; + ubyte writeEnableCmd ; + ubyte pageProgramCmd ; + ubyte qpageProgramCmd ; + ubyte qppAddrMode ; + ubyte fastReadCmd ; + ubyte frDmyClk ; + ubyte qpiFastReadCmd ; + ubyte qpiFrDmyClk ; + ubyte fastReadDoCmd ; + ubyte frDoDmyClk ; + ubyte fastReadDioCmd ; + ubyte frDioDmyClk ; + ubyte fastReadQoCmd ; + ubyte frQoDmyClk ; + ubyte fastReadQioCmd ; + ubyte frQioDmyClk ; + ubyte qpiFastReadQioCmd ; + ubyte qpiFrQioDmyClk ; + ubyte qpiPageProgramCmd ; + ubyte writeVregEnableCmd ; + ubyte wrEnableIndex ; + ubyte qeIndex ; + ubyte busyIndex ; + ubyte wrEnableBit ; + ubyte qeBit ; + ubyte busyBit ; + ubyte wrEnableWriteRegLen ; + ubyte wrEnableReadRegLen ; + ubyte qeWriteRegLen ; + ubyte qeReadRegLen ; + ubyte releasePowerDown ; + ubyte busyReadRegLen ; + ubyte readRegCmd[4] ; + ubyte writeRegCmd[4] ; + ubyte enterQpi ; + ubyte exitQpi ; + ubyte cReadMode ; + ubyte cRExit ; + ubyte burstWrapCmd ; + ubyte burstWrapCmdDmyClk ; + ubyte burstWrapDataMode ; + ubyte burstWrapData ; + ubyte deBurstWrapCmd ; + ubyte deBurstWrapCmdDmyClk ; + ubyte deBurstWrapDataMode ; + ubyte deBurstWrapData ; + uint16 timeEsector ; + uint16 timeE32k ; + uint16 timeE64k ; + uint16 timePagePgm ; + uint16 timeCe ; + ubyte pdDelay ; + ubyte qeData ; +} SPI_FLASH_CFG_TYPE; + +typedef struct { + uint32 magic ; + HAL_SYS_CLK_CONFIG cfg; + local uint32 checksum = Checksum(CHECKSUM_CRC32,startof(cfg),sizeof(cfg)); + uint32 crc32 ; + if(checksum != crc32) { + Warning("invalid crc32 for HAL_PLL_CONFIG"); + }; +} HAL_PLL_CONFIG; + +typedef struct { + ubyte xtal_type; + ubyte pll_clk; + ubyte hclk_div; + ubyte hclk_div; + + ubyte flash_clk_type; + ubyte flash_clk_div; + ubyte rsvd[2]; +} HAL_SYS_CLK_CONFIG; + +typedef struct { + uint32 sign_type : 2 ; + uint32 encrypt_type : 2 ; + uint32 key_sel : 2 ; + uint32 rsvd1 : 2 ; + uint32 no_segment : 1 ; + uint32 cache_enable : 1 ; + uint32 notload_in_bootrom : 1 ; + uint32 aes_region_lock : 1 ; + uint32 cache_way_disable : 4 ; + uint32 crc_ignore : 1 ; + uint32 hash_ignore : 1 ; + uint32 halt_cpu1 : 1 ; + uint32 rsvd : 13 ; + + uint32 img_len ; + uint32 boot_entry ; + uint32 img_start ; + uint32 hash[8] ; +} HAL_BASIC_CONFIG; + +/**** PARSING CODE ****/ +LittleEndian(); + +HAL_BOOTHEADER BootHeader ; + +if (BootHeader.magic != 0x504e4642) +{ + Warning("Invalid Magic.\n"); + return 1; +} + +if(BootHeader.basicCfg.img_len < FileSize()) { + FSeek(BootHeader.basicCfg.img_start); + ubyte image[BootHeader.basicCfg.img_len] ; + local char s[64 + 1]; + local int ret = ChecksumAlgStr(CHECKSUM_SHA256, s, startof(image),sizeof(image)); + if(ret) { + local char ChecksumAlgStrResult[64 + 1]; + local quad k; + for (k = 0; k < 8; k++) { + ChecksumAlgStrResult[k * 8 + 1] = (char)(BootHeader.basicCfg.hash[k] & 0xF); + ChecksumAlgStrResult[k * 8 + 0] = (char)((BootHeader.basicCfg.hash[k] >> 4) & 0xF); + ChecksumAlgStrResult[k * 8 + 3] = (char)((BootHeader.basicCfg.hash[k] >> 8) & 0xF); + ChecksumAlgStrResult[k * 8 + 2] = (char)((BootHeader.basicCfg.hash[k] >> 12) & 0xF); + ChecksumAlgStrResult[k * 8 + 5] = (char)((BootHeader.basicCfg.hash[k] >> 16) & 0xF); + ChecksumAlgStrResult[k * 8 + 4] = (char)((BootHeader.basicCfg.hash[k] >> 20) & 0xF); + ChecksumAlgStrResult[k * 8 + 7] = (char)((BootHeader.basicCfg.hash[k] >> 24) & 0xF); + ChecksumAlgStrResult[k * 8 + 6] = (char)((BootHeader.basicCfg.hash[k] >> 28) & 0xF); + } + for (k = 0; k < 64; k++) { + if (ChecksumAlgStrResult[k] >= 10) { + ChecksumAlgStrResult[k] = ChecksumAlgStrResult[k] + 'A' - 10; + } else { + ChecksumAlgStrResult[k] += '0'; + } + } + ChecksumAlgStrResult[64] = '\0'; + if(Strcmp(s, ChecksumAlgStrResult)) { + Warning("invalid sha256 for the image!"); + } + } else { + Warning("hash check for the image failure"); + } +} 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!"); +} diff --git a/README.md b/README.md index 3696fcc7d04dccc7273ea70b5e0a3ca04d6ad713..6f6f1b4bbf5691ffce34ec7cb3274d1f7e8abab7 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ | 芯片型号 | 链接 | |:----|:----| | BL616 | [BL616Image.bt](./BL616Image.bt) | +| BL702 | [BL702Image.bt](./BL702Image.bt) | | BL808 | [BL808Image.bt](./BL808Image.bt) | | D1 | [D1Image.bt](./D1Image.bt) |