diff --git a/Makefile b/Makefile index 9e663fc9a..20c540beb 100644 --- a/Makefile +++ b/Makefile @@ -343,16 +343,26 @@ $(TARGET_BIN): $(TARGET_UNPATCHED_BIN) $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN) $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd - @echo "Patching MD5 hash into exst elf" "$(STDOUT)" - $(OBJCOPY) $(TARGET_ELF) --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) +# Note: From the objcopy manual "If you do not specify outfile, objcopy creates a temporary file and destructively renames the result with the name of infile" +# Due to this a temporary file must be created and removed, even though we're only extracting data from the input file. +# If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in +# a) regeneration of $(TARGET_BIN), and +# b) the results of $(TARGET_BIN) will not be as expected. + @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)" + $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) + rm $(TARGET_EXST_ELF).tmp + + @echo "Patching MD5 hash into HASH section" "$(STDOUT)" $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE) + + @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)" $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_HEX): $(TARGET_BIN) $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified")) - @echo "Creating EXST HEX from patched EXST ELF $(TARGET_HEX), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)" - $(V1) $(OBJCOPY) -O ihex --adjust-vma=$(EXST_ADJUST_VMA) --gap-fill=0x00 --pad-to=$(shell echo "$(FIRMWARE_SIZE)" | awk '{printf("0x%08x", (1024*$$1) + $(EXST_ADJUST_VMA));}') $(TARGET_EXST_ELF) $@ + @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)" + $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@ endif diff --git a/src/link/stm32_flash_h750_exst.ld b/src/link/stm32_flash_h750_exst.ld index a4abd652a..c043a6ef7 100644 --- a/src/link/stm32_flash_h750_exst.ld +++ b/src/link/stm32_flash_h750_exst.ld @@ -35,7 +35,8 @@ ENTRY(Reset_Handler) For H7 EXST (External Storage) targets a binary is built that is placed on an external device. The bootloader will then copy this entire binary to RAM, at the CODE_RAM address. The bootloader -then executes code at the CODE_RAM address. +then executes code at the CODE_RAM address. The address of CODE_RAM is fixed to 0x24010000 +and must not be changed. Currently, this is inefficient as there are two copies of some sections in RAM. e.g. .tcm_code. @@ -59,7 +60,7 @@ MEMORY ITCM_RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 64K DTCM_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 64K - CODE_RAM (rx) : ORIGIN = 0x24010000, LENGTH = 448K - _exst_hash_size + CODE_RAM (rx) : ORIGIN = 0x24010000, LENGTH = 448K - _exst_hash_size /* hard coded start address, as required by SPRACINGH7 boot loader, don't change! */ EXST_HASH (rx) : ORIGIN = 0x24010000 + LENGTH(CODE_RAM), LENGTH = _exst_hash_size D2_RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 256K /* SRAM1 + SRAM2 */ diff --git a/src/main/target/SPRACINGH7EXTREME/target.mk b/src/main/target/SPRACINGH7EXTREME/target.mk index 6530f82a3..791a8aee2 100644 --- a/src/main/target/SPRACINGH7EXTREME/target.mk +++ b/src/main/target/SPRACINGH7EXTREME/target.mk @@ -5,8 +5,7 @@ HSE_VALUE = 8000000 FEATURES += VCP ONBOARDFLASH SDCARD_SDIO EXST = yes -# flash address 0x97CE0000 - code_ram address (0x24010000) = 0x73CD0000 -EXST_ADJUST_VMA = 0x73CD0000 +EXST_ADJUST_VMA = 0x97CE0000 TARGET_SRC += \ diff --git a/src/main/target/SPRACINGH7NANO/target.mk b/src/main/target/SPRACINGH7NANO/target.mk index 68a9f25b0..a1ed7ad09 100644 --- a/src/main/target/SPRACINGH7NANO/target.mk +++ b/src/main/target/SPRACINGH7NANO/target.mk @@ -3,8 +3,7 @@ H750xB_TARGETS += $(TARGET) HSE_VALUE = 8000000 EXST = yes -# flash address 0x97CE0000 - code_ram address (0x24010000) = 0x73CD0000 -EXST_ADJUST_VMA = 0x73CD0000 +EXST_ADJUST_VMA = 0x97CE0000 FEATURES += VCP ONBOARDFLASH diff --git a/src/main/target/SPRACINGH7ZERO/target.mk b/src/main/target/SPRACINGH7ZERO/target.mk index 5b6cb7ccb..2c60241ea 100644 --- a/src/main/target/SPRACINGH7ZERO/target.mk +++ b/src/main/target/SPRACINGH7ZERO/target.mk @@ -3,8 +3,7 @@ H750xB_TARGETS += $(TARGET) HSE_VALUE = 8000000 EXST = yes -# flash address 0x97CE0000 - code_ram address (0x24010000) = 0x73CD0000 -EXST_ADJUST_VMA = 0x73CD0000 +EXST_ADJUST_VMA = 0x97CE0000 FEATURES += VCP ONBOARDFLASH SDCARD_SDIO