From f8e6e87a6e73e020d2be9b6a17c3c628142960b3 Mon Sep 17 00:00:00 2001 From: Mingrui Ma Date: Tue, 11 Apr 2023 16:36:24 +0800 Subject: [PATCH] =?UTF-8?q?d1:=20=E7=BC=96=E5=86=99=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E5=B9=B6=E8=83=BD=E8=A7=A3=E6=9E=90?= =?UTF-8?q?RISC-V=E8=B7=B3=E8=BD=AC=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解析RISC-V跳转指令可用于定位代码段。修改readme文件。 Signed-off-by: Mingrui Ma --- D1Image.bt | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 3 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 D1Image.bt diff --git a/D1Image.bt b/D1Image.bt new file mode 100644 index 0000000..fd1a74c --- /dev/null +++ b/D1Image.bt @@ -0,0 +1,55 @@ +//------------------------------------------------ +//--- 010 Editor v13.0.1 Binary Template +// +// File: d1-flash +// Authors: Mingrui Ma +// Version: 0.0.0 +// Purpose: +// Category: +// File Mask: +// ID Bytes: +// History: +//------------------------------------------------ +RequiresVersion( 12 ); + +/**** STRUCTURES ****/ +struct EgonHead; + +typedef struct { + uint32 jump_instruction ; + ubyte magic[8]; + uint32 checksum ; + uint32 total_length ; + uint32 _head_size; + uint32 fel_script_address; + uint32 fel_uenv_length; + uint32 dt_name_offset; + uint32 dram_size; + uint32 boot_media; + uint32 string_pool[13]; +} EgonHead; + +/**** PARSING CODE ****/ +LittleEndian(); + +EgonHead head ; + +local uint32 opcode = head.jump_instruction & 0x7f; +// 0x6f JAL opcode +if (opcode == 0x6f) +{ + local uint32 imm1912 = (head.jump_instruction >> 12) & 0xff; + local uint32 imm11 = (head.jump_instruction >> 20) & 0x01; + local uint32 imm101 = (head.jump_instruction >> 21) & 0x3ff; + local uint32 imm20 = (head.jump_instruction >> 31) & 0x01; + local uint32 offset = (imm20 << 20) + (imm1912 << 12) + (imm11 << 11) + (imm101 << 1); + + local quad off = FTell(); + if(offset < FileSize() && head.total_length <= FileSize()) { + FSeek(offset); + ubyte code[head.total_length - offset] ; + } else { + Warning("code appears to either overlap with header, exist after the end of the file or overlap with the end of the file!"); + } + FSeek(off); +} diff --git a/README.md b/README.md index c2e1a80..9ff4d76 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,11 @@ | 芯片型号 | 链接 | |:----|:----| | BL808 | [BL808Image.bt](./BL808Image.bt) | +| D1 | [D1Image.bt](./D1Image.bt) | ## 许可协议 -本项目采用木兰宽松许可证,第2版。 +本项目采用木兰宽松许可证,第2版。 ``` Copyright (c) 2023 RustSBI Team -- Gitee