Skip to content

Commit

Permalink
[sw] Fix flash_header section attributes
Browse files Browse the repository at this point in the history
Moving the flash_header section from the linker script to an assembly file
allows us to specify that section's attributes and ensure it's not
writeable. This prevents the segment containing the code and other
read-only data to also be flagged as writeable.

Signed-off-by: Luís Marques <[email protected]>
  • Loading branch information
luismarques authored and lenary committed Aug 7, 2020
1 parent d4651a2 commit 64c8973
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 9 additions & 1 deletion sw/device/exts/common/flash_crt.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

/**
* Flash header.
*
* Contains the address of the entry point.
*/
.section .flash_header, "a", @progbits
.4byte _start

/**
* Flash executable runtime initialization code.
*/

// NOTE: The "ax" flag below is necessary to ensure that this section
// is allocated space in ROM by the linker.
.section .crt, "ax"
.section .crt, "ax", @progbits

.extern main
.extern crt_interrupt_vector
Expand Down
6 changes: 1 addition & 5 deletions sw/device/exts/common/flash_link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ SECTIONS {
* signature, but for now it's just the entry point at offset zero.
*/
.flash_header ORIGIN(eflash) : ALIGN(4) {
/**
* NOTE:ld scripts do not provide a mechanism to refer to ENTRY,
* so we just harcode the _start symbol.
*/
LONG(_start)
KEEP(*(.flash_header))
} > eflash

/**
Expand Down

0 comments on commit 64c8973

Please sign in to comment.