summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/atmel-samd/Makefile15
-rw-r--r--ports/atmel-samd/boards/common.template.ld4
-rw-r--r--ports/atmel-samd/mpconfigport.h47
m---------ports/atmel-samd/peripherals0
-rw-r--r--ports/cxd56/boards/spresense/mpconfigboard.mk2
-rwxr-xr-xports/nrf/Makefile34
-rw-r--r--ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h3
-rw-r--r--ports/nrf/boards/common.template.ld8
-rw-r--r--ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h3
-rw-r--r--ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.h3
-rw-r--r--ports/nrf/boards/metro_nrf52840_express/mpconfigboard.h3
-rw-r--r--ports/nrf/boards/pca10059/mpconfigboard.mk2
-rw-r--r--ports/nrf/ld_defines.c39
-rw-r--r--ports/nrf/mpconfigport.h76
-rw-r--r--ports/nrf/mpconfigport.mk2
-rw-r--r--ports/nrf/supervisor/internal_flash.c8
-rw-r--r--py/circuitpy_defns.mk12
-rw-r--r--supervisor/supervisor.mk6
-rw-r--r--tools/build_memory_info.py20
19 files changed, 188 insertions, 99 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index 32517c801..83fd879aa 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -157,7 +157,7 @@ endif
-LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own.
@@ -324,19 +324,10 @@ SRC_QSTR_PREPROCESSOR += peripherals/samd/$(CHIP_FAMILY)/clocks.c
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
-LD_FILE = $(BUILD)/$(notdir $(patsubst %.template.ld,%.ld,$(LD_TEMPLATE_FILE)))
-
-# ld_defines.pp is generated from ld_defines.c. See py/mkrules.mk.
-# Run gen_ld_files.py over ALL *.template.ld files, not just LD_TEMPLATE_FILE,
-# because it may include other template files.
-$(LD_FILE): $(BUILD)/ld_defines.pp boards/*.template.ld
- $(STEPECHO) "GEN $@"
- $(Q)$(PYTHON3) $(TOP)/tools/gen_ld_files.py --defines $< --out_dir $(BUILD) boards/*.template.ld
-
-$(BUILD)/firmware.elf: $(OBJ) $(LD_FILE)
+$(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE)
$(STEPECHO) "LINK $@"
$(Q)$(CC) -o $@ $(LDFLAGS) $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group
- $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE)
+ $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE)
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(STEPECHO) "Create $@"
diff --git a/ports/atmel-samd/boards/common.template.ld b/ports/atmel-samd/boards/common.template.ld
index 4c537e001..1054605c8 100644
--- a/ports/atmel-samd/boards/common.template.ld
+++ b/ports/atmel-samd/boards/common.template.ld
@@ -6,9 +6,9 @@ MEMORY
FLASH_BOOTLOADER (rx): ORIGIN = ${BOOTLOADER_START_ADDR}, LENGTH = ${BOOTLOADER_SIZE}
FLASH_FIRMWARE (rx) : ORIGIN = ${CIRCUITPY_FIRMWARE_START_ADDR}, LENGTH = ${CIRCUITPY_FIRMWARE_SIZE}
- FLASH_NVM (r) : ORIGIN = ${CIRCUITPY_INTERNAL_NVM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_NVM_SIZE}
- FLASH_CONFIG (r) : ORIGIN = ${CIRCUITPY_INTERNAL_CONFIG_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_CONFIG_SIZE}
FLASH_FILESYSTEM (r) : ORIGIN = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE}
+ FLASH_CONFIG (r) : ORIGIN = ${CIRCUITPY_INTERNAL_CONFIG_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_CONFIG_SIZE}
+ FLASH_NVM (r) : ORIGIN = ${CIRCUITPY_INTERNAL_NVM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_NVM_SIZE}
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = ${RAM_SIZE}
}
diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h
index ecb962194..6ab95c8a5 100644
--- a/ports/atmel-samd/mpconfigport.h
+++ b/ports/atmel-samd/mpconfigport.h
@@ -81,12 +81,12 @@
#endif
// If CIRCUITPY is internal, use half of flash for it.
-#ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
- #if INTERNAL_FLASH_FILESYSTEM
- #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (FLASH_SIZE/2)
- #else
- #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
+#if INTERNAL_FLASH_FILESYSTEM
+ #ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (FLASH_SIZE/2)
#endif
+#else
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
#endif
// HSRAM_SIZE is defined in the ASF4 include files for each SAMD51 chip.
@@ -135,9 +135,9 @@
//
// bootloader (8 or 16kB)
// firmware
+// internal CIRCUITPY flash filesystem (optional)
// internal config, used to store crystalless clock calibration info (optional)
// microntroller.nvm (optional)
-// internal CIRCUITPY flash filesystem (optional)
// Define these regions starting up from the bottom of flash:
@@ -147,18 +147,43 @@
// Define these regions start down from the top of flash:
-#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR \
- (FLASH_SIZE - CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE)
-
#define CIRCUITPY_INTERNAL_NVM_START_ADDR \
- (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR - CIRCUITPY_INTERNAL_NVM_SIZE)
+ (FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
#define CIRCUITPY_INTERNAL_CONFIG_START_ADDR \
(CIRCUITPY_INTERNAL_NVM_START_ADDR - CIRCUITPY_INTERNAL_CONFIG_SIZE)
+#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR \
+ (CIRCUITPY_INTERNAL_CONFIG_START_ADDR - CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE)
+
// The firmware space is the space left over between the fixed lower and upper regions.
#define CIRCUITPY_FIRMWARE_SIZE \
- (CIRCUITPY_INTERNAL_CONFIG_START_ADDR - CIRCUITPY_FIRMWARE_START_ADDR)
+ (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR - CIRCUITPY_FIRMWARE_START_ADDR)
+
+#if BOOTLOADER_START_ADDR % FLASH_PAGE_SIZE != 0
+#error BOOTLOADER_START_ADDR must be on a flash page boundary.
+#endif
+
+#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash page boundary.
+#endif
+#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
+
+#if CIRCUITPY_INTERNAL_CONFIG_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be on a flash page boundary.
+#endif
+#if CIRCUITPY_INTERNAL_CONFIG_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
+
+#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash page boundary.
+#endif
+#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
#if CIRCUITPY_FIRMWARE_SIZE < 0
#error No space left in flash for firmware after specifying other regions!
diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals
-Subproject bb26a4145c86a51debc6571bb1f791e0d4fd296
+Subproject 4c0deecf889da0074c1dbc9a5e2d24cb7c7a31c
diff --git a/ports/cxd56/boards/spresense/mpconfigboard.mk b/ports/cxd56/boards/spresense/mpconfigboard.mk
index a2d4e5d88..7b8ac6ff6 100644
--- a/ports/cxd56/boards/spresense/mpconfigboard.mk
+++ b/ports/cxd56/boards/spresense/mpconfigboard.mk
@@ -2,3 +2,5 @@ USB_VID = 0x054c
USB_PID = 0x0bc2
USB_PRODUCT = "Spresense"
USB_MANUFACTURER = "Sony"
+
+INTERNAL_FLASH_FILESYSTEM = 1
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index b96b8affb..e7af13a73 100755
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -63,8 +63,6 @@ ifneq ($(SD), )
include bluetooth/bluetooth_common.mk
endif
-FROZEN_MPY_DIR = freeze
-
CROSS_COMPILE = arm-none-eabi-
FATFS_DIR = lib/oofatfs
@@ -92,7 +90,7 @@ INC += -I../../supervisor/shared/usb
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb3 -Og
else
- CFLAGS += -Os -DNDEBUG
+ CFLAGS += -Os -DNDEBUG -ggdb3
CFLAGS += -flto -flto-partition=none
endif
@@ -118,7 +116,7 @@ CFLAGS += \
# TODO: check this
CFLAGS += -D__START=main
-LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc
LDFLAGS += -mthumb -mcpu=cortex-m4
@@ -193,15 +191,16 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
-SRC_S = supervisor/cpu.s
+# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
+# because a few modules have files both in common-hal/ and shared-modules/.
+# Doing a $(sort ...) removes duplicates as part of sorting.
+SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
-FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
-FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
+SRC_S = supervisor/cpu.s
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_NRFX:.c=.o))
-OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
-OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
+OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif
@@ -219,19 +218,10 @@ SRC_QSTR_PREPROCESSOR +=
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
-LD_FILE = $(BUILD)/$(notdir $(patsubst %.template.ld,%.ld,$(LD_TEMPLATE_FILE)))
-
-# ld_defines.pp is generated from ld_defines.c. See py/mkrules.mk.
-# Run gen_ld_files.py over ALL *.template.ld files, not just LD_TEMPLATE_FILE,
-# because it may include other template files.
-$(LD_FILE): $(BUILD)/ld_defines.pp boards/*.template.ld
- $(STEPECHO) "GEN $@"
- $(Q)$(PYTHON3) $(TOP)/tools/gen_ld_files.py --defines $< --out_dir $(BUILD) boards/*.template.ld
-
-$(BUILD)/firmware.elf: $(OBJ)
+$(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE)
$(STEPECHO) "LINK $@"
- $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
- $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE)
+ $(Q)$(CC) -o $@ $(LDFLAGS) $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group
+ $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE)
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(STEPECHO) "Create $@"
@@ -273,7 +263,7 @@ else ifeq ($(FLASHER), pyocd)
flash: $(BUILD)/firmware.hex
pyocd-flashtool -t $(MCU_VARIANT) $< --sector_erase
- #pyocd-tool -t $(MCU_VARIANT) erase $(BOOT_SETTING_ADDR)
+# pyocd-tool -t $(MCU_VARIANT) erase $(BOOT_SETTING_ADDR)
pyocd-tool -t $(MCU_VARIANT) write32 $(BOOT_SETTING_ADDR) 0x00000001
pyocd-tool -t $(MCU_VARIANT) reset
diff --git a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
index 7ca9b12ae..5abb86820 100644
--- a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
+++ b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
@@ -30,9 +30,6 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Circuit Playground Bluefruit"
#define MICROPY_HW_MCU_NAME "nRF52840"
-#define FLASH_SIZE (0x100000)
-#define FLASH_PAGE_SIZE (4096)
-
#define MICROPY_HW_LED_STATUS (&pin_P1_14)
// Unusually, board does not have a 32 kHz xtal. Nearly all boards do.
diff --git a/ports/nrf/boards/common.template.ld b/ports/nrf/boards/common.template.ld
index 9fd066de1..f26723492 100644
--- a/ports/nrf/boards/common.template.ld
+++ b/ports/nrf/boards/common.template.ld
@@ -9,11 +9,11 @@ MEMORY
/* nRF SoftDevice */
FLASH_MBR (rx) : ORIGIN = ${MBR_START_ADDR}, LENGTH = ${MBR_SIZE}
FLASH_SD (rx) : ORIGIN = ${SD_FLASH_START_ADDR}, LENGTH = ${SD_FLASH_SIZE}
- FLASH_ISR (rx) : ORIGIN = ${CIRCUITPY_ISR_START_ADDR}, LENGTH = ${CIRCUITPY_ISR_LENGTH}
+ FLASH_ISR (rx) : ORIGIN = ${ISR_START_ADDR}, LENGTH = ${ISR_SIZE}
FLASH_FIRMWARE (rx) : ORIGIN = ${CIRCUITPY_FIRMWARE_START_ADDR}, LENGTH = ${CIRCUITPY_FIRMWARE_SIZE}
+ FLASH_FATFS (r) : ORIGIN = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE}
FLASH_BLE_CONFIG (r) : ORIGIN = ${CIRCUITPY_BLE_CONFIG_START_ADDR}, LENGTH = ${CIRCUITPY_BLE_CONFIG_SIZE}
FLASH_NVM (r) : ORIGIN = ${CIRCUITPY_INTERNAL_NVM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_NVM_SIZE}
- FLASH_FATFS (r) : ORIGIN = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR}, LENGTH = ${CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE}
FLASH_BOOTLOADER (rx) : ORIGIN = ${BOOTLOADER_START_ADDR}, LENGTH = ${BOOTLOADER_SIZE}
FLASH_BOOTLOADER_SETTINGS (r) : ORIGIN = ${BOOTLOADER_SETTINGS_START_ADDR}, LENGTH = ${BOOTLOADER_SETTINGS_SIZE}
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x03C000 /* 240 KiB */
@@ -32,10 +32,6 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_end = 0x20020000; /* tunable */
-/* Flash region for File System */
-__fatfs_flash_start_addr = ORIGIN(FLASH_FATFS);
-__fatfs_flash_length = LENGTH(FLASH_FATFS);
-
/* define output sections */
SECTIONS
{
diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h
index b388515e4..64988e1a2 100644
--- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h
+++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h
@@ -30,9 +30,6 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Feather nRF52840 Express"
#define MICROPY_HW_MCU_NAME "nRF52840"
-#define FLASH_SIZE (0x100000)
-#define FLASH_PAGE_SIZE (4096)
-
#define MICROPY_HW_NEOPIXEL (&pin_P0_16)
#define MICROPY_HW_LED_STATUS (&pin_P1_15)
diff --git a/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.h
index 2f17460ae..629463e4e 100644
--- a/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.h
+++ b/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.h
@@ -3,9 +3,6 @@
#define MICROPY_HW_BOARD_NAME "Adafruit ItsyBitsy nRF52840 Express"
#define MICROPY_HW_MCU_NAME "nRF52840"
-#define FLASH_SIZE (0x100000)
-#define FLASH_PAGE_SIZE (4096)
-
#define MICROPY_HW_LED_STATUS (&pin_P0_06)
#define MICROPY_HW_APA102_MOSI (&pin_P0_08)
diff --git a/ports/nrf/boards/metro_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/metro_nrf52840_express/mpconfigboard.h
index 5188a379f..837355154 100644
--- a/ports/nrf/boards/metro_nrf52840_express/mpconfigboard.h
+++ b/ports/nrf/boards/metro_nrf52840_express/mpconfigboard.h
@@ -30,9 +30,6 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Metro nRF52840 Express"
#define MICROPY_HW_MCU_NAME "nRF52840"
-#define FLASH_SIZE (0x100000)
-#define FLASH_PAGE_SIZE (4096)
-
#define MICROPY_HW_NEOPIXEL (&pin_P0_13)
#define MICROPY_HW_LED_STATUS (&pin_P1_13)
diff --git a/ports/nrf/boards/pca10059/mpconfigboard.mk b/ports/nrf/boards/pca10059/mpconfigboard.mk
index f9ff9c21c..3f97b0821 100644
--- a/ports/nrf/boards/pca10059/mpconfigboard.mk
+++ b/ports/nrf/boards/pca10059/mpconfigboard.mk
@@ -5,4 +5,4 @@ USB_MANUFACTURER = "Nordic Semiconductor"
MCU_CHIP = nrf52840
-INTERNAL_FLASH_FILEYSTEM = 1
+INTERNAL_FLASH_FILESYSTEM = 1
diff --git a/ports/nrf/ld_defines.c b/ports/nrf/ld_defines.c
new file mode 100644
index 000000000..0ec6dfdb5
--- /dev/null
+++ b/ports/nrf/ld_defines.c
@@ -0,0 +1,39 @@
+// Fake source file used only to capture #define values for use in ld template files.
+#include "mpconfigport.h"
+
+// For each value needed in the LD file, create a C-like line:
+// /*NAME_OF_VALUE=*/ NAME_OF_VALUE;
+// The C preprocessor will replace NAME_OF_VALUE with the actual value.
+// This will be post-processed by tools/gen_ld_files.py to extract the name and value.
+
+// The next line is a marker to start looking for definitions. Lines above the next line are ignored.
+// START_LD_DEFINES
+
+/*MBR_START_ADDR=*/ MBR_START_ADDR;
+/*MBR_SIZE=*/ MBR_SIZE;
+
+/*SD_FLASH_START_ADDR=*/ SD_FLASH_START_ADDR;
+/*SD_FLASH_SIZE=*/ SD_FLASH_SIZE;
+
+/*ISR_START_ADDR=*/ ISR_START_ADDR;
+/*ISR_SIZE=*/ ISR_SIZE;
+
+/*CIRCUITPY_DEFAULT_STACK_SIZE=*/ CIRCUITPY_DEFAULT_STACK_SIZE;
+
+/*CIRCUITPY_FIRMWARE_START_ADDR=*/ CIRCUITPY_FIRMWARE_START_ADDR;
+/*CIRCUITPY_FIRMWARE_SIZE=*/ CIRCUITPY_FIRMWARE_SIZE;
+
+/*CIRCUITPY_BLE_CONFIG_START_ADDR=*/ CIRCUITPY_BLE_CONFIG_START_ADDR;
+/*CIRCUITPY_BLE_CONFIG_SIZE=*/ CIRCUITPY_BLE_CONFIG_SIZE;
+
+/*CIRCUITPY_INTERNAL_NVM_START_ADDR=*/ CIRCUITPY_INTERNAL_NVM_START_ADDR;
+/*CIRCUITPY_INTERNAL_NVM_SIZE=*/ CIRCUITPY_INTERNAL_NVM_SIZE;
+
+/*CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR=*/ CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR;
+/*CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE=*/ CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE;
+
+/*BOOTLOADER_START_ADDR=*/ BOOTLOADER_START_ADDR;
+/*BOOTLOADER_SIZE=*/ BOOTLOADER_SIZE;
+
+/*BOOTLOADER_SETTINGS_START_ADDR=*/ BOOTLOADER_SETTINGS_START_ADDR;
+/*BOOTLOADER_SETTINGS_SIZE=*/ BOOTLOADER_SETTINGS_SIZE;
diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h
index 00d4a51ad..d10f12f6a 100644
--- a/ports/nrf/mpconfigport.h
+++ b/ports/nrf/mpconfigport.h
@@ -30,8 +30,13 @@
#include "ble_drv.h"
+#include "nrf_mbr.h" // for MBR_SIZE
+#include "nrf_sdm.h" // for SD_FLASH_SIZE
+#include "peripherals/nrf/nvm.h" // for FLASH_PAGE_SIZE
+
#ifdef NRF52840
#define MICROPY_PY_SYS_PLATFORM "nRF52840"
+#define FLASH_SIZE (0x100000) // 1MiB
#endif
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
@@ -45,11 +50,12 @@
// 24kiB stack
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
-#if INTERNAL_FLASH_FILESYSTEM
-#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
-#else
-#define CIRCUITPYINTERNAL_FLASH_FILESYSTEM_SIZE (0)
-#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// This also includes mpconfigboard.h.
+#include "py/circuitpy_mpconfig.h"
+
+// Definitions that might be overriden by mpconfigboard.h
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
#define CIRCUITPY_INTERNAL_NVM_SIZE (8192)
@@ -60,14 +66,22 @@
#define BOARD_HAS_32KHZ_XTAL (1)
#endif
+#if INTERNAL_FLASH_FILESYSTEM
+ #ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (256*1024)
+ #endif
+#else
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
+#endif
+
// Flash layout, starting at 0x00000000
//
// SoftDevice
// ISR
// firmware
+// internal CIRCUITPY flash filesystem (optional)
// BLE config (bonding info, etc.) (optional)
// microntroller.nvm (optional)
-// internal CIRCUITPY flash filesystem (optional)
// bootloader (note the MBR at 0x0 redirects to the bootloader here, in high flash)
// bootloader settings
@@ -76,14 +90,14 @@
// Define these regions starting up from the bottom of flash:
#define MBR_START_ADDR (0x0)
-// MBR_SIZE is from nrf_sdm.h
+// MBR_SIZE is from nrf_mbr.h
#define SD_FLASH_START_ADDR (MBR_START_ADDR + MBR_SIZE)
// SD_FLASH_SIZE is from nrf_sdm.h
-#define ISR_FLASH_START_ADDR (SD_FLASH_START_ADDR + SD_FLASH_SIZE)
-#define ISR_FLASH_SIZE (0x1000) // 4kiB
+#define ISR_START_ADDR (SD_FLASH_START_ADDR + SD_FLASH_SIZE)
+#define ISR_SIZE (0x1000) // 4kiB
-#define CIRCUITPY_FIRMWARE_START_ADDR (ISR_FLASH_START_ADDR + ISR_FLASH_LENGTH)
+#define CIRCUITPY_FIRMWARE_START_ADDR (ISR_START_ADDR + ISR_SIZE)
// Define these regions starting down from the bootloader:
@@ -92,22 +106,52 @@
#define BOOTLOADER_SETTINGS_START_ADDR (0x000FF000)
#define BOOTLOADER_SETTINGS_SIZE (0x1000) // 4kiB
-#define FLASH_FATFS_SIZE (256*1024)
-#define FLASH_FATFS_START_ADDR (BOOTLOADER_START_ADDR - FLASH_FATFS_SIZE)
-
-#define CIRCUITPY_INTERNAL_NVM_START_ADDR (FLASH_FATFS_START_ADDR - CIRCUITPY_INTERNAL_NVM_SIZE)
+#define CIRCUITPY_INTERNAL_NVM_START_ADDR (BOOTLOADER_START_ADDR - CIRCUITPY_INTERNAL_NVM_SIZE)
+// 32kiB for bonding, etc.
#define CIRCUITPY_BLE_CONFIG_SIZE (32*1024)
#define CIRCUITPY_BLE_CONFIG_START_ADDR (CIRCUITPY_INTERNAL_NVM_START_ADDR - CIRCUITPY_BLE_CONFIG_SIZE)
+#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (CIRCUITPY_BLE_CONFIG_START_ADDR - CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE)
+
// The firmware space is the space left over between the fixed lower and upper regions.
-#define CIRCUITPY_FIRMWARE_SIZE (CIRCUITPY_BLE_CONFIG_START_ADDR - CIRCUITPY_FIRMWARE_START_ADDR)
+#define CIRCUITPY_FIRMWARE_SIZE (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR - CIRCUITPY_FIRMWARE_START_ADDR)
+
+#if BOOTLOADER_START_ADDR % FLASH_PAGE_SIZE != 0
+#error BOOTLOADER_START_ADDR must be on a flash page boundary.
+#endif
+
+#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash page boundary.
+#endif
+#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
+
+#if CIRCUITPY_BLE_CONFIG_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_BLE_CONFIG_SIZE must be on a flash page boundary.
+#endif
+#if CIRCUITPY_BLE_CONFIG_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_BLE_CONFIG_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
+
+#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash page boundary.
+#endif
+#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_PAGE_SIZE != 0
+#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_PAGE_SIZE.
+#endif
#if CIRCUITPY_FIRMWARE_SIZE < 0
#error No space left in flash for firmware after specifying other regions!
#endif
-#include "py/circuitpy_mpconfig.h"
+#if CIRCUITPY_FIRMWARE_SIZE < 0
+#error No space left in flash for firmware after specifying other regions!
+#endif
+
+
+
#define MICROPY_PORT_ROOT_POINTERS \
CIRCUITPY_COMMON_ROOT_POINTERS \
diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk
index 47cabffb5..9b738d4b3 100644
--- a/ports/nrf/mpconfigport.mk
+++ b/ports/nrf/mpconfigport.mk
@@ -53,7 +53,7 @@ CIRCUITPY_FREQUENCYIO = 0
# nRF52840-specific
-ifeq($(MCU_CHIP),nrf52840)
+ifeq ($(MCU_CHIP),nrf52840)
MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52840
diff --git a/ports/nrf/supervisor/internal_flash.c b/ports/nrf/supervisor/internal_flash.c
index c43454eb3..07aa5079f 100644
--- a/ports/nrf/supervisor/internal_flash.c
+++ b/ports/nrf/supervisor/internal_flash.c
@@ -42,10 +42,6 @@
#include "nrf_sdm.h"
#endif
-// defined in linker
-extern uint32_t __fatfs_flash_start_addr[];
-extern uint32_t __fatfs_flash_length[];
-
#define NO_CACHE 0xffffffff
uint8_t _flash_cache[FLASH_PAGE_SIZE] __attribute__((aligned(4)));
@@ -56,7 +52,7 @@ uint32_t _flash_page_addr = NO_CACHE;
/* Internal Flash API
*------------------------------------------------------------------*/
static inline uint32_t lba2addr(uint32_t block) {
- return ((uint32_t)__fatfs_flash_start_addr) + block * FILESYSTEM_BLOCK_SIZE;
+ return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE;
}
void supervisor_flash_init(void) {
@@ -67,7 +63,7 @@ uint32_t supervisor_flash_get_block_size(void) {
}
uint32_t supervisor_flash_get_block_count(void) {
- return ((uint32_t) __fatfs_flash_length) / FILESYSTEM_BLOCK_SIZE ;
+ return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE ;
}
void supervisor_flash_flush(void) {
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 34c097e36..265b552bb 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -402,6 +402,18 @@ $(addprefix lib/,\
)
endif
+ifdef LD_TEMPLATE_FILE
+# Generate a linker script (.ld file) from a template, for those builds that use it.
+GENERATED_LD_FILE = $(BUILD)/$(notdir $(patsubst %.template.ld,%.ld,$(LD_TEMPLATE_FILE)))
+#
+# ld_defines.pp is generated from ld_defines.c. See py/mkrules.mk.
+# Run gen_ld_files.py over ALL *.template.ld files, not just LD_TEMPLATE_FILE,
+# because it may include other template files.
+$(GENERATED_LD_FILE): $(BUILD)/ld_defines.pp boards/*.template.ld
+ $(STEPECHO) "GEN $@"
+ $(Q)$(PYTHON3) $(TOP)/tools/gen_ld_files.py --defines $< --out_dir $(BUILD) boards/*.template.ld
+endif
+
.PHONY: check-release-needs-clean-build
check-release-needs-clean-build:
diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk
index 87d506b3b..96a14c25b 100644
--- a/supervisor/supervisor.mk
+++ b/supervisor/supervisor.mk
@@ -25,14 +25,12 @@ CFLAGS += -DINTERNAL_FLASH_FILESYSTEM=$(INTERNAL_FLASH_FILESYSTEM)
ifndef QSPI_FLASH_FILESYSTEM
QSPI_FLASH_FILESYSTEM = 0
endif
-# EXPRESS_BOARD is obsolete and should be removed when samd-peripherals is updated.
-CFLAGS += -DQSPI_FLASH_FILESYSTEM=$(QSPI_FLASH_FILESYSTEM) -DEXPRESS_BOARD
+CFLAGS += -DQSPI_FLASH_FILESYSTEM=$(QSPI_FLASH_FILESYSTEM)
ifndef SPI_FLASH_FILESYSTEM
SPI_FLASH_FILESYSTEM = 0
endif
-# EXPRESS_BOARD is obsolete and should be removed when samd-peripherals is updated.
-CFLAGS += -DSPI_FLASH_FILESYSTEM=$(SPI_FLASH_FILESYSTEM) -DEXPRESS_BOARD
+CFLAGS += -DSPI_FLASH_FILESYSTEM=$(SPI_FLASH_FILESYSTEM)
ifeq ($(CIRCUITPY_BLEIO),1)
SRC_SUPERVISOR += supervisor/shared/bluetooth.c
diff --git a/tools/build_memory_info.py b/tools/build_memory_info.py
index f128561ab..afe49650e 100644
--- a/tools/build_memory_info.py
+++ b/tools/build_memory_info.py
@@ -41,7 +41,8 @@ data = 0
bss = 0
# stdin is the linker output.
for line in sys.stdin:
- print(line)
+ # Uncomment to see linker output.
+ # print(line)
line = line.strip()
if not line.startswith("text"):
text, data, bss = map(int, line.split()[:3])
@@ -51,7 +52,7 @@ regions = {}
with open(sys.argv[1], "r") as f:
for line in f:
line = line.strip()
- if line.startswith(("FLASH_FIRMWARE", "RAM")):
+ if line.startswith(("FLASH_FIRMWARE", "FLASH", "RAM")):
regions[line.split()[0]] = line.split("=")[-1]
for region in regions:
@@ -62,10 +63,17 @@ for region in regions:
space = M_PATTERN.sub(M_REPLACE, space)
regions[region] = eval(space)
-free_flash = regions["FLASH_FIRMWARE"] - text - data
-free_ram = regions["RAM"] - data - bss
-print("{} bytes free in flash firmware space out of {} bytes ({}kB).".format(free_flash, regions["FLASH_FIRMWARE"], regions["FLASH_FIRMWARE"] / 1024))
-print("{} bytes free in ram for heap out of {} bytes ({}kB).".format(free_ram, regions["RAM"], regions["RAM"] / 1024))
+# TODO Remove check for both FLASH_FIRMWARE and FLASH after all ports are converted to use FLASH_FIRMWARE.
+try:
+ firmware_region = regions["FLASH_FIRMWARE"]
+except KeyError:
+ firmware_region = regions["FLASH"]
+ram_region = regions["RAM"]
+
+free_flash = firmware_region - text - data
+free_ram = ram_region - data - bss
+print("{} bytes free in flash firmware space out of {} bytes ({}kB).".format(free_flash, firmware_region, firmware_region / 1024))
+print("{} bytes free in ram for heap out of {} bytes ({}kB).".format(free_ram, ram_region, ram_region / 1024))
print()
# Check that we have free flash space. GCC doesn't fail when the text + data