diff --git a/bricks/cityhub/city_hub.ld b/bricks/cityhub/city_hub.ld index 2b070fb8a..aef4b071b 100644 --- a/bricks/cityhub/city_hub.ld +++ b/bricks/cityhub/city_hub.ld @@ -6,7 +6,8 @@ GNU linker script for LEGO Powered Up City Hub */ -/* Specify the memory areas */ +/* Memory areas. NB: Total storage size (FLASH_USER_0 + FLASH_USER_1) + MUST match PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE */ MEMORY { /* Non-erasable BLE bootloader (LEGO LWP3). Device boots only if all words @@ -15,7 +16,7 @@ MEMORY /* The firmware. Installed via BLE bootloader. */ FLASH_FIRMWARE (rx) : ORIGIN = 0x08005000, LENGTH = 220K /* User data written by the firmware during shutdown. */ - FLASH_USER_0 (rx) : ORIGIN = 0x0803C000, LENGTH = 12K + FLASH_USER_0 (rx) : ORIGIN = 0x0803C000, LENGTH = 12K /* As above, but this part is not counted by bootloader checksum. */ FLASH_USER_1 (rx) : ORIGIN = 0x0803F000, LENGTH = 4K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K @@ -23,6 +24,9 @@ MEMORY "MAGIC_OFFSET" = 0x100; _stack_size = 4K; + +/* Start of data storage. */ _pbdrv_block_device_storage_start = ORIGIN(FLASH_USER_0); -_pbdrv_block_device_storage_size = LENGTH(FLASH_USER_0) + LENGTH(FLASH_USER_1); + +/* Portion of the data parsed for the checksum on boot. */ _pbsys_program_load_checked_size = LENGTH(FLASH_USER_0); diff --git a/bricks/movehub/move_hub.ld b/bricks/movehub/move_hub.ld index ad3c73505..50f533d13 100644 --- a/bricks/movehub/move_hub.ld +++ b/bricks/movehub/move_hub.ld @@ -6,7 +6,8 @@ GNU linker script for LEGO BOOST Move Hub */ -/* Specify the memory areas */ +/* Memory areas. NB: Total storage size (FLASH_USER_0 + FLASH_USER_1) + MUST match PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE */ MEMORY { /* Non-erasable BLE bootloader (LEGO LWP3). Device boots only if all words @@ -15,7 +16,7 @@ MEMORY /* The firmware. Installed via BLE bootloader. */ FLASH_FIRMWARE (rx) : ORIGIN = 0x08005000, LENGTH = 104K /* User data written by the firmware during shutdown. */ - FLASH_USER_0 (rx) : ORIGIN = 0x0801F000, LENGTH = 2K + FLASH_USER_0 (rx) : ORIGIN = 0x0801F000, LENGTH = 2K /* As above, but this part is not counted by bootloader checksum. */ FLASH_USER_1 (rx) : ORIGIN = 0x0801F800, LENGTH = 2K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K @@ -23,6 +24,9 @@ MEMORY "MAGIC_OFFSET" = 0x100; _stack_size = 3K; + +/* Start of data storage. */ _pbdrv_block_device_storage_start = ORIGIN(FLASH_USER_0); -_pbdrv_block_device_storage_size = LENGTH(FLASH_USER_0) + LENGTH(FLASH_USER_1); + +/* Portion of the data parsed for the checksum on boot. */ _pbsys_program_load_checked_size = LENGTH(FLASH_USER_0); diff --git a/bricks/technichub/technic_hub.ld b/bricks/technichub/technic_hub.ld index 54ede546e..99ac77543 100644 --- a/bricks/technichub/technic_hub.ld +++ b/bricks/technichub/technic_hub.ld @@ -6,7 +6,8 @@ GNU linker script for LEGO Technic Hub */ -/* Specify the memory areas */ +/* Memory areas. NB: Total storage size (FLASH_USER_0 + FLASH_USER_1) + MUST match PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE */ MEMORY { /* Non-erasable BLE bootloader (LEGO LWP3). Device boots only if all words @@ -23,6 +24,9 @@ MEMORY "MAGIC_OFFSET" = 0x200; _stack_size = 8K; + +/* Start of data storage. */ _pbdrv_block_device_storage_start = ORIGIN(FLASH_USER_0); -_pbdrv_block_device_storage_size = LENGTH(FLASH_USER_0) + LENGTH(FLASH_USER_1); + +/* Portion of the data parsed for the checksum on boot. */ _pbsys_program_load_checked_size = LENGTH(FLASH_USER_0); diff --git a/lib/pbio/drv/block_device/block_device_flash_stm32.c b/lib/pbio/drv/block_device/block_device_flash_stm32.c index 4f4d3612a..5425c0caf 100644 --- a/lib/pbio/drv/block_device/block_device_flash_stm32.c +++ b/lib/pbio/drv/block_device/block_device_flash_stm32.c @@ -21,12 +21,6 @@ #include STM32_HAL_H -uint32_t pbdrv_block_device_get_size(void) { - // Defined in linker script. - extern uint32_t _pbdrv_block_device_storage_size; - return (uint32_t)(&_pbdrv_block_device_storage_size); -} - void pbdrv_block_device_init(void) { } @@ -37,7 +31,7 @@ PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffe PT_BEGIN(pt); // Exit on invalid size. - if (size == 0 || offset + size > pbdrv_block_device_get_size()) { + if (size == 0 || offset + size > PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE) { *err = PBIO_ERROR_INVALID_ARG; PT_EXIT(pt); } @@ -59,7 +53,7 @@ static pbio_error_t block_device_erase_and_write(uint8_t *buffer, uint32_t size) static const uint32_t base_address = (uint32_t)(&_pbdrv_block_device_storage_start[0]); // Exit if size is 0, too big, or not a multiple of double-word size. - if (size == 0 || size > pbdrv_block_device_get_size() || size % sizeof(uint64_t)) { + if (size == 0 || size > PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE || size % sizeof(uint64_t)) { return PBIO_ERROR_INVALID_ARG; } @@ -75,11 +69,11 @@ static pbio_error_t block_device_erase_and_write(uint8_t *buffer, uint32_t size) .PageAddress = base_address, #elif defined(STM32L4) .Banks = FLASH_BANK_1, // Hard coded for STM32L431RC. - .Page = (FLASH_SIZE - (pbdrv_block_device_get_size())) / FLASH_PAGE_SIZE, + .Page = (FLASH_SIZE - (PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE)) / FLASH_PAGE_SIZE, #else #error "Unsupported target." #endif - .NbPages = pbdrv_block_device_get_size() / FLASH_PAGE_SIZE, + .NbPages = PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE / FLASH_PAGE_SIZE, .TypeErase = FLASH_TYPEERASE_PAGES }; diff --git a/lib/pbio/drv/block_device/block_device_w25qxx_stm32.c b/lib/pbio/drv/block_device/block_device_w25qxx_stm32.c index 79c521b01..0dede3b4c 100644 --- a/lib/pbio/drv/block_device/block_device_w25qxx_stm32.c +++ b/lib/pbio/drv/block_device/block_device_w25qxx_stm32.c @@ -360,7 +360,7 @@ PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffe PT_BEGIN(pt); // Exit on invalid size. - if (size == 0 || offset + size > pbdrv_block_device_get_size()) { + if (size == 0 || offset + size > PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE) { *err = PBIO_ERROR_INVALID_ARG; PT_EXIT(pt); } @@ -377,7 +377,7 @@ PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffe size_now = pbio_math_min(size - size_done, FLASH_SIZE_READ); // Set address for this read request and send it. - set_address_be(&cmd_request_read.buffer[1], bdev.pdata->start_address + offset + size_done); + set_address_be(&cmd_request_read.buffer[1], PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_START_ADDRESS + offset + size_done); PT_SPAWN(pt, &child, spi_command_thread(&child, &cmd_request_read, err)); if (*err != PBIO_SUCCESS) { goto out; @@ -467,7 +467,7 @@ PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size PT_BEGIN(pt); // Exit on invalid size. - if (size == 0 || size > pbdrv_block_device_get_size()) { + if (size == 0 || size > PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE) { *err = PBIO_ERROR_INVALID_ARG; PT_EXIT(pt); } @@ -483,7 +483,7 @@ PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size for (offset = 0; offset < size; offset += FLASH_SIZE_ERASE) { // Writing size 0 means erase. PT_SPAWN(pt, &child, flash_erase_or_write(&child, - bdev.pdata->start_address + offset, NULL, 0, err)); + PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_START_ADDRESS + offset, NULL, 0, err)); if (*err != PBIO_SUCCESS) { goto out; } @@ -493,7 +493,7 @@ PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size for (size_done = 0; size_done < size; size_done += size_now) { size_now = pbio_math_min(size - size_done, FLASH_SIZE_WRITE); PT_SPAWN(pt, &child, flash_erase_or_write(&child, - bdev.pdata->start_address + size_done, buffer + size_done, size_now, err)); + PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_START_ADDRESS + size_done, buffer + size_done, size_now, err)); if (*err != PBIO_SUCCESS) { goto out; } @@ -505,10 +505,6 @@ PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size PT_END(pt); } -uint32_t pbdrv_block_device_get_size(void) { - return bdev.pdata->end_address - bdev.pdata->start_address; -} - PROCESS(pbdrv_block_device_w25qxx_stm32_init_process, "w25qxx"); void pbdrv_block_device_init(void) { diff --git a/lib/pbio/drv/block_device/block_device_w25qxx_stm32.h b/lib/pbio/drv/block_device/block_device_w25qxx_stm32.h index 705803347..232cb39ea 100644 --- a/lib/pbio/drv/block_device/block_device_w25qxx_stm32.h +++ b/lib/pbio/drv/block_device/block_device_w25qxx_stm32.h @@ -40,15 +40,6 @@ typedef struct { IRQn_Type irq; /** The /CS pin. */ const pbdrv_gpio_t pin_ncs; - /** - * Platform-specific starting address on the chip from where we can safely - * write data. All reads and writes to the block device are relative to - * this chip address. This can be used to protect the first region of flash - * if it is used to store things like bootloader information. - */ - uint32_t start_address; - /** Ending address (exclusive) complementary to the start_address. */ - uint32_t end_address; } pbdrv_block_device_w25qxx_stm32_platform_data_t; /** diff --git a/lib/pbio/include/pbdrv/block_device.h b/lib/pbio/include/pbdrv/block_device.h index 36ff130d3..4554dfba0 100644 --- a/lib/pbio/include/pbdrv/block_device.h +++ b/lib/pbio/include/pbdrv/block_device.h @@ -18,13 +18,6 @@ #if PBDRV_CONFIG_BLOCK_DEVICE -/** - * Gets the size of the block device. - * - * @return The maximum size that can be read or written. - */ -uint32_t pbdrv_block_device_get_size(void); - /** * Read data from a storage device. * @@ -71,9 +64,6 @@ PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size #else -static inline uint32_t pbdrv_block_device_get_size(void) { - return 0; -} static inline PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { PT_BEGIN(pt); *err = PBIO_ERROR_NOT_SUPPORTED; diff --git a/lib/pbio/platform/city_hub/pbdrvconfig.h b/lib/pbio/platform/city_hub/pbdrvconfig.h index 01d6a64de..150bcc3ab 100644 --- a/lib/pbio/platform/city_hub/pbdrvconfig.h +++ b/lib/pbio/platform/city_hub/pbdrvconfig.h @@ -24,6 +24,7 @@ #define PBDRV_CONFIG_BLOCK_DEVICE (1) #define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32 (1) +#define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE (16 * 1024) // Must match FLASH_USER_0 + FLASH_USER_1 in linker script #define PBDRV_CONFIG_BLUETOOTH (1) #define PBDRV_CONFIG_BLUETOOTH_STM32_CC2640 (1) diff --git a/lib/pbio/platform/city_hub/pbsysconfig.h b/lib/pbio/platform/city_hub/pbsysconfig.h index bc954ab7c..2587e9095 100644 --- a/lib/pbio/platform/city_hub/pbsysconfig.h +++ b/lib/pbio/platform/city_hub/pbsysconfig.h @@ -1,12 +1,15 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020-2022 The Pybricks Authors +#include "pbdrvconfig.h" + #define PBSYS_CONFIG_BATTERY_CHARGER (0) #define PBSYS_CONFIG_BLUETOOTH (1) #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (20 * 1024) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (1) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (20 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0) diff --git a/lib/pbio/platform/debug/pbsysconfig.h b/lib/pbio/platform/debug/pbsysconfig.h index 1f908cc44..b0acee237 100644 --- a/lib/pbio/platform/debug/pbsysconfig.h +++ b/lib/pbio/platform/debug/pbsysconfig.h @@ -6,7 +6,8 @@ #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (64 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (64 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (0) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (0) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0) diff --git a/lib/pbio/platform/essential_hub/pbdrvconfig.h b/lib/pbio/platform/essential_hub/pbdrvconfig.h index 7532e2bcd..7cd63e184 100644 --- a/lib/pbio/platform/essential_hub/pbdrvconfig.h +++ b/lib/pbio/platform/essential_hub/pbdrvconfig.h @@ -35,6 +35,12 @@ #define PBDRV_CONFIG_BLOCK_DEVICE (1) #define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32 (1) #define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_W25Q32 (1) +// Carve out 256K from the reserved 1M area at the start of the flash. +// This avoids touching the file system, the area read by the LEGO +// bootloader and the area used by upstream MicroPython. Currently, this +// just needs to be big enough to back up the user program on shutdown. +#define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_START_ADDRESS (512 * 1024) +#define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE (256 * 1024) #define PBDRV_CONFIG_BUTTON (1) #define PBDRV_CONFIG_BUTTON_GPIO (1) diff --git a/lib/pbio/platform/essential_hub/pbsysconfig.h b/lib/pbio/platform/essential_hub/pbsysconfig.h index 41c5985db..c7711d15a 100644 --- a/lib/pbio/platform/essential_hub/pbsysconfig.h +++ b/lib/pbio/platform/essential_hub/pbsysconfig.h @@ -6,7 +6,8 @@ #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (256 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (258 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (0) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (1) diff --git a/lib/pbio/platform/essential_hub/platform.c b/lib/pbio/platform/essential_hub/platform.c index 147839285..117da2f25 100644 --- a/lib/pbio/platform/essential_hub/platform.c +++ b/lib/pbio/platform/essential_hub/platform.c @@ -630,12 +630,6 @@ const pbdrv_block_device_w25qxx_stm32_platform_data_t pbdrv_block_device_w25qxx_ .bank = GPIOB, .pin = 12, }, - // Carve out 256K from the reserved 1M area at the start of the flash. - // This avoids touching the file system, the area read by the LEGO - // bootloader and the area used by upstream MicroPython. Currently, this - // just needs to be big enough to back up the user program on shutdown. - .start_address = 512 * 1024, - .end_address = 768 * 1024, }; // USB diff --git a/lib/pbio/platform/move_hub/pbdrvconfig.h b/lib/pbio/platform/move_hub/pbdrvconfig.h index c9b3084ec..d3d8a1a05 100644 --- a/lib/pbio/platform/move_hub/pbdrvconfig.h +++ b/lib/pbio/platform/move_hub/pbdrvconfig.h @@ -20,6 +20,7 @@ #define PBDRV_CONFIG_BLOCK_DEVICE (1) #define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32 (1) +#define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE (4 * 1024) // Must match FLASH_USER_0 + FLASH_USER_1 in linker script #define PBDRV_CONFIG_BLUETOOTH (1) #define PBDRV_CONFIG_BLUETOOTH_STM32_BLUENRG (1) diff --git a/lib/pbio/platform/move_hub/pbsysconfig.h b/lib/pbio/platform/move_hub/pbsysconfig.h index 59fa95046..0bc07f69c 100644 --- a/lib/pbio/platform/move_hub/pbsysconfig.h +++ b/lib/pbio/platform/move_hub/pbsysconfig.h @@ -1,12 +1,15 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020-2022 The Pybricks Authors +#include "pbdrvconfig.h" + #define PBSYS_CONFIG_BATTERY_CHARGER (0) #define PBSYS_CONFIG_BLUETOOTH (1) #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (7 * 1024) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (1) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (7 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0) diff --git a/lib/pbio/platform/prime_hub/pbdrvconfig.h b/lib/pbio/platform/prime_hub/pbdrvconfig.h index 917f08ba9..487dfc798 100644 --- a/lib/pbio/platform/prime_hub/pbdrvconfig.h +++ b/lib/pbio/platform/prime_hub/pbdrvconfig.h @@ -35,6 +35,12 @@ #define PBDRV_CONFIG_BLOCK_DEVICE (1) #define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32 (1) #define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_W25Q256 (1) +// Carve out 256K from the reserved 1M area at the start of the flash. +// This avoids touching the file system, the area read by the LEGO +// bootloader and the area used by upstream MicroPython. Currently, this +// just needs to be big enough to back up the user program on shutdown. +#define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_START_ADDRESS (512 * 1024) +#define PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE (256 * 1024) #define PBDRV_CONFIG_BUTTON (1) #define PBDRV_CONFIG_BUTTON_RESISTOR_LADDER (1) diff --git a/lib/pbio/platform/prime_hub/pbsysconfig.h b/lib/pbio/platform/prime_hub/pbsysconfig.h index 7dc8ab8b8..c29611886 100644 --- a/lib/pbio/platform/prime_hub/pbsysconfig.h +++ b/lib/pbio/platform/prime_hub/pbsysconfig.h @@ -6,7 +6,8 @@ #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (256 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (258 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_W25QXX_STM32_SIZE) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (0) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (1) diff --git a/lib/pbio/platform/prime_hub/platform.c b/lib/pbio/platform/prime_hub/platform.c index dac3f915c..03927e8a3 100644 --- a/lib/pbio/platform/prime_hub/platform.c +++ b/lib/pbio/platform/prime_hub/platform.c @@ -923,12 +923,6 @@ const pbdrv_block_device_w25qxx_stm32_platform_data_t pbdrv_block_device_w25qxx_ .bank = GPIOB, .pin = 12, }, - // Carve out 256K from the reserved 1M area at the start of the flash. - // This avoids touching the file system, the area read by the LEGO - // bootloader and the area used by upstream MicroPython. Currently, this - // just needs to be big enough to back up the user program on shutdown. - .start_address = 512 * 1024, - .end_address = 768 * 1024, }; // USB diff --git a/lib/pbio/platform/technic_hub/pbdrvconfig.h b/lib/pbio/platform/technic_hub/pbdrvconfig.h index 766d394ea..0c514c407 100644 --- a/lib/pbio/platform/technic_hub/pbdrvconfig.h +++ b/lib/pbio/platform/technic_hub/pbdrvconfig.h @@ -25,6 +25,7 @@ #define PBDRV_CONFIG_BLOCK_DEVICE (1) #define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32 (1) +#define PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE (16 * 1024) // Must match FLASH_USER_0 + FLASH_USER_1 in linker script #define PBDRV_CONFIG_BLUETOOTH (1) #define PBDRV_CONFIG_BLUETOOTH_STM32_CC2640 (1) diff --git a/lib/pbio/platform/technic_hub/pbsysconfig.h b/lib/pbio/platform/technic_hub/pbsysconfig.h index dfda9f900..7d4e95737 100644 --- a/lib/pbio/platform/technic_hub/pbsysconfig.h +++ b/lib/pbio/platform/technic_hub/pbsysconfig.h @@ -1,12 +1,15 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020-2022 The Pybricks Authors +#include "pbdrvconfig.h" + #define PBSYS_CONFIG_BATTERY_CHARGER (0) #define PBSYS_CONFIG_BLUETOOTH (1) #define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0) #define PBSYS_CONFIG_MAIN (1) #define PBSYS_CONFIG_PROGRAM_LOAD (1) -#define PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE (32 * 1024) #define PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM (1) +#define PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE (32 * 1024) +#define PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32_SIZE) #define PBSYS_CONFIG_STATUS_LIGHT (1) #define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0) diff --git a/lib/pbio/sys/program_load.c b/lib/pbio/sys/program_load.c index 811afdb99..5ff945861 100644 --- a/lib/pbio/sys/program_load.c +++ b/lib/pbio/sys/program_load.c @@ -19,6 +19,11 @@ #include "core.h" +// Sanity check that application RAM is enough to load ROM and still do something useful +#if PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE < PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE + 2048 +#error "Application RAM must be at least ROM size + 2K." +#endif + /** * Map of loaded data. All data types are little-endian. */ @@ -44,7 +49,7 @@ typedef struct { /** * Data of the application program (code + heap). */ - uint8_t program_data[PBSYS_CONFIG_PROGRAM_LOAD_PROGRAM_DATA_SIZE] __attribute__((aligned(sizeof(void *)))); + uint8_t program_data[PBSYS_CONFIG_PROGRAM_LOAD_RAM_SIZE] __attribute__((aligned(sizeof(void *)))); } data_map_t; // The data map sits at the start of user RAM. @@ -90,7 +95,7 @@ static void pbsys_program_load_update_checksum(void) { // Gets the (constant) maximum program size. static inline uint32_t pbsys_program_load_get_max_program_size() { - return pbdrv_block_device_get_size() - MAP_HEADER_SIZE; + return PBSYS_CONFIG_PROGRAM_LOAD_ROM_SIZE - MAP_HEADER_SIZE; } /**