From d5f776d614b00f1d6f29beea4fc2efe3aa7c53e7 Mon Sep 17 00:00:00 2001 From: zhji Date: Sat, 10 May 2025 22:21:01 +0800 Subject: [PATCH] [feat] add flash ld script and jump to flash --- example/boot2/main.c | 8 +----- flash.ld | 63 ++++++++++++++++++++++++++++++++++++++++++++ project.build | 2 +- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 flash.ld diff --git a/example/boot2/main.c b/example/boot2/main.c index 30a42d0..8b493c1 100644 --- a/example/boot2/main.c +++ b/example/boot2/main.c @@ -245,18 +245,12 @@ int main(void) } } if (boot_pin_high > boot_pin_low) { - printf("enter boot mode\r\n"); while (1) { uart_state_machine(UART_ID_0); } } else { - printf("enter flash mode\r\n"); flash_enter_quad_xip(6); - printf("xip success\r\n"); - for (uint32_t i = 0; i < 32; i += 4) { - printf("0x%08lX: 0x%08lX\r\n", 0x10000200 + i, *(volatile uint32_t *)(0x10000200 + i)); - } - jump_to_address(0x10100000); + jump_to_address(0x10010000 | 1); } return 0; diff --git a/flash.ld b/flash.ld new file mode 100644 index 0000000..a78a52d --- /dev/null +++ b/flash.ld @@ -0,0 +1,63 @@ +ENTRY(isr_reset) + +MEMORY +{ + FLASH (rx) :ORIGIN = 0x10010000, LENGTH = 4M - 64K + RAM (xrw) :ORIGIN = 0x20000000, LENGTH = 256K +} + +_stack_top = 0x20040000 + 4 * 1024; +_stack_top_core1 = 0x20041000 + 4 * 1024; + +PHDRS +{ + fw_header PT_LOAD FLAGS(5); /* R + X */ + text PT_LOAD FLAGS(5); /* R + X */ + rodata PT_LOAD FLAGS(6); /* R + W */ + data PT_LOAD FLAGS(6); /* R + W */ + bss PT_LOAD FLAGS(6); /* R + W */ +} + +SECTIONS +{ + .fw_header : + { + . = ALIGN(4); + KEEP(*(.fw_header)) + KEEP(*(.text.isr_reset)) + . = ALIGN(4); + } >FLASH :fw_header + + .text : + { + . = ALIGN(4); + *(*.text*) + . = ALIGN(4); + } >FLASH :text + + .rodata : + { + . = ALIGN(4); + *(*.rodata*) + . = ALIGN(4); + } >FLASH :rodata + + .data : + { + . = ALIGN(4); + _data_load = LOADADDR(.data); + _data_run = .; + *(*.data*) + . = ALIGN(4); + _data_run_end = .; + } >RAM AT>FLASH :data + + .bss (NOLOAD) : + { + . = ALIGN(4); + _bss_run = .; + *(*.bss*) + . = ALIGN(4); + _bss_run_end = .; + } >RAM :bss +} diff --git a/project.build b/project.build index 3d13023..4122bc5 100644 --- a/project.build +++ b/project.build @@ -12,7 +12,7 @@ CFLAGS += -fdata-sections CFLAGS += -Wpointer-arith ifneq ($(findstring -T, $(LDFLAGS)), -T) -LDFLAGS += -T$(SDK_BASE_DIR)/ram.ld +LDFLAGS += -T$(SDK_BASE_DIR)/flash.ld endif LDFLAGS += -mcpu=cortex-m0plus LDFLAGS += -mthumb