From ca9ffbab7c5ca910c46707aff823ab1c1ebce0a5 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 10 Oct 2019 20:39:25 +0200 Subject: [PATCH] Configuration (via .config), single entry point for options --- .gitignore | 8 ++- Makefile | 78 ++++++++++++------------- config/Makefile | 8 +++ config/examples/hifive1.config | 21 +++++++ config/examples/stm32f7-dualbank.config | 22 +++++++ config/examples/stm32wb-small.config | 4 ++ hal/cc26x2.ld | 2 +- hal/hifive1.ld | 2 +- hal/kinetis.ld | 2 +- hal/nrf52.ld | 2 +- hal/samr21.ld | 2 +- hal/stm32f4.ld | 9 ++- hal/stm32f7.c | 4 +- hal/stm32f7.ld | 8 ++- hal/stm32g0.ld | 2 +- hal/stm32l0.ld | 2 +- hal/stm32wb.ld | 8 ++- include/{target.h => target.h.in} | 31 +++------- test-app/ARM-stm32f7.ld | 4 +- test-app/ARM.ld | 4 +- test-app/Makefile | 28 +++++++-- test-app/RISCV.ld | 2 +- test-app/standalone.ld | 2 + tools/config.mk | 40 +++++++++++++ 24 files changed, 210 insertions(+), 85 deletions(-) create mode 100644 config/Makefile create mode 100644 config/examples/hifive1.config create mode 100644 config/examples/stm32f7-dualbank.config create mode 100644 config/examples/stm32wb-small.config rename include/{target.h => target.h.in} (57%) create mode 100644 tools/config.mk diff --git a/.gitignore b/.gitignore index d99016b9..3ecbbca0 100644 --- a/.gitignore +++ b/.gitignore @@ -67,11 +67,17 @@ tools/ecc256/ecc256_keygen cscope.out tags -# Generated files using target.h +# Generated files +.wolfboot-config +include/target.h .wolfboot-arch-offset .wolfboot-offset .wolfboot-partition-size +.bootloader-partition-size # Test tools tools/test-expect-version/test-expect-version tools/test-update-server/server +config/*.ld + + diff --git a/Makefile b/Makefile index 350f8420..ab61d159 100644 --- a/Makefile +++ b/Makefile @@ -3,34 +3,13 @@ # Configure by passing alternate values # via environment variables. # -# Default values: -ARCH?=ARM -TARGET?=stm32f4 -SIGN?=ED25519 -KINETIS?=$(HOME)/src/FRDM-K64F -KINETIS_CPU=MK64FN1M0VLL12 -KINETIS_DRIVERS?=$(KINETIS)/devices/MK64F12 -KINETIS_CMSIS?=$(KINETIS)/CMSIS -FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk -DEBUG?=0 -VTOR?=1 -CORTEX_M0?=0 -NO_ASM?=0 -EXT_FLASH?=0 -SPI_FLASH?=0 -ALLOW_DOWNGRADE?=0 -NVM_FLASH_WRITEONCE?=0 -WOLFBOOT_VERSION?=0 -V?=0 -SPMATH?=1 -RAM_CODE?=0 -DUALBANK_SWAP=0 - - +# Configuration values: see tools/config.mk +-include .config +include tools/config.mk ## Initializers CFLAGS:=-D__WOLFBOOT -DWOLFBOOT_VERSION=$(WOLFBOOT_VERSION)UL -LSCRIPT:=hal/$(TARGET).ld +LSCRIPT:=config/target.ld LDFLAGS:=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=wolfboot.map -ffreestanding -nostartfiles OBJS:= \ ./hal/$(TARGET).o \ @@ -43,6 +22,7 @@ OBJS:= \ ./lib/wolfssl/wolfcrypt/src/wolfmath.o \ ./lib/wolfssl/wolfcrypt/src/fe_low_mem.o + ## Architecture/CPU configuration include arch.mk @@ -136,26 +116,23 @@ wolfboot.hex: wolfboot.elf $(Q)$(OBJCOPY) -O ihex $^ $@ align: wolfboot-align.bin - -wolfboot-align.bin: wolfboot.bin - @cat include/target.h | grep WOLFBOOT_PARTITION_BOOT_ADDRESS | tr -d "\n\r" | sed -e "s/.*[ ]//g" > .wolfboot-offset - @printf "%d" `cat .wolfboot-offset` > .wolfboot-offset + +.bootloader-partition-size: + @printf "%d" $(WOLFBOOT_PARTITION_BOOT_ADDRESS) > .wolfboot-offset @printf "%d" $(ARCH_FLASH_OFFSET) > .wolfboot-arch-offset - @expr `cat .wolfboot-offset` - `cat .wolfboot-arch-offset` > .wolfboot-partition-size - @dd if=/dev/zero bs=`cat .wolfboot-partition-size` count=1 2>/dev/null | tr "\000" "\377" > $(@) - @#rm -f .wolfboot-partition-size .wolfboot-offset .wolfboot-arch-offset - @dd if=$^ of=$(@) conv=notrunc 2>/dev/null + @expr `cat .wolfboot-offset` - `cat .wolfboot-arch-offset` > .bootloader-partition-size + @rm -f .wolfboot-offset .wolfboot-arch-offset + +wolfboot-align.bin: .bootloader-partition-size wolfboot.bin + @dd if=/dev/zero bs=`cat .bootloader-partition-size` count=1 2>/dev/null | tr "\000" "\377" > $(@) + @dd if=wolfboot.bin of=$(@) conv=notrunc 2>/dev/null @echo @echo "\t[SIZE]" @$(SIZE) wolfboot.elf @echo -test-app/image.bin: - @make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) \ - V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\ - KINETIS=$(KINETIS) KINETIS_CPU=$(KINETIS_CPU) KINETIS_DRIVERS=$(KINETIS_DRIVERS) \ - KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \ - FREEDOM_E_SDK=$(FREEDOM_E_SDK) +test-app/image.bin: wolfboot-align.bin + @make -C test-app @rm -f src/*.o hal/*.o @$(SIZE) test-app/image.elf @@ -173,10 +150,15 @@ factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY) @echo "\t[MERGE] $@" @cat wolfboot-align.bin test-app/image_v1_signed.bin > $@ -wolfboot.elf: $(OBJS) $(LSCRIPT) +wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) @echo "\t[LD] $@" $(Q)$(LD) $(LDFLAGS) -Wl,--start-group $(OBJS) -Wl,--end-group -o $@ +$(LSCRIPT): hal/$(TARGET).ld .bootloader-partition-size FORCE + @cat hal/$(TARGET).ld | \ + sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/`cat .bootloader-partition-size`/g" \ + > $@ + src/ed25519_pub_key.c: ed25519.der src/ecc256_pub_key.c: ecc256.der @@ -185,12 +167,23 @@ keys: $(PRIVATE_KEY) clean: @find . -type f -name "*.o" | xargs rm -f - @rm -f *.bin *.elf wolfboot.map *.bin *.hex + @rm -f *.bin *.elf wolfboot.map *.bin *.hex config/target.ld @make -C test-app clean distclean: clean - @rm -f *.pem *.der tags ./src/ed25519_pub_key.c ./src/ecc256_pub_key.c + @rm -f *.pem *.der tags ./src/ed25519_pub_key.c ./src/ecc256_pub_key.c include/target.h +include/target.h: include/target.h.in FORCE + @cat include/target.h.in | \ + sed -e "s/##WOLFBOOT_PARTITION_SIZE##/$(WOLFBOOT_PARTITION_SIZE)/g" | \ + sed -e "s/##WOLFBOOT_SECTOR_SIZE##/$(WOLFBOOT_SECTOR_SIZE)/g" | \ + sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/$(WOLFBOOT_PARTITION_BOOT_ADDRESS)/g" | \ + sed -e "s/##WOLFBOOT_PARTITION_UPDATE_ADDRESS##/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \ + sed -e "s/##WOLFBOOT_PARTITION_SWAP_ADDRESS##/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" \ + > $@ + +config: FORCE + make -C config %.o:%.c @echo "\t[CC-$(ARCH)] $@" @@ -202,3 +195,4 @@ distclean: clean FORCE: +.PHONY: FORCE clean diff --git a/config/Makefile b/config/Makefile new file mode 100644 index 00000000..3426c063 --- /dev/null +++ b/config/Makefile @@ -0,0 +1,8 @@ +-include ../.config +include ../tools/config.mk +config: + rm -f ../config/target.ld + rm -f ../.config + rm -f ../include/target.h + @$(foreach q, $(CONFIG_VARS), a=$($q); echo -n $q \? [$$a] :; a=$($q); read SH_$q; test -z $$SH_$q && SH_$q=$$a; echo "$q?=$$SH_$q" >> ../.config;) + diff --git a/config/examples/hifive1.config b/config/examples/hifive1.config new file mode 100644 index 00000000..f793db3c --- /dev/null +++ b/config/examples/hifive1.config @@ -0,0 +1,21 @@ +ARCH?=RISCV +TARGET?=hifive1 +SIGN?=ECC256 +FREEDOM_E_SDK?=~/src/freedom-e-sdk +DEBUG?=0 +VTOR?=1 +CORTEX_M0?=0 +NO_ASM?=1 +ALLOW_DOWNGRADE?=0 +NVM_FLASH_WRITEONCE?=0 +WOLFBOOT_VERSION?=1 +V?=0 +SPMATH?=1 +RAM_CODE?=1 +DUALBANK_SWAP?=0 +IMAGE_HEADER_SIZE?=256 +WOLFBOOT_PARTITION_SIZE?=0x80000 +WOLFBOOT_SECTOR_SIZE?=0x1000 +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x20020000 +WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x20060000 +WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x200A0000 diff --git a/config/examples/stm32f7-dualbank.config b/config/examples/stm32f7-dualbank.config new file mode 100644 index 00000000..4017af79 --- /dev/null +++ b/config/examples/stm32f7-dualbank.config @@ -0,0 +1,22 @@ +ARCH?=ARM +TARGET?=stm32f7 +SIGN?=ECC256 +DEBUG?=0 +VTOR?=1 +CORTEX_M0?=0 +NO_ASM?=0 +EXT_FLASH?=0 +SPI_FLASH?=0 +ALLOW_DOWNGRADE?=0 +NVM_FLASH_WRITEONCE?=0 +WOLFBOOT_VERSION?=1 +V?=0 +SPMATH?=1 +RAM_CODE?=1 +DUALBANK_SWAP?=1 +IMAGE_HEADER_SIZE?=256 +WOLFBOOT_PARTITION_SIZE?=0x80000 +WOLFBOOT_SECTOR_SIZE?=0x20000 +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8020000 +WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x8120000 +WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x0 diff --git a/config/examples/stm32wb-small.config b/config/examples/stm32wb-small.config new file mode 100644 index 00000000..ac6f5e56 --- /dev/null +++ b/config/examples/stm32wb-small.config @@ -0,0 +1,4 @@ +TARGET=stm32wb +SIGN=ECC256 +WOLFBOOT_PARTITION_BOOT_ADDRESS=0xA000 +WOLFBOOT_PARTITION_SIZE=0x4000 diff --git a/hal/cc26x2.ld b/hal/cc26x2.ld index d72c2ece..9f31418e 100644 --- a/hal/cc26x2.ld +++ b/hal/cc26x2.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x0010000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0xD800 } diff --git a/hal/hifive1.ld b/hal/hifive1.ld index d49fd078..b1f2e88d 100644 --- a/hal/hifive1.ld +++ b/hal/hifive1.ld @@ -4,7 +4,7 @@ ENTRY( _reset ) MEMORY { - FLASH(rxai!w) : ORIGIN = 0x20010000, LENGTH = 64K + FLASH(rxai!w) : ORIGIN = 0x20010000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM(wxa!ri) : ORIGIN = 0x80000000, LENGTH = 16K } diff --git a/hal/kinetis.ld b/hal/kinetis.ld index 0abb26fc..e9a69bbc 100644 --- a/hal/kinetis.ld +++ b/hal/kinetis.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x000A000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 64K } diff --git a/hal/nrf52.ld b/hal/nrf52.ld index 76f38fbc..005dde60 100644 --- a/hal/nrf52.ld +++ b/hal/nrf52.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x0001f000, LENGTH = 0x0010000 + FLASH (rx) : ORIGIN = 0x0001f000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0xD800 } diff --git a/hal/samr21.ld b/hal/samr21.ld index 2a64d8f6..e9ad7883 100644 --- a/hal/samr21.ld +++ b/hal/samr21.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x0010000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 } diff --git a/hal/stm32f4.ld b/hal/stm32f4.ld index b7aa7fa8..2515690c 100644 --- a/hal/stm32f4.ld +++ b/hal/stm32f4.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x001FFE0 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 } @@ -16,6 +16,13 @@ SECTIONS _end_text = .; } > FLASH + .edidx : + { + . = ALIGN(4); + *(.ARM.exidx*) + } > FLASH + + _stored_data = .; .data : AT (_stored_data) { diff --git a/hal/stm32f7.c b/hal/stm32f7.c index 082dd24e..a026f0aa 100644 --- a/hal/stm32f7.c +++ b/hal/stm32f7.c @@ -489,7 +489,9 @@ void RAMFUNCTION fork_bootloader(void) flash_erase_sector(i); hal_flash_write(WOLFBOOT_ORIG_BOOTLOADER, bootloader_copy_mem, BOOTLOADER_SIZE); hal_flash_lock(); - arch_reboot(); +#ifdef __WOLFBOOT + //arch_reboot(); +#endif } diff --git a/hal/stm32f7.ld b/hal/stm32f7.ld index c235f530..d4a408eb 100644 --- a/hal/stm32f7.ld +++ b/hal/stm32f7.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x001FFE0 + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 /* mapping TCM only */ } @@ -15,6 +15,12 @@ SECTIONS . = ALIGN(4); _end_text = .; } > FLASH + + .edidx : + { + . = ALIGN(4); + *(.ARM.exidx*) + } > FLASH _stored_data = .; .data : AT (_stored_data) diff --git a/hal/stm32g0.ld b/hal/stm32g0.ld index bdf6c0b0..a22ac309 100644 --- a/hal/stm32g0.ld +++ b/hal/stm32g0.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x8000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008FFF } diff --git a/hal/stm32l0.ld b/hal/stm32l0.ld index e8634b92..72507e5c 100644 --- a/hal/stm32l0.ld +++ b/hal/stm32l0.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x8000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K } diff --git a/hal/stm32wb.ld b/hal/stm32wb.ld index 69857e96..8f1e49ef 100644 --- a/hal/stm32wb.ld +++ b/hal/stm32wb.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x8000 + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00030000 } @@ -15,6 +15,12 @@ SECTIONS . = ALIGN(4); _end_text = .; } > FLASH + + .edidx : + { + . = ALIGN(4); + *(.ARM.exidx*) + } > FLASH _stored_data = .; .data : AT (_stored_data) diff --git a/include/target.h b/include/target.h.in similarity index 57% rename from include/target.h rename to include/target.h.in index 835a8c74..9342bf17 100644 --- a/include/target.h +++ b/include/target.h.in @@ -2,6 +2,8 @@ * * User configurable build-time options for bootloader and application offsets * + * target.h is automatically generated using the template in target.h.in by running + * "make config". * * Copyright (C) 2019 wolfSSL Inc. * @@ -25,30 +27,11 @@ #ifndef H_TARGETS_TARGET_ #define H_TARGETS_TARGET_ -/* Example flash partitioning. - * Ensure that your firmware entry point is - * at FLASH_AREA_IMAGE_0_OFFSET + 0x100 - */ +#define WOLFBOOT_SECTOR_SIZE ##WOLFBOOT_SECTOR_SIZE## +#define WOLFBOOT_PARTITION_BOOT_ADDRESS ##WOLFBOOT_PARTITION_BOOT_ADDRESS## +#define WOLFBOOT_PARTITION_SIZE ##WOLFBOOT_PARTITION_SIZE## +#define WOLFBOOT_PARTITION_UPDATE_ADDRESS ##WOLFBOOT_PARTITION_UPDATE_ADDRESS## +#define WOLFBOOT_PARTITION_SWAP_ADDRESS ##WOLFBOOT_PARTITION_SWAP_ADDRESS## -#define WOLFBOOT_SECTOR_SIZE 0x20000 -#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000 - -#ifdef EXT_FLASH - -/* Test configuration with 1MB external memory */ -/* (Addresses are relative to the beginning of the ext)*/ - -#define WOLFBOOT_PARTITION_SIZE 0x80000 -#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x00000 -#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x80000 - -#else - -/* Test configuration with internal memory */ -#define WOLFBOOT_PARTITION_SIZE 0x20000 -#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x40000 -#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000 - -#endif #endif /* !H_TARGETS_TARGET_ */ diff --git a/test-app/ARM-stm32f7.ld b/test-app/ARM-stm32f7.ld index 826ce62c..ee9639a3 100644 --- a/test-app/ARM-stm32f7.ld +++ b/test-app/ARM-stm32f7.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x08020100, LENGTH = 0x001FF00 + FLASH (rx) : ORIGIN = ##WOLFBOOT_TEST_APP_ADDRESS##, LENGTH = ##WOLFBOOT_TEST_APP_SIZE## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 } @@ -25,6 +25,8 @@ SECTIONS _start_data = .; KEEP(*(.data*)) . = ALIGN(4); + KEEP(*(.ramcode)) + . = ALIGN(4); _end_data = .; } > RAM diff --git a/test-app/ARM.ld b/test-app/ARM.ld index c1306af5..24318aed 100644 --- a/test-app/ARM.ld +++ b/test-app/ARM.ld @@ -1,6 +1,6 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x0020100, LENGTH = 0x005FFF + FLASH (rx) : ORIGIN = ##WOLFBOOT_TEST_APP_ADDRESS##, LENGTH = ##WOLFBOOT_TEST_APP_SIZE## RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K /* Run in lowmem */ } @@ -25,6 +25,8 @@ SECTIONS _start_data = .; KEEP(*(.data*)) . = ALIGN(4); + KEEP(*(.ramcode)) + . = ALIGN(4); _end_data = .; } > RAM diff --git a/test-app/Makefile b/test-app/Makefile index 6984b7a4..2d874692 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -1,3 +1,5 @@ +-include ../.config +-include ../tools/config.mk TARGET?=none ARCH?=ARM KINETIS_CMSIS?=$(KINETIS)/CMSIS @@ -19,9 +21,11 @@ ifeq ($(V),0) Q=@ endif -LSCRIPT:=$(ARCH).ld +ENTRY_POINT=`cat .entry-point-address` +LSCRIPT:=../config/target-app.ld +LSCRIPT_TEMPLATE:=$(ARCH).ld ifeq ($(TARGET),stm32f7) - LSCRIPT=ARM-stm32f7.ld + LSCRIPT_TEMPLATE=ARM-stm32f7.ld CFLAGS+=-DDUALBANK_SWAP endif LDFLAGS:=$(CFLAGS) -T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map @@ -38,7 +42,7 @@ endif ifeq ($(TARGET),kinetis) CFLAGS+= -I$(KINETIS_DRIVERS)/drivers -I$(KINETIS_DRIVERS) -DCPU_$(KINETIS_CPU) -I$(KINETIS_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DNVM_FLASH_WRITEONCE=1 APP_OBJS+= $(KINETIS_DRIVERS)/drivers/fsl_clock.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_flash.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_cache.o \ - $(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o $(KINETIS_DRIVERS)/drivers/fsl_gpio.o + $(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o $(KINETIS_DRIVERS)/drivers/fsl_gpio.o endif ifeq ($(TARGET),stm32g0) @@ -102,4 +106,20 @@ standalone: image.bin $(Q)$(CC) $(CFLAGS) -c -o $@ $^ clean: - @rm -f *.bin *.elf tags *.o + @rm -f *.bin *.elf tags *.o $(LSCRIPT) + +$(LSCRIPT): $(LSCRIPT_TEMPLATE) FORCE + @printf "%d" $(WOLFBOOT_PARTITION_BOOT_ADDRESS) > .wolfboot-offset + @printf "%d" $(WOLFBOOT_PARTITION_SIZE) > .partition-size + @printf "%d" $(IMAGE_HEADER_SIZE) > .header-size + @expr `cat .wolfboot-offset` + `cat .header-size` > .entry-point + @printf "0x%X" `cat .entry-point` > .entry-point + @expr `cat .partition-size` - `cat .header-size` > .app-size + @printf "0x%X" `cat .app-size` > .app-size + @ cat $(LSCRIPT_TEMPLATE) | \ + sed -e "s/##WOLFBOOT_TEST_APP_SIZE##/`cat .app-size`/g" | \ + sed -e "s/##WOLFBOOT_TEST_APP_ADDRESS##/`cat .entry-point`/g" \ + > $(@) + @rm -f .app-size .entry-point .wolfboot-offset .partition-size .header-size + +.PHONY: FORCE clean diff --git a/test-app/RISCV.ld b/test-app/RISCV.ld index 84f024c4..57947eec 100644 --- a/test-app/RISCV.ld +++ b/test-app/RISCV.ld @@ -4,7 +4,7 @@ ENTRY( _reset ) MEMORY { - FLASH(rxai!w) : ORIGIN = 0x20020100, LENGTH = 256K - 0x100 + FLASH(rxai!w) : ORIGIN = ##WOLFBOOT_TEST_APP_ADDRESS##, LENGTH = ##WOLFBOOT_TEST_APP_SIZE## RAM(wxa!ri) : ORIGIN = 0x80001000, LENGTH = 12K } diff --git a/test-app/standalone.ld b/test-app/standalone.ld index 3deb9753..e4624333 100644 --- a/test-app/standalone.ld +++ b/test-app/standalone.ld @@ -28,6 +28,8 @@ SECTIONS _start_data = .; KEEP(*(.data*)) . = ALIGN(4); + KEEP(*(.ramcode)) + . = ALIGN(4); _end_data = .; } > RAM diff --git a/tools/config.mk b/tools/config.mk new file mode 100644 index 00000000..a93b8ea3 --- /dev/null +++ b/tools/config.mk @@ -0,0 +1,40 @@ +#Defaults, used by CI +ifeq ($(ARCH),) + ARCH?=ARM + TARGET?=stm32f4 + SIGN?=ED25519 + KINETIS?=$(HOME)/src/FRDM-K64F + KINETIS_CPU=MK64FN1M0VLL12 + KINETIS_DRIVERS?=$(KINETIS)/devices/MK64F12 + KINETIS_CMSIS?=$(KINETIS)/CMSIS + FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk + DEBUG?=0 + VTOR?=1 + CORTEX_M0?=0 + NO_ASM?=0 + EXT_FLASH?=0 + SPI_FLASH?=0 + ALLOW_DOWNGRADE?=0 + NVM_FLASH_WRITEONCE?=0 + WOLFBOOT_VERSION?=0 + V?=0 + SPMATH?=1 + RAM_CODE?=0 + DUALBANK_SWAP=0 + IMAGE_HEADER_SIZE?=256 + WOLFBOOT_PARTITION_SIZE?=0x20000 + WOLFBOOT_SECTOR_SIZE?=0x20000 + WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x20000 + WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x40000 + WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x60000 +endif + + +CONFIG_VARS:= ARCH TARGET SIGN KINETIS KINETIS_CPU KINETIS_DRIVERS \ + KINETIS_CMSIS FREEDOM_E_SDK DEBUG VTOR CORTEX_M0 NO_ASM EXT_FLASH \ + SPI_FLASH ALLOW_DOWNGRADE NVM_FLASH_WRITEONCE WOLFBOOT_VERSION V \ + SPMATH RAM_CODE DUALBANK_SWAP IMAGE_HEADER_SIZE \ + WOLFBOOT_PARTITION_SIZE WOLFBOOT_SECTOR_SIZE \ + WOLFBOOT_PARTITION_BOOT_ADDRESS WOLFBOOT_PARTITION_UPDATE_ADDRESS \ + WOLFBOOT_PARTITION_SWAP_ADDRESS +