[feat] add flash ld script and jump to flash

This commit is contained in:
zhji 2025-05-10 22:21:01 +08:00
parent c5c43d5b23
commit d5f776d614
3 changed files with 65 additions and 8 deletions

View File

@ -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;

63
flash.ld Normal file
View File

@ -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
}

View File

@ -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