Skip to content

Commit

Permalink
bricks/stm32: Make bootloader region explicit.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
laurensvalk committed Aug 30, 2022
1 parent 1227529 commit 6268f1d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 42 deletions.
17 changes: 10 additions & 7 deletions bricks/cityhub/city_hub.ld
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
4 changes: 2 additions & 2 deletions bricks/debug/debug.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions bricks/essentialhub/essential_hub.ld
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand Down
17 changes: 10 additions & 7 deletions bricks/movehub/move_hub.ld
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
10 changes: 6 additions & 4 deletions bricks/primehub/prime_hub.ld
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions bricks/stm32/common.ld
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand All @@ -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 :
Expand All @@ -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);
Expand All @@ -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 :
Expand Down Expand Up @@ -100,7 +100,7 @@ SECTIONS
.name :
{
*(.name) /* customizable hub name */
} >FLASH
} >FLASH_FIRMWARE

.user :
{
Expand All @@ -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) }
}
17 changes: 10 additions & 7 deletions bricks/technichub/technic_hub.ld
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
6 changes: 3 additions & 3 deletions tools/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 6268f1d

Please sign in to comment.