Skip to content

Commit 92d0478

Browse files
authored
Merge pull request #21 from wolfSSL/dotconfig
Dotconfig: Single entry point for all options
2 parents 45064ce + ea78a09 commit 92d0478

29 files changed

Lines changed: 309 additions & 98 deletions

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ tools/ecc256/ecc256_keygen
6767
cscope.out
6868
tags
6969

70-
# Generated files using target.h
70+
# Generated files
71+
.wolfboot-config
72+
include/target.h
7173
.wolfboot-arch-offset
7274
.wolfboot-offset
7375
.wolfboot-partition-size
76+
.bootloader-partition-size
7477

7578
# Test tools
7679
tools/test-expect-version/test-expect-version
7780
tools/test-update-server/server
81+
config/*.ld
82+
83+
# Generated confiuguration file
84+
.config

Makefile

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,13 @@
33
# Configure by passing alternate values
44
# via environment variables.
55
#
6-
# Default values:
7-
ARCH?=ARM
8-
TARGET?=stm32f4
9-
SIGN?=ED25519
10-
KINETIS?=$(HOME)/src/FRDM-K64F
11-
KINETIS_CPU=MK64FN1M0VLL12
12-
KINETIS_DRIVERS?=$(KINETIS)/devices/MK64F12
13-
KINETIS_CMSIS?=$(KINETIS)/CMSIS
14-
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
15-
DEBUG?=0
16-
VTOR?=1
17-
CORTEX_M0?=0
18-
NO_ASM?=0
19-
EXT_FLASH?=0
20-
SPI_FLASH?=0
21-
ALLOW_DOWNGRADE?=0
22-
NVM_FLASH_WRITEONCE?=0
23-
WOLFBOOT_VERSION?=0
24-
V?=0
25-
SPMATH?=1
26-
RAM_CODE?=0
27-
DUALBANK_SWAP=0
28-
29-
6+
# Configuration values: see tools/config.mk
7+
-include .config
8+
include tools/config.mk
309

3110
## Initializers
3211
CFLAGS:=-D__WOLFBOOT -DWOLFBOOT_VERSION=$(WOLFBOOT_VERSION)UL
33-
LSCRIPT:=hal/$(TARGET).ld
12+
LSCRIPT:=config/target.ld
3413
LDFLAGS:=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=wolfboot.map -ffreestanding -nostartfiles
3514
OBJS:= \
3615
./hal/$(TARGET).o \
@@ -43,6 +22,7 @@ OBJS:= \
4322
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
4423
./lib/wolfssl/wolfcrypt/src/fe_low_mem.o
4524

25+
4626
## Architecture/CPU configuration
4727
include arch.mk
4828

@@ -136,26 +116,23 @@ wolfboot.hex: wolfboot.elf
136116
$(Q)$(OBJCOPY) -O ihex $^ $@
137117

138118
align: wolfboot-align.bin
139-
140-
wolfboot-align.bin: wolfboot.bin
141-
@cat include/target.h | grep WOLFBOOT_PARTITION_BOOT_ADDRESS | tr -d "\n\r" | sed -e "s/.*[ ]//g" > .wolfboot-offset
142-
@printf "%d" `cat .wolfboot-offset` > .wolfboot-offset
119+
120+
.bootloader-partition-size:
121+
@printf "%d" $(WOLFBOOT_PARTITION_BOOT_ADDRESS) > .wolfboot-offset
143122
@printf "%d" $(ARCH_FLASH_OFFSET) > .wolfboot-arch-offset
144-
@expr `cat .wolfboot-offset` - `cat .wolfboot-arch-offset` > .wolfboot-partition-size
145-
@dd if=/dev/zero bs=`cat .wolfboot-partition-size` count=1 2>/dev/null | tr "\000" "\377" > $(@)
146-
@#rm -f .wolfboot-partition-size .wolfboot-offset .wolfboot-arch-offset
147-
@dd if=$^ of=$(@) conv=notrunc 2>/dev/null
123+
@expr `cat .wolfboot-offset` - `cat .wolfboot-arch-offset` > .bootloader-partition-size
124+
@rm -f .wolfboot-offset .wolfboot-arch-offset
125+
126+
wolfboot-align.bin: .bootloader-partition-size wolfboot.bin
127+
@dd if=/dev/zero bs=`cat .bootloader-partition-size` count=1 2>/dev/null | tr "\000" "\377" > $(@)
128+
@dd if=wolfboot.bin of=$(@) conv=notrunc 2>/dev/null
148129
@echo
149130
@echo "\t[SIZE]"
150131
@$(SIZE) wolfboot.elf
151132
@echo
152133

153-
test-app/image.bin:
154-
@make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) \
155-
V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\
156-
KINETIS=$(KINETIS) KINETIS_CPU=$(KINETIS_CPU) KINETIS_DRIVERS=$(KINETIS_DRIVERS) \
157-
KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
158-
FREEDOM_E_SDK=$(FREEDOM_E_SDK)
134+
test-app/image.bin: wolfboot-align.bin
135+
@make -C test-app
159136
@rm -f src/*.o hal/*.o
160137
@$(SIZE) test-app/image.elf
161138

@@ -173,10 +150,15 @@ factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY)
173150
@echo "\t[MERGE] $@"
174151
@cat wolfboot-align.bin test-app/image_v1_signed.bin > $@
175152

176-
wolfboot.elf: $(OBJS) $(LSCRIPT)
153+
wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT)
177154
@echo "\t[LD] $@"
178155
$(Q)$(LD) $(LDFLAGS) -Wl,--start-group $(OBJS) -Wl,--end-group -o $@
179156

157+
$(LSCRIPT): hal/$(TARGET).ld .bootloader-partition-size FORCE
158+
@cat hal/$(TARGET).ld | \
159+
sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/`cat .bootloader-partition-size`/g" \
160+
> $@
161+
180162
src/ed25519_pub_key.c: ed25519.der
181163

182164
src/ecc256_pub_key.c: ecc256.der
@@ -185,12 +167,23 @@ keys: $(PRIVATE_KEY)
185167

186168
clean:
187169
@find . -type f -name "*.o" | xargs rm -f
188-
@rm -f *.bin *.elf wolfboot.map *.bin *.hex
170+
@rm -f *.bin *.elf wolfboot.map *.bin *.hex config/target.ld
189171
@make -C test-app clean
190172

191173
distclean: clean
192-
@rm -f *.pem *.der tags ./src/ed25519_pub_key.c ./src/ecc256_pub_key.c
174+
@rm -f *.pem *.der tags ./src/ed25519_pub_key.c ./src/ecc256_pub_key.c include/target.h
175+
176+
include/target.h: include/target.h.in FORCE
177+
@cat include/target.h.in | \
178+
sed -e "s/##WOLFBOOT_PARTITION_SIZE##/$(WOLFBOOT_PARTITION_SIZE)/g" | \
179+
sed -e "s/##WOLFBOOT_SECTOR_SIZE##/$(WOLFBOOT_SECTOR_SIZE)/g" | \
180+
sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/$(WOLFBOOT_PARTITION_BOOT_ADDRESS)/g" | \
181+
sed -e "s/##WOLFBOOT_PARTITION_UPDATE_ADDRESS##/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \
182+
sed -e "s/##WOLFBOOT_PARTITION_SWAP_ADDRESS##/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" \
183+
> $@
193184

185+
config: FORCE
186+
make -C config
194187

195188
%.o:%.c
196189
@echo "\t[CC-$(ARCH)] $@"
@@ -202,3 +195,4 @@ distclean: clean
202195

203196
FORCE:
204197

198+
.PHONY: FORCE clean

config/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../.config
2+
include ../tools/config.mk
3+
config:
4+
rm -f ../config/target.ld
5+
rm -f ../.config
6+
rm -f ../include/target.h
7+
@$(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;)
8+

config/examples/hifive1.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARCH?=RISCV
2+
TARGET?=hifive1
3+
SIGN?=ECC256
4+
FREEDOM_E_SDK?=~/src/freedom-e-sdk
5+
DEBUG?=0
6+
VTOR?=1
7+
CORTEX_M0?=0
8+
NO_ASM?=1
9+
ALLOW_DOWNGRADE?=0
10+
NVM_FLASH_WRITEONCE?=0
11+
WOLFBOOT_VERSION?=1
12+
V?=0
13+
SPMATH?=1
14+
RAM_CODE?=1
15+
DUALBANK_SWAP?=0
16+
IMAGE_HEADER_SIZE?=256
17+
WOLFBOOT_PARTITION_SIZE?=0x80000
18+
WOLFBOOT_SECTOR_SIZE?=0x1000
19+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x20020000
20+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x20060000
21+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x200A0000

config/examples/stm32f4.config

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARCH?=ARM
2+
TARGET?=stm32f4
3+
SIGN?=ED25519
4+
DEBUG?=0
5+
VTOR?=1
6+
CORTEX_M0?=0
7+
NO_ASM?=0
8+
EXT_FLASH?=0
9+
SPI_FLASH?=0
10+
ALLOW_DOWNGRADE?=0
11+
NVM_FLASH_WRITEONCE?=0
12+
WOLFBOOT_VERSION?=0
13+
V?=0
14+
SPMATH?=1
15+
RAM_CODE?=0
16+
DUALBANK_SWAP?=0
17+
IMAGE_HEADER_SIZE?=256
18+
WOLFBOOT_PARTITION_SIZE?=0x20000
19+
WOLFBOOT_SECTOR_SIZE?=0x20000
20+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x20000
21+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x40000
22+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x60000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARCH?=ARM
2+
TARGET?=stm32f7
3+
SIGN?=ECC256
4+
DEBUG?=0
5+
VTOR?=1
6+
CORTEX_M0?=0
7+
NO_ASM?=0
8+
EXT_FLASH?=0
9+
SPI_FLASH?=0
10+
ALLOW_DOWNGRADE?=0
11+
NVM_FLASH_WRITEONCE?=0
12+
WOLFBOOT_VERSION?=1
13+
V?=0
14+
SPMATH?=1
15+
RAM_CODE?=1
16+
DUALBANK_SWAP?=1
17+
IMAGE_HEADER_SIZE?=256
18+
WOLFBOOT_PARTITION_SIZE?=0x80000
19+
WOLFBOOT_SECTOR_SIZE?=0x20000
20+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8020000
21+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x8120000
22+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x0

config/examples/stm32g0.config

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARCH?=ARM
2+
TARGET?=stm32g0
3+
SIGN?=ED25519
4+
DEBUG?=0
5+
VTOR?=1
6+
CORTEX_M0?=1
7+
NO_ASM?=0
8+
EXT_FLASH?=0
9+
SPI_FLASH?=0
10+
ALLOW_DOWNGRADE?=0
11+
NVM_FLASH_WRITEONCE?=1
12+
WOLFBOOT_VERSION?=0
13+
V?=0
14+
SPMATH?=1
15+
RAM_CODE?=0
16+
DUALBANK_SWAP?=0
17+
IMAGE_HEADER_SIZE?=256
18+
WOLFBOOT_PARTITION_SIZE?=0xB000
19+
WOLFBOOT_SECTOR_SIZE?=0x800
20+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
21+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x13000
22+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1E000

config/examples/stm32l0.config

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARCH?=ARM
2+
TARGET?=stm32l0
3+
SIGN?=ED25519
4+
DEBUG?=0
5+
VTOR?=1
6+
CORTEX_M0?=1
7+
NO_ASM?=0
8+
EXT_FLASH?=0
9+
SPI_FLASH?=0
10+
ALLOW_DOWNGRADE?=0
11+
NVM_FLASH_WRITEONCE?=0
12+
WOLFBOOT_VERSION?=0
13+
V?=0
14+
SPMATH?=1
15+
RAM_CODE?=0
16+
DUALBANK_SWAP?=0
17+
IMAGE_HEADER_SIZE?=256
18+
WOLFBOOT_PARTITION_SIZE?=0x10000
19+
WOLFBOOT_SECTOR_SIZE?=0x1000
20+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
21+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x18000
22+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x28000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TARGET=stm32wb
2+
SIGN=ECC256
3+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xA000
4+
WOLFBOOT_PARTITION_SIZE=0x4000

docs/compile.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ To enable specific compile options, use environment variables while calling make
77

88
`make CORTEX_M0=1`
99

10+
As an alternative, you can provide a .config file in the root directory of wolfBoot.
11+
Command line options have priority on `.config` options, as long as .config options are
12+
defined using the `?=` operator, e.g.:
13+
14+
`WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x14000`
15+
16+
## Generate a new configuration
17+
18+
A new `.config` file with a set of default parameters
19+
can be generated by running `make config`. The build script will ask to enter a default value for
20+
each configuration parameter. Enter confirm the current value, indicated in between `[]`.
21+
22+
Once a .config file is in place, it will change the default compile-time options when running `make`
23+
without parameters.
24+
25+
.config can be modified with a text editor to alter the default options later on.
26+
1027
## Platform selection
1128

1229
If supported natively, the target platform can be specified using the `TARGET` variable.
@@ -27,11 +44,11 @@ By default, wolfBoot is compiled for ARM Cortex-M3/4/7. To compile for Cortex-M0
2744

2845
### Flash partitions
2946

30-
The file [include/target.h](../include/target.h) must be modified according to flash geometry,
47+
The file [include/target.h](../include/target.h) is generated according to the configured flash geometry,
3148
partitions size and offset of the target system. The following values must be set to provide the
32-
desired flash configuration:
49+
desired flash configuration, either via the command line, or using the .config file:
3350

34-
`WOLFBOOT_SECTOR_SIZE`
51+
- `WOLFBOOT_SECTOR_SIZE`
3552

3653
This variable determines the size of the physical sector on the flash memory. If areas with different
3754
block sizes are used for the two partitions (e.g. update partition on an external flash), this variable
@@ -40,26 +57,26 @@ should indicate the size of the biggest sector shared between the two partitions
4057
WolfBoot uses this value as minimum unit when swapping the firmware images in place. For this reason,
4158
this value is also used to set the size of the SWAP partition.
4259

43-
`WOLFBOOT_PARTITION_BOOT_ADDRESS`
60+
- `WOLFBOOT_PARTITION_BOOT_ADDRESS`
4461

4562
This is the start address of the boot partition, aligned to the beginning of a new flash sector.
4663
The application code starts after a further offset, equal to the partition header size (256B
4764
for Ed25519 and ECC signature headers).
4865

49-
`WOLFBOOT_PARTITION_UPDATE_ADDRESS`
66+
- `WOLFBOOT_PARTITION_UPDATE_ADDRESS`
5067

5168
This is the start address of the update partition. If an external memory is used via the
5269
`EXT_FLASH` option, this variable contains the offset of the update partition from the
5370
beginning of the external memory addressable space.
5471

55-
`WOLFBOOT_PARTITION_SWAP_ADDRESS`
72+
- `WOLFBOOT_PARTITION_SWAP_ADDRESS`
5673

5774
The address for the swap spaced used by wolfBoot to swap the two firmware images in place,
5875
in order to perform a reversable update. The size of the SWAP partition is exactly one sector on the flash.
5976
If an external memory is used, the variable contains the offset of the SWAP area from the beginning
6077
of its addressable space.
6178

62-
`WOLFBOOT_PARTITION_SIZE`
79+
- `WOLFBOOT_PARTITION_SIZE`
6380

6481
The size of the BOOT and UPDATE partition. The size is the same for both partitions.
6582

0 commit comments

Comments
 (0)