我正在使用 stm32cubeIDE 并尝试在二进制文件末尾存储 crc 以用于更新目的。我使用此方法是因为否则调试将无法工作,并且我必须将 .crc 区域标记为 NOLOAD 才能使调试工作。
我在闪存末尾有一个 CRC 部分,专门用于存储 CRC。
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K
BOOT (rx) : ORIGIN = 0x8000000, LENGTH = 40K
FLASH (rx) : ORIGIN = 0x800A000, LENGTH = 221172
CRC (rx) : ORIGIN = 0x803FFFC, LENGTH = 4
}
.crc :
{
. = ALIGN(4);
KEEP (*(.crc)) /* .version sections (constants, strings, etc.) */
KEEP (*(.crc*)) /* .version* sections (constants, strings, etc.) */
. = ALIGN(4);
} >CRC
我有一个包含CRC的二进制文件crc.bin,二进制文件的内容很简单:ABAB ABAB
我定义了一个 const 值,以便 crc 部分包含在 elf 文件中:
__attribute__((section(".crc"), used))
const uint32_t crc_placeholder = 0xFFFFFFFF;
我正在使用这些构建后命令:
arm-none-eabi-objdump -h DS_TEST_ST433CCU.elf&&arm-none-eabi-objdump -s -j .crc DS_TEST_ST433CCU.elf&&arm-none-eabi-objcopy --update-section .crc=crc.bin DS_TEST_ST433CCU.elf&&arm-none-eabi-objdump -s -j .crc DS_TEST_ST433CCU.elf&&arm-none-eabi-objcopy -O binary DS_TEST_ST433CCU.elf DS_TEST_ST433CCU1.bin
以下是这些命令的输出:
arm-none-eabi-objdump -h DS_TEST_ST433CCU.elf
DS_TEST_ST433CCU.elf: file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn
0 .isr_vector 0000018c 0800a000 0800a000 00001000 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .text 0000daac 0800a190 0800a190 00001190 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .rodata 00000628 08017c40 08017c40 0000ec40 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .ARM.extab 00000000 08018268 08018268 00011000 2**0
CONTENTS
4 .ARM 00000008 08018268 08018268 0000f268 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .preinit_array 00000000 08018270 08018270 00011000 2**0
CONTENTS, ALLOC, LOAD, DATA
6 .init_array 00000004 08018270 08018270 0000f270 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .fini_array 00000004 08018274 08018274 0000f274 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .data 000001e0 20000000 08018278 00010000 2**2
CONTENTS, ALLOC, LOAD, DATA
9 .bss 00002da8 200001e0 08018458 000101e0 2**2
ALLOC
10 ._user_heap_stack 00000600 20002f88 08018458 00010f88 2**0
ALLOC
11 .boot_app 00000000 08000000 08000000 00011000 2**0
CONTENTS
12 .crc 00000004 0803fffc 0803fffc 00010ffc 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
13 .ARM.attributes 00000030 00000000 00000000 00011000 2**0
CONTENTS, READONLY
14 .debug_info 0001fa45 00000000 00000000 00011030 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
15 .debug_abbrev 00005211 00000000 00000000 00030a75 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
16 .debug_aranges 00001d98 00000000 00000000 00035c88 2**3
CONTENTS, READONLY, DEBUGGING, OCTETS
17 .debug_rnglists 00001685 00000000 00000000 00037a20 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
18 .debug_macro 00029dc0 00000000 00000000 000390a5 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
19 .debug_line 00020976 00000000 00000000 00062e65 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
20 .debug_str 000efcb8 00000000 00000000 000837db 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
21 .comment 00000043 00000000 00000000 00173493 2**0
CONTENTS, READONLY
22 .debug_frame 00008dc8 00000000 00000000 001734d8 2**2
CONTENTS, READONLY, DEBUGGING, OCTETS
23 .debug_line_str 0000005e 00000000 00000000 0017c2a0 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
arm-none-eabi-objdump -s -j .crc DS_TEST_ST433CCU.elf
DS_TEST_ST433CCU.elf: file format elf32-littlearm
Contents of section .crc:
803fffc ffffffff ....
arm-none-eabi-objcopy --update-section .crc=crc.bin DS_TEST_ST433CCU.elf
arm-none-eabi-objdump -s -j .crc DS_TEST_ST433CCU.elf
DS_TEST_ST433CCU.elf: file format elf32-littlearm
Contents of section .crc:
803fffc 66666666 20666666 66 abab abab
arm-none-eabi-objcopy -O binary DS_TEST_ST433CCU.elf DS_TEST_ST433CCU1.bin
这些 66666666 20666666 66 从哪里进入 elf 文件?最终的二进制文件甚至不包含 abab abab。
66666666 20666666 66
字面上是字符串ffff ffff
- 不是十六进制,而是那些中间有空格的九个字节。您的 crc.bin 文件应该正好是四个字节长并且包含二进制数据,而不是 ASCII 文本。