-
Notifications
You must be signed in to change notification settings - Fork 16
/
wolfboot.mk
70 lines (55 loc) · 2.22 KB
/
wolfboot.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
ifdef WOLFBOOT_OFFSET
WOLFBOOT:=$(abspath $(RIOTBASE)/../../wolfBoot/)
CFLAGS += -I$(WOLFBOOT)/include
SIGNTOOL ?= python3 $(WOLFBOOT)/tools/keytools/sign.py
KEYGENTOOL ?= python3 $(WOLFBOOT)/tools/keytools/keygen.py
BINFILE ?= $(BINDIR)/$(APPLICATION).bin
SIGN_BINFILE = $(BINDIR)/$(APPLICATION)_v5_signed.bin
WOLFBOOT_KEYFILE ?= $(WOLFBOOT)/ed25519.der
WOLFBOOT_BIN ?= $(WOLFBOOT)/wolfboot.bin
export IMAGE_HDR_SIZE ?= 256
wolfboot-create-key: $(WOLFBOOT_KEYFILE)
$(WOLFBOOT_KEYFILE):
make -C $(WOLFBOOT) clean
make -C $(WOLFBOOT) distclean
make -C $(WOLFBOOT) TARGET=samr21 DEBUG=0 ed25519.der \
wolfboot: wolfboot-create-key link
@$(COLOR_ECHO)
@$(COLOR_ECHO) '$(COLOR_PURPLE)Re-linking for wolfBoot at $(WOLFBOOT_OFFSET)...$(COLOR_RESET)'
@$(COLOR_ECHO)
@$(COLOR_ECHO) 'sources:'
@$(COLOR_ECHO) $(SRC)
@$(COLOR_ECHO)
$(_LINK) $(LINKFLAGPREFIX)--defsym=_rom_start_addr="$$(($(WOLFBOOT_OFFSET) + $(IMAGE_HDR_SIZE)))" \
$(LINKFLAGPREFIX)--defsym=length="$$(($(WOLFBOOT_PARTITION_SIZE) - $(IMAGE_HDR_SIZE)))" \
$(LINKFLAGPREFIX)--defsym=image_header="$(IMAGE_HDR_SIZE)" -o $(ELFFILE) && \
$(OBJCOPY) $(OFLAGS) -Obinary $(ELFFILE) $(BINFILE) && \
$(SIGNTOOL) $(BINFILE) $(WOLFBOOT_KEYFILE) $(IMAGE_VERSION) $(WOLFBOOT_OFFSET)
@$(COLOR_ECHO)
@$(COLOR_ECHO) '$(COLOR_PURPLE)Signed with $(WOLFBOOT_KEYFILE) for version $(IMAGE_VERSION) \
$(COLOR_RESET)'
@$(COLOR_ECHO)
$(WOLFBOOT_BIN):
@$(COLOR_ECHO) 'sources:'
@$(COLOR_ECHO) $(SRC)
@$(COLOR_ECHO)
make -C $(WOLFBOOT) clean
make -C $(WOLFBOOT) TARGET=samr21 TARGET_ARCH= DEBUG=0 BOOT0_OFFSET=$(WOLFBOOT_OFFSET) \
WOLFBOOT_SECTOR_SIZE=0x100 \
WOLFBOOT_PARTITION_SIZE=0x1B000 \
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08000 \
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x23000 \
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x3E000 \
wolfboot.bin
.PHONY: wolfboot-flash-bootloader wolfboot-flash
wolfboot-flash-bootloader: HEXFILE = $(WOLFBOOT_BIN)
wolfboot-flash-bootloader: $(WOLFBOOT_BIN) $(FLASHDEPS)
sudo $(FLASHER) $(FFLAGS) -o 0x0
wolfboot-flash: HEXFILE = $(SIGN_BINFILE)
wolfboot-flash: wolfboot $(FLASHDEPS) wolfboot-flash-bootloader
sudo $(FLASHER) $(FFLAGS) -o $(WOLFBOOT_OFFSET)
else
wolfboot:
$(Q)echo "error: wolfboot not supported on board $(BOARD)!"
$(Q)false
endif # WOLFBOOT_OFFSET