From 1f1d7082a59755d5ba1d28619d4dcf078f902762 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 24 Apr 2023 14:14:56 +0200 Subject: [PATCH] sys/slot_aux: add build system integration for AUX slot --- sys/Makefile.include | 3 +++ sys/riotboot/Makefile.include | 2 +- sys/slot_aux/Makefile.include | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 sys/slot_aux/Makefile.include diff --git a/sys/Makefile.include b/sys/Makefile.include index 9464ca2df7..617f62fce9 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -110,6 +110,9 @@ ifneq (,$(filter scanf_float,$(USEMODULE))) endif endif +# we need to include this before the riotboot include +include $(RIOTBASE)/sys/slot_aux/Makefile.include + ifneq (,$(filter riotboot,$(FEATURES_USED))) include $(RIOTBASE)/sys/riotboot/Makefile.include endif diff --git a/sys/riotboot/Makefile.include b/sys/riotboot/Makefile.include index b81e69716b..d0182d3812 100644 --- a/sys/riotboot/Makefile.include +++ b/sys/riotboot/Makefile.include @@ -9,7 +9,7 @@ RIOTBOOT_HDR_LEN ?= 0x100 NUM_SLOTS ?= 2 # Take the whole flash minus RIOTBOOT_LEN and divide it by NUM_SLOTS -SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) +SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-$(RIOTBOOT_LEN)-$(SLOT_AUX_LEN)) / $(NUM_SLOTS)))) SLOT1_LEN ?= $(SLOT0_LEN) SLOT0_LEN := $(SLOT0_LEN) SLOT1_LEN := $(SLOT1_LEN) diff --git a/sys/slot_aux/Makefile.include b/sys/slot_aux/Makefile.include new file mode 100644 index 0000000000..729d0d0c2d --- /dev/null +++ b/sys/slot_aux/Makefile.include @@ -0,0 +1,15 @@ +# This adds an optional AUX slot to flash that can be used to store persistent data. +# It will work with and without riotboot, but the size of the slot must remain fixed across +# firmware versions. + +# Size of the AUX slot in Bytes - must align with flash page size +SLOT_AUX_LEN ?= 0 +SLOT_AUX_OFFSET ?= $(shell echo $$(($(ROM_LEN:%K=%*1024)-$(SLOT_AUX_LEN)))) + +LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_slot_aux_offset=$(SLOT_AUX_OFFSET) +LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_slot_aux_len=$(SLOT_AUX_LEN) + +ifneq (0, $(SLOT_AUX_LEN)) + CFLAGS += -DCONFIG_SLOT_AUX_OFFSET=$(SLOT_AUX_OFFSET) + CFLAGS += -DCONFIG_SLOT_AUX_LEN=$(SLOT_AUX_LEN) +endif