From 6268f1d5bf8175dfa45a2731b2caa9c1563fb49d Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 29 Aug 2022 12:56:41 +0200 Subject: [PATCH] bricks/stm32: Make bootloader region explicit. - Makes bootloader section explicit and explains what it does. - Rename FLASH to FLASH_FIRMWARE to make it clear that things at the start of (what used to be called) FLASH don't actually go into the start of flash. --- bricks/cityhub/city_hub.ld | 17 ++++++++++------- bricks/debug/debug.ld | 4 ++-- bricks/essentialhub/essential_hub.ld | 8 +++++--- bricks/movehub/move_hub.ld | 17 ++++++++++------- bricks/primehub/prime_hub.ld | 10 ++++++---- bricks/stm32/common.ld | 18 +++++++++--------- bricks/technichub/technic_hub.ld | 17 ++++++++++------- tools/metadata.py | 6 +++--- 8 files changed, 55 insertions(+), 42 deletions(-) diff --git a/bricks/cityhub/city_hub.ld b/bricks/cityhub/city_hub.ld index 4da0d0fc8..56b40dbc0 100644 --- a/bricks/cityhub/city_hub.ld +++ b/bricks/cityhub/city_hub.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2018-2021 The Pybricks Authors */ +/* Copyright (c) 2018-2022 The Pybricks Authors */ /* GNU linker script for LEGO Powered Up City Hub @@ -9,13 +9,16 @@ /* Specify the memory areas */ MEMORY { - /* Flash size is 256K, bootloader resides in first 20K, last 4K seems to be reserved */ - FLASH (rx) : ORIGIN = 0x08005000, LENGTH = 232K - USER_FLASH (rx) : ORIGIN = 0x0803F000, LENGTH = 4K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K + /* Non-erasable BLE bootloader (LEGO LWP3). */ + FLASH_BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 20K + /* The firmware. Installed via BLE bootloader. */ + FLASH_FIRMWARE (rx) : ORIGIN = 0x08005000, LENGTH = 232K + /* User data written by the firmware during shutdown. */ + FLASH_USER (rx) : ORIGIN = 0x0803F000, LENGTH = 4K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K } "MAGIC_OFFSET" = 0x100; _stack_size = 4K; -_pbdrv_block_device_storage_start = ORIGIN(USER_FLASH); -_pbdrv_block_device_storage_size = LENGTH(USER_FLASH); +_pbdrv_block_device_storage_start = ORIGIN(FLASH_USER); +_pbdrv_block_device_storage_size = LENGTH(FLASH_USER); diff --git a/bricks/debug/debug.ld b/bricks/debug/debug.ld index ff2492517..46019bc6e 100644 --- a/bricks/debug/debug.ld +++ b/bricks/debug/debug.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */ - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + FLASH_FIRMWARE (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K } _stack_size = 8K; diff --git a/bricks/essentialhub/essential_hub.ld b/bricks/essentialhub/essential_hub.ld index b875ead2c..cbc4e192d 100644 --- a/bricks/essentialhub/essential_hub.ld +++ b/bricks/essentialhub/essential_hub.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2018-2021 The Pybricks Authors */ +/* Copyright (c) 2018-2022 The Pybricks Authors */ /* GNU linker script for LEGO SPIKE Essential hub @@ -9,8 +9,10 @@ /* Specify the memory areas */ MEMORY { - /* Flash size is 1M. Bootloader resides in first 32K. */ - FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 992K + /* Non-erasable DFU bootloader. */ + FLASH_BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 32K + /* The firmware. Installed via DFU bootloader */ + FLASH_FIRMWARE (rx) : ORIGIN = 0x08008000, LENGTH = 992K /* SRAM1 (256K) and SRAM2 (64K) are treated as one continuous block */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K } diff --git a/bricks/movehub/move_hub.ld b/bricks/movehub/move_hub.ld index 9f23e32e9..d403f30e5 100644 --- a/bricks/movehub/move_hub.ld +++ b/bricks/movehub/move_hub.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2018-2021 The Pybricks Authors */ +/* Copyright (c) 2018-2022 The Pybricks Authors */ /* GNU linker script for LEGO BOOST Move Hub @@ -9,13 +9,16 @@ /* Specify the memory areas */ MEMORY { - /* Flash size is 128K, bootloader resides in first 20K, last 2K seems to be reserved */ - FLASH (rx) : ORIGIN = 0x08005000, LENGTH = 106K - USER_FLASH (rx) : ORIGIN = 0x0801F800, LENGTH = 2K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K + /* Non-erasable BLE bootloader (LEGO LWP3). */ + FLASH_BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 20K + /* The firmware. Installed via BLE bootloader. */ + FLASH_FIRMWARE (rx) : ORIGIN = 0x08005000, LENGTH = 106K + /* User data written by the firmware during shutdown. */ + FLASH_USER (rx) : ORIGIN = 0x0801F800, LENGTH = 2K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K } "MAGIC_OFFSET" = 0x100; _stack_size = 3K; -_pbdrv_block_device_storage_start = ORIGIN(USER_FLASH); -_pbdrv_block_device_storage_size = LENGTH(USER_FLASH); +_pbdrv_block_device_storage_start = ORIGIN(FLASH_USER); +_pbdrv_block_device_storage_size = LENGTH(FLASH_USER); diff --git a/bricks/primehub/prime_hub.ld b/bricks/primehub/prime_hub.ld index fb5136534..974098b45 100644 --- a/bricks/primehub/prime_hub.ld +++ b/bricks/primehub/prime_hub.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2018-2021 The Pybricks Authors */ +/* Copyright (c) 2018-2022 The Pybricks Authors */ /* GNU linker script for LEGO SPIKE Prime hub @@ -9,10 +9,12 @@ /* Specify the memory areas */ MEMORY { - /* Flash size is 1M. Bootloader resides in first 32K. */ - FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 992K + /* Non-erasable DFU bootloader. */ + FLASH_BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 32K + /* The firmware. Installed via DFU bootloader */ + FLASH_FIRMWARE (rx) : ORIGIN = 0x08008000, LENGTH = 992K /* SRAM1 (256K) and SRAM2 (64K) are treated as one continuous block */ - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K } _stack_size = 16K; diff --git a/bricks/stm32/common.ld b/bricks/stm32/common.ld index 67495f128..fe45b7398 100644 --- a/bricks/stm32/common.ld +++ b/bricks/stm32/common.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2018-2021 The Pybricks Authors */ +/* Copyright (c) 2018-2022 The Pybricks Authors */ /* top end of the stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); @@ -9,7 +9,7 @@ _sstack = _estack - _stack_size; /* define output sections */ SECTIONS { - /* The program code and other data goes into FLASH */ + /* The program code and other data goes into FLASH_FIRMWARE */ .text : { . = ALIGN(4); @@ -27,7 +27,7 @@ SECTIONS . = ALIGN(4); _etext = .; /* define a global symbol at end of code */ _sidata = _etext; /* This is used by the startup in order to initialize the .data section */ - } >FLASH + } >FLASH_FIRMWARE /* This section is for special needs of the Move Hub firmware - must be first section in SRAM! */ .magic : @@ -45,8 +45,8 @@ SECTIONS /* This is the initialized data section The program executes knowing that the data is in the RAM - but the loader puts the initial values in the FLASH (inidata). - It is one task of the startup to copy the initial values from FLASH to RAM. */ + but the loader puts the initial values in the FLASH_FIRMWARE (inidata). + It is one task of the startup to copy the initial values from FLASH_FIRMWARE to RAM. */ .data : { . = ALIGN(4); @@ -55,7 +55,7 @@ SECTIONS . = ALIGN(4); _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ - } >RAM AT> FLASH + } >RAM AT> FLASH_FIRMWARE /* Uninitialized data section */ .bss : @@ -100,7 +100,7 @@ SECTIONS .name : { *(.name) /* customizable hub name */ - } >FLASH + } >FLASH_FIRMWARE .user : { @@ -109,14 +109,14 @@ SECTIONS LONG(SIZEOF(.user) - (. + 4 - LOADADDR(.user))); /* Size of compiled main.mpy file in bytes */ _pb_user_mpy_data = .; KEEP(*(.mpy)); /* Compiled main.mpy file */ - } >FLASH + } >FLASH_FIRMWARE .checksum : { . = ALIGN(4); _checksum = .; LONG(0) /* This gets replaced later with proper checksum by other tools. */ - } >FLASH + } >FLASH_FIRMWARE .ARM.attributes 0 : { *(.ARM.attributes) } } diff --git a/bricks/technichub/technic_hub.ld b/bricks/technichub/technic_hub.ld index f4596518a..bf8444c07 100644 --- a/bricks/technichub/technic_hub.ld +++ b/bricks/technichub/technic_hub.ld @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2013, 2014 Damien P. George */ -/* Copyright (c) 2019-2021 The Pybricks Authors */ +/* Copyright (c) 2019-2022 The Pybricks Authors */ /* GNU linker script for LEGO Technic Hub @@ -9,13 +9,16 @@ /* Specify the memory areas */ MEMORY { - /* Flash size is 256K, bootloader resides in first 32K, last 4K is for user data */ - FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 220K - USER_FLASH (rx) : ORIGIN = 0x0803F000, LENGTH = 4K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K + /* Non-erasable BLE bootloader (LEGO LWP3). */ + FLASH_BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 32K + /* The firmware. Installed via BLE bootloader. */ + FLASH_FIRMWARE (rx) : ORIGIN = 0x08008000, LENGTH = 220K + /* User data written by the firmware during shutdown. */ + FLASH_USER (rx) : ORIGIN = 0x0803F000, LENGTH = 4K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K } "MAGIC_OFFSET" = 0x200; _stack_size = 8K; -_pbdrv_block_device_storage_start = ORIGIN(USER_FLASH); -_pbdrv_block_device_storage_size = LENGTH(USER_FLASH); +_pbdrv_block_device_storage_start = ORIGIN(FLASH_USER); +_pbdrv_block_device_storage_size = LENGTH(FLASH_USER); diff --git a/tools/metadata.py b/tools/metadata.py index fb0fafb0e..c5e4a2454 100755 --- a/tools/metadata.py +++ b/tools/metadata.py @@ -77,7 +77,7 @@ def generate( user_start = None # Starting address of user .mpy file for line in map_file.readlines(): - match = re.match(r"^FLASH\s+(0x[0-9A-Fa-f]{8,16})\s+(0x[0-9A-Fa-f]{8,16})", line) + match = re.match(r"^FLASH_FIRMWARE\s+(0x[0-9A-Fa-f]{8,16})\s+(0x[0-9A-Fa-f]{8,16})", line) if match: flash_origin = int(match[1], base=0) flash_length = int(match[2], base=0) @@ -95,11 +95,11 @@ def generate( continue if flash_origin is None: - print("Failed to find 'FLASH' start address", file=sys.stderr) + print("Failed to find 'FLASH_FIRMWARE' start address", file=sys.stderr) exit(1) if flash_length is None: - print("Failed to find 'FLASH' length", file=sys.stderr) + print("Failed to find 'FLASH_FIRMWARE' length", file=sys.stderr) exit(1) if name_start is None: