From ac46418709990b3e9c61c31cc5d80e0d936c54fd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 26 Feb 2024 19:27:51 +0100 Subject: [PATCH 1/9] riotboot: set FW_ROM_LEN --- bootloaders/riotboot_common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootloaders/riotboot_common.mk b/bootloaders/riotboot_common.mk index de4975f94399..b30dbdd5bd0b 100644 --- a/bootloaders/riotboot_common.mk +++ b/bootloaders/riotboot_common.mk @@ -26,4 +26,4 @@ include $(RIOTBASE)/Makefile.include # limit riotboot bootloader size # TODO: Manage to set this variable for boards which already embed a # bootloader, currently it will be overwritten -ROM_LEN := $(RIOTBOOT_LEN) +FW_ROM_LEN := $(RIOTBOOT_LEN) From 2a0b9157900a147ca40221b3889f7abb77c1fea0 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 26 Feb 2024 16:33:43 +0100 Subject: [PATCH 2/9] features.yaml: add periph_flashpage_aux feature --- features.yaml | 3 +++ makefiles/features_existing.inc.mk | 1 + 2 files changed, 4 insertions(+) diff --git a/features.yaml b/features.yaml index 329fc42b46a3..4b979f21c5a4 100644 --- a/features.yaml +++ b/features.yaml @@ -695,6 +695,9 @@ groups: help: The Flashpage peripheral supports pagewise writing. - name: periph_flashpage_rwee help: The Flashpage peripheral is of the Read While Write. + - name: periph_flashpage_aux + help: It is possible to partition off a part of the internal flash for an + auxiliary slot. - title: Other Peripheral Storage Features features: diff --git a/makefiles/features_existing.inc.mk b/makefiles/features_existing.inc.mk index e7dde9f5e079..5d4d7359cdab 100644 --- a/makefiles/features_existing.inc.mk +++ b/makefiles/features_existing.inc.mk @@ -147,6 +147,7 @@ FEATURES_EXISTING := \ periph_eeprom \ periph_eth \ periph_flashpage \ + periph_flashpage_aux \ periph_flashpage_in_address_space \ periph_flashpage_pagewise \ periph_flashpage_rwee \ From 1f1d7082a59755d5ba1d28619d4dcf078f902762 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 24 Apr 2023 14:14:56 +0200 Subject: [PATCH 3/9] 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 9464ca2df77d..617f62fce931 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 b81e69716be4..d0182d3812a2 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 000000000000..729d0d0c2d14 --- /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 From 308374fc2974a4eb0d123417e8a817b32640a322 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 24 Apr 2023 14:19:37 +0200 Subject: [PATCH 4/9] cpu/cortexm_common: allow to define AUX slot on flash --- cpu/cortexm_common/Makefile.features | 1 + cpu/cortexm_common/ldscripts/cortexm_base.ld | 1 + cpu/cortexm_common/ldscripts/cortexm_rom_offset.ld | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu/cortexm_common/Makefile.features b/cpu/cortexm_common/Makefile.features index b28fabe26379..6a6ca14f8e3f 100644 --- a/cpu/cortexm_common/Makefile.features +++ b/cpu/cortexm_common/Makefile.features @@ -7,6 +7,7 @@ FEATURES_PROVIDED += cpu_core_cortexm FEATURES_PROVIDED += dbgpin FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += newlib +FEATURES_PROVIDED += periph_flashpage_aux FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += puf_sram FEATURES_PROVIDED += picolibc diff --git a/cpu/cortexm_common/ldscripts/cortexm_base.ld b/cpu/cortexm_common/ldscripts/cortexm_base.ld index 06283bc805dc..4a6d3f762b58 100644 --- a/cpu/cortexm_common/ldscripts/cortexm_base.ld +++ b/cpu/cortexm_common/ldscripts/cortexm_base.ld @@ -41,6 +41,7 @@ _backup_ram_len = DEFINED( _backup_ram_len ) ? _backup_ram_len : 0x0 ; MEMORY { bkup_ram (w!rx) : ORIGIN = _backup_ram_start_addr, LENGTH = _backup_ram_len + rom_aux (rx) : ORIGIN = _rom_start_addr + _slot_aux_offset, LENGTH = _slot_aux_len } /* Section Definitions */ diff --git a/cpu/cortexm_common/ldscripts/cortexm_rom_offset.ld b/cpu/cortexm_common/ldscripts/cortexm_rom_offset.ld index f31be5f3a7a8..d688c64dd841 100644 --- a/cpu/cortexm_common/ldscripts/cortexm_rom_offset.ld +++ b/cpu/cortexm_common/ldscripts/cortexm_rom_offset.ld @@ -21,6 +21,8 @@ */ _rom_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0; -_fw_rom_length = DEFINED( _fw_rom_length ) ? _fw_rom_length : _rom_length - _rom_offset; +_slot_aux_len = DEFINED( _slot_aux_len ) ? _slot_aux_len : 0x0; +_fw_rom_length = DEFINED( _fw_rom_length ) ? _fw_rom_length : _rom_length - _rom_offset - _slot_aux_len; -ASSERT((_fw_rom_length <= _rom_length - _rom_offset), "Specified firmware size does not fit in ROM"); +ASSERT(_fw_rom_length <= _rom_length - _rom_offset - _slot_aux_len, "Specified firmware size does not fit in ROM"); +ASSERT(_fw_rom_length <= _rom_length, "Specified firmware size does not fit in ROM"); From a417a3e72c854138db005f2c7eb5f188db7dd432 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 24 Apr 2023 14:21:47 +0200 Subject: [PATCH 5/9] cpu/riscv_common: allow to define AUX slot on flash --- cpu/riscv_common/Makefile.features | 1 + cpu/riscv_common/Makefile.include | 6 ++---- cpu/riscv_common/ldscripts/riscv.ld | 1 + cpu/riscv_common/ldscripts/riscv_vars.ld | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cpu/riscv_common/Makefile.features b/cpu/riscv_common/Makefile.features index 174b9d04dad8..46f9f267b4c9 100644 --- a/cpu/riscv_common/Makefile.features +++ b/cpu/riscv_common/Makefile.features @@ -8,6 +8,7 @@ FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_coretimer +FEATURES_PROVIDED += periph_flashpage_aux FEATURES_PROVIDED += puf_sram FEATURES_PROVIDED += rust_target FEATURES_PROVIDED += ssp diff --git a/cpu/riscv_common/Makefile.include b/cpu/riscv_common/Makefile.include index 632fd461250c..5eae51e1345b 100644 --- a/cpu/riscv_common/Makefile.include +++ b/cpu/riscv_common/Makefile.include @@ -14,10 +14,8 @@ ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_start_addr=$(RAM_START_ADDR) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_length=$(RAM_LEN) - LINKFLAGS += $(if $(ROM_OFFSET),$(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET) \ - ,$(LINKFLAGPREFIX)--defsym=_rom_offset=0x0) - LINKFLAGS += $(if $(FW_ROM_LEN),$(LINKFLAGPREFIX)--defsym=_fw_rom_length=$(FW_ROM_LEN) \ - ,$(LINKFLAGPREFIX)--defsym=_fw_rom_length=$(ROM_LEN)) + LINKFLAGS += $(if $(ROM_OFFSET),$(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET)) + LINKFLAGS += $(if $(FW_ROM_LEN),$(LINKFLAGPREFIX)--defsym=_fw_rom_length=$(FW_ROM_LEN)) endif ifneq (,$(ITIM_START_ADDR)) diff --git a/cpu/riscv_common/ldscripts/riscv.ld b/cpu/riscv_common/ldscripts/riscv.ld index 8c9d78a9c4de..aca2241abc2a 100644 --- a/cpu/riscv_common/ldscripts/riscv.ld +++ b/cpu/riscv_common/ldscripts/riscv.ld @@ -25,6 +25,7 @@ MEMORY flash (rxai!w) : ORIGIN = _rom_start_addr + _rom_offset, LENGTH = _fw_rom_length ram (wxa!ri) : ORIGIN = _ram_start_addr, LENGTH = _ram_length itim (wxa!ri) : ORIGIN = _itim_start_addr, LENGTH = _itim_length + rom_aux (rx) : ORIGIN = _rom_start_addr + _slot_aux_offset, LENGTH = _slot_aux_len } INCLUDE riscv_base.ld diff --git a/cpu/riscv_common/ldscripts/riscv_vars.ld b/cpu/riscv_common/ldscripts/riscv_vars.ld index 0efcc7f3c796..860f1e010669 100644 --- a/cpu/riscv_common/ldscripts/riscv_vars.ld +++ b/cpu/riscv_common/ldscripts/riscv_vars.ld @@ -21,3 +21,10 @@ _itim_start_addr = DEFINED( _itim_start_addr ) ? _itim_start_addr : 0x0; _itim_length = DEFINED( _itim_length ) ? _itim_length : 0x0; + +_rom_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0; +_slot_aux_len = DEFINED( _slot_aux_len ) ? _slot_aux_len : 0x0; +_fw_rom_length = DEFINED( _fw_rom_length ) ? _fw_rom_length : _rom_length - _rom_offset - _slot_aux_len; + +ASSERT(_fw_rom_length <= _rom_length - _rom_offset - _slot_aux_len, "Specified firmware size does not fit in ROM"); +ASSERT(_fw_rom_length <= _rom_length, "Specified firmware size does not fit in ROM"); From e3819ca96015f20a1ca864cc73d4f6b69eb6e8f8 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 17 Sep 2022 18:09:58 +0200 Subject: [PATCH 6/9] drivers/mtd_flashpage: define mtd_flash_aux_slot device --- drivers/Makefile.dep | 4 ++ drivers/include/mtd_flashpage.h | 53 ++++++++++++++++++++++++++- drivers/mtd_flashpage/mtd_flashpage.c | 10 +++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 31c98b08a0f4..f86459b0c230 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -136,6 +136,10 @@ ifneq (,$(filter pcf857%,$(USEMODULE))) USEMODULE += pcf857x endif +ifneq (,$(filter periph_flashpage_aux,$(FEATURES_USED))) + FEATURES_REQUIRED += periph_flashpage_pagewise +endif + ifneq (,$(filter periph_ptp_timer periph_ptp_speed_adjustment,$(FEATURES_USED))) FEATURES_REQUIRED += periph_ptp endif diff --git a/drivers/include/mtd_flashpage.h b/drivers/include/mtd_flashpage.h index 5c2db79efb66..b8a14b41ea7a 100644 --- a/drivers/include/mtd_flashpage.h +++ b/drivers/include/mtd_flashpage.h @@ -35,7 +35,7 @@ extern "C" #endif /** - * @brief Macro helper to initialize a mtd_t with flash-age driver + * @brief Macro helper to initialize a mtd_t with flashpage driver */ #define MTD_FLASHPAGE_INIT_VAL(_pages_per_sector) { \ .base = { \ @@ -47,6 +47,23 @@ extern "C" }, \ } +/** + * @brief Macro helper to initialize a mtd_t with a portion of the flash + * + * @param[in] start Start address of the flash section + * @param[in] len Size of the flash section in bytes + */ +#define MTD_FLASHPAGE_AUX_INIT_VAL(start, len) { \ + .base = { \ + .driver = &mtd_flashpage_driver, \ + .sector_count = len / FLASHPAGE_SIZE, \ + .pages_per_sector = 1, \ + .page_size = FLASHPAGE_SIZE, \ + .write_size = 1, \ + }, \ + .offset = start / FLASHPAGE_SIZE, \ +} + /** * @brief Flashpage MTD device operations table */ @@ -62,6 +79,40 @@ typedef struct { flash */ } mtd_flashpage_t; +#if CONFIG_SLOT_AUX_LEN || DOXYGEN +/** + * @brief MTD device representing the auxiliary flash slot + */ +extern mtd_flashpage_t mtd_flash_aux_slot; + +/** + * @brief Generic MTD device backed by the auxiliary flash slot + */ +extern mtd_dev_t *mtd_aux; +#endif + +/** + * @brief Size of the auxiliary slot on the internal flash + * Must align with the flash page size. + * + * @note Don't set this config value directly! + * Instead set `SLOT_AUX_LEN` in the board's `Makefile.include` + * + * This value is fixed and can not be changed in the field / via firmware + * updates. Changing this value requires re-flashing of riotboot. + * + */ +#ifndef CONFIG_SLOT_AUX_LEN +#define CONFIG_SLOT_AUX_LEN 0 +#endif + +/** + * @brief Default MTD offset for the AUX slot + */ +#ifndef CONFIG_SLOT_AUX_MTD_OFFSET +#define CONFIG_SLOT_AUX_MTD_OFFSET 1 +#endif + #ifdef __cplusplus } #endif diff --git a/drivers/mtd_flashpage/mtd_flashpage.c b/drivers/mtd_flashpage/mtd_flashpage.c index f7bf1efd3124..4e2b72f41bdf 100644 --- a/drivers/mtd_flashpage/mtd_flashpage.c +++ b/drivers/mtd_flashpage/mtd_flashpage.c @@ -159,3 +159,13 @@ const mtd_desc_t mtd_flashpage_driver = { .write_page = _write_page, .erase_sector = _erase_sector, }; + +#if CONFIG_SLOT_AUX_LEN +mtd_flashpage_t mtd_flash_aux_slot = MTD_FLASHPAGE_AUX_INIT_VAL(CONFIG_SLOT_AUX_OFFSET, + CONFIG_SLOT_AUX_LEN); +MTD_XFA_ADD(mtd_flash_aux_slot, CONFIG_SLOT_AUX_MTD_OFFSET); +mtd_dev_t *mtd_aux = &mtd_flash_aux_slot.base; + +static_assert(CONFIG_SLOT_AUX_OFFSET % FLASHPAGE_SIZE == 0, "AUX slot must align with page"); +static_assert(CONFIG_SLOT_AUX_LEN % FLASHPAGE_SIZE == 0, "AUX slot must align with page"); +#endif From 634b186d1d2dec61d14bd1ed9ae57fe070e080f6 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sun, 18 Sep 2022 15:50:23 +0200 Subject: [PATCH 7/9] tests/mtd_flashpage: add test for AUX slot --- tests/drivers/mtd_flashpage/Makefile | 7 +++ tests/drivers/mtd_flashpage/Makefile.ci | 12 ++++ tests/drivers/mtd_flashpage/main.c | 78 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/drivers/mtd_flashpage/Makefile.ci diff --git a/tests/drivers/mtd_flashpage/Makefile b/tests/drivers/mtd_flashpage/Makefile index fc32dba0f458..ec0454e185ca 100644 --- a/tests/drivers/mtd_flashpage/Makefile +++ b/tests/drivers/mtd_flashpage/Makefile @@ -4,4 +4,11 @@ USEMODULE += mtd_flashpage USEMODULE += mtd_write_page USEMODULE += embunit +FEATURES_OPTIONAL += periph_flashpage_aux + +# define an auxiliary slot on the internal flash +# NOTE: This should typically be set by the board as it can not be changed in the field. +# This is only defined here for the sake of the test. +SLOT_AUX_LEN := 0x8000 + include $(RIOTBASE)/Makefile.include diff --git a/tests/drivers/mtd_flashpage/Makefile.ci b/tests/drivers/mtd_flashpage/Makefile.ci new file mode 100644 index 000000000000..1ed3a60826ca --- /dev/null +++ b/tests/drivers/mtd_flashpage/Makefile.ci @@ -0,0 +1,12 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-c031c6 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + samd10-xmini \ + stk3200 \ + stm32g0316-disco \ + stm32f030f4-demo \ + weact-g030f6 \ + # diff --git a/tests/drivers/mtd_flashpage/main.c b/tests/drivers/mtd_flashpage/main.c index c9f27fa788e8..96957ca67bb9 100644 --- a/tests/drivers/mtd_flashpage/main.c +++ b/tests/drivers/mtd_flashpage/main.c @@ -11,6 +11,7 @@ * * @file */ +#include #include #include @@ -217,6 +218,80 @@ static void test_mtd_write_read_page(void) #endif } +#ifdef MODULE_PERIPH_FLASHPAGE_AUX +static bool mem_is_all_set(const uint8_t *buf, uint8_t c, size_t n) +{ + for (const uint8_t *end = buf + n; buf != end; ++buf) { + if (*buf != c) { + return false; + } + } + + return true; +} + +static void test_mtd_aux_slot(void) +{ + mtd_dev_t *dev_aux = mtd_aux; + + mtd_init(dev_aux); + + uint32_t sector = dev_aux->sector_count - 2; + + static uint8_t buffer[FLASHPAGE_SIZE]; + + uint32_t page_0 = dev_aux->pages_per_sector * sector; + uint32_t page_1 = dev_aux->pages_per_sector * (sector + 1); + uint32_t page_size = dev_aux->page_size; + + /* write dummy data to sectors */ + memset(buffer, 0x23, dev_aux->page_size); + TEST_ASSERT_EQUAL_INT(mtd_write_page_raw(dev_aux, buffer, page_0, 0, page_size), 0); + TEST_ASSERT_EQUAL_INT(mtd_write_page_raw(dev_aux, buffer, page_1, 0, page_size), 0); + + /* erase two sectors and check if they have been erased */ + TEST_ASSERT_EQUAL_INT(mtd_erase_sector(dev_aux, sector, 2), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, 0, page_size), 0); + TEST_ASSERT(mem_is_all_set(buffer, 0xFF, page_size) || mem_is_all_set(buffer, 0x00, page_size)); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_1, 0, page_size), 0); + TEST_ASSERT(mem_is_all_set(buffer, 0xFF, page_size) || mem_is_all_set(buffer, 0x00, page_size)); + + /* write test data & read it back */ + const char test_str[] = "0123456789"; + uint32_t offset = 5; + + TEST_ASSERT_EQUAL_INT(mtd_write_page_raw(dev_aux, test_str, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(memcmp(test_str, buffer, sizeof(test_str)), 0); + + /* write across page boundary */ + offset = page_size - sizeof(test_str) / 2; + TEST_ASSERT_EQUAL_INT(mtd_write_page_raw(dev_aux, test_str, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(memcmp(test_str, buffer, sizeof(test_str)), 0); + + /* write across sector boundary */ + offset = page_size - sizeof(test_str) / 2 + + (dev_aux->pages_per_sector - 1) * page_size; + TEST_ASSERT_EQUAL_INT(mtd_write_page_raw(dev_aux, test_str, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(memcmp(test_str, buffer, sizeof(test_str)), 0); + + /* overwrite first test string, rely on MTD for read-modify-write */ + const char test_str_2[] = "Hello World!"; + offset = 5; + TEST_ASSERT_EQUAL_INT(mtd_write_page(dev_aux, test_str_2, page_0, offset, sizeof(test_str_2)), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, offset, sizeof(test_str_2)), 0); + TEST_ASSERT_EQUAL_INT(memcmp(test_str_2, buffer, sizeof(test_str_2)), 0); + + /* test write_page across sectors */ + offset = dev_aux->pages_per_sector * dev_aux->page_size - 2; + TEST_ASSERT_EQUAL_INT(mtd_write_page(dev_aux, test_str, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(mtd_read_page(dev_aux, buffer, page_0, offset, sizeof(test_str)), 0); + TEST_ASSERT_EQUAL_INT(memcmp(test_str, buffer, sizeof(test_str)), 0); +} +#endif + Test *tests_mtd_flashpage_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { @@ -225,6 +300,9 @@ Test *tests_mtd_flashpage_tests(void) new_TestFixture(test_mtd_write_erase), new_TestFixture(test_mtd_write_read), new_TestFixture(test_mtd_write_read_page), +#ifdef MODULE_PERIPH_FLASHPAGE_AUX + new_TestFixture(test_mtd_aux_slot), +#endif }; EMB_UNIT_TESTCALLER(mtd_flashpage_tests, setup, teardown, fixtures); From fe48fae2ad01fd6cc2bf36081f6e4e544f252ccc Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 28 Feb 2024 13:15:25 +0100 Subject: [PATCH 8/9] dist/tools/insufficient_memory: add 'does not fit in ROM' message --- dist/tools/insufficient_memory/create_makefile.ci.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dist/tools/insufficient_memory/create_makefile.ci.sh b/dist/tools/insufficient_memory/create_makefile.ci.sh index 7f2c0e257b79..a4c87fe34b37 100755 --- a/dist/tools/insufficient_memory/create_makefile.ci.sh +++ b/dist/tools/insufficient_memory/create_makefile.ci.sh @@ -57,6 +57,7 @@ for BOARD in $(EXTERNAL_BOARD_DIRS="" make --no-print-directory info-boards-sup -e "not within region" \ -e "wraps around address space" \ -e "overlaps section" \ + -e "does not fit in ROM" \ "$TMPFILE" > /dev/null; then printf "${CBIG}%s${CRESET}\n" "too big" BOARDS="${BOARDS} ${BOARD}" From d26937fe9c84bc159d835cfbac86c0e8da162d2a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 28 Feb 2024 13:49:12 +0100 Subject: [PATCH 9/9] cpu/gd32v: don't set FW_ROM_LEN to ROM_LEN FW_ROM_LEN is supposed to be a subset of ROM_LEN that contains the firmware (without bootloader, AUX slot). --- cpu/gd32v/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/gd32v/Makefile.include b/cpu/gd32v/Makefile.include index 97dead6fab06..4d1861979665 100644 --- a/cpu/gd32v/Makefile.include +++ b/cpu/gd32v/Makefile.include @@ -17,7 +17,7 @@ else $(error CPU model $(CPU_MODEL) not supported) endif -FW_ROM_LEN ?= $(shell printf "0x%x" $$(($(ROM_LEN:%K=%*1024)))) +ROM_LEN := $(shell printf "0x%x" $$(($(ROM_LEN:%K=%*1024)))) RIOTBOOT_HDR_LEN ?= 0x400 ifneq (,$(filter usbus_dfu tinyusb_dfu,$(USEMODULE)))