diff --git a/cpu/msp430_common/ldscripts/msp430_common.ld b/cpu/msp430_common/ldscripts/msp430_common.ld new file mode 100644 index 0000000000..56b08ac9af --- /dev/null +++ b/cpu/msp430_common/ldscripts/msp430_common.ld @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +SECTIONS +{ + /* Populate information about rom size */ + _srom = ORIGIN(ROM); + _erom = ORIGIN(ROM) + LENGTH(ROM); + + .end_fw (NOLOAD) : ALIGN(4) { + _end_fw = . ; + } > ROM +} diff --git a/cpu/msp430_common/periph/flashpage.c b/cpu/msp430_common/periph/flashpage.c index b54b83ab85..54973ac540 100644 --- a/cpu/msp430_common/periph/flashpage.c +++ b/cpu/msp430_common/periph/flashpage.c @@ -26,6 +26,13 @@ #include "irq.h" #include "periph/flashpage.h" +/** + * @brief Memory markers, defined in the linker script + * @{ + */ +extern uint32_t _end_fw; +extern uint32_t _erom; + static inline int _unlock(void) { int state; @@ -97,3 +104,15 @@ void flashpage_write(void *target_addr, const void *data, size_t len) /* lock flash and re-enable interrupts */ _lock(state); } + +unsigned flashpage_first_free(void) +{ + return flashpage_page(&_end_fw) + 1; +} + +/* MSP430 cpu's last page holds the interrupt vector, so flashpage_last_free + is the one before last */ +unsigned flashpage_last_free(void) +{ + return flashpage_page(&_erom) - 1; +} diff --git a/makefiles/arch/msp430.inc.mk b/makefiles/arch/msp430.inc.mk index 801d155274..f49b8ff360 100644 --- a/makefiles/arch/msp430.inc.mk +++ b/makefiles/arch/msp430.inc.mk @@ -16,6 +16,7 @@ ASFLAGS += $(CFLAGS_CPU) --defsym $(CPU_MODEL)=1 $(CFLAGS_DBG) LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) LINKFLAGS += -Wl,--gc-sections -Wl,-L$(MSP430_SUPPORT_FILES)/include LINKFLAGS += -T $(MSP430_SUPPORT_FILES)/include/$(CPU_MODEL).ld +LINKFLAGS += -T $(RIOTCPU)/msp430_common/ldscripts/msp430_common.ld LINKFLAGS += $(RIOTCPU)/msp430_common/ldscripts/xfa.ld OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color