Skip to content

Commit cd809c3

Browse files
committed
Add Neotron Pico compatible linker script.
1 parent 2daba85 commit cd809c3

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ This OS is a work in progress. We intend to support:
2222
Your board will need an appropriate Neotron BIOS installed, and you need to have OpenOCD running for your particular board. You also need to set the linker
2323
arguments so you link the binary to suit the memory available on your system.
2424

25+
### Build Instructions for the Neotron Pico
26+
27+
The Neotron Pico has some special memory requirements - in particular, the
28+
flash lives at `0x1000_0000` and not `0x0000_0000`. There is 1920 KiB of
29+
flash, and 240 KiB of RAM available.
30+
31+
```
32+
$ git clone https://github.com/neotron-compute/Neotron-OS.git
33+
$ cd Neotron-OS
34+
$ git submodule update --init
35+
$ RUSTFLAGS="-C link-arg=-Tneotron-os-pico.ld" cargo build --release --target=thumbv6m-none-eabi
36+
```
37+
2538
### Build Instructions for 256K RAM systems
2639

2740
Systems which reserve the second 512 KiB of Flash and first 256 KiB of SRAM

neotron-os-pico.ld

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/* # Developer notes
2+
3+
- Symbols that start with a double underscore (__) are considered "private"
4+
5+
- Symbols that start with a single underscore (_) are considered "semi-public"; they can be
6+
overridden in a user linker script, but should not be referred from user code (e.g. `extern "C" {
7+
static mut __sbss }`).
8+
9+
- `EXTERN` forces the linker to keep a symbol in the final binary. We use this to make sure a
10+
symbol if not dropped if it appears in or near the front of the linker arguments and "it's not
11+
needed" by any of the preceding objects (linker arguments)
12+
13+
- `PROVIDE` is used to provide default values that can be overridden by a user linker script
14+
15+
- On alignment: it's important for correctness that the VMA boundaries of both .bss and .data *and*
16+
the LMA of .data are all 4-byte aligned. These alignments are assumed by the RAM initialization
17+
routine. There's also a second benefit: 4-byte aligned boundaries means that you won't see
18+
"Address (..) is out of bounds" in the disassembly produced by `objdump`.
19+
*/
20+
21+
/* Provides information about the memory layout of the device */
22+
MEMORY
23+
{
24+
/* The BIOS gets the first 128 KiB of Flash, leaving 1920 KiB for the OS */
25+
FLASH (rx) : ORIGIN = 0x10020000, LENGTH = 0x1E0000
26+
/*
27+
* The RP2040 has 256 KiB of SRAM striped across four banks (for high
28+
* performance), plus a fifth bank containing another 8 KiB of RAM. The
29+
* BIOS is at the top of the high-performance RAM. We get the lower part.
30+
*/
31+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x3C000
32+
/* The SDRAM holds the LCD framebuffers */
33+
}
34+
35+
/* # Entry point = what the BIOS calls to start the OS */
36+
ENTRY(entry_point);
37+
EXTERN(__RESET_VECTOR);
38+
39+
/* # Sections */
40+
SECTIONS
41+
{
42+
43+
/* ## Sections in FLASH */
44+
.entry_point ORIGIN(FLASH) :
45+
{
46+
KEEP(*(.entry_point))
47+
} > FLASH
48+
49+
PROVIDE(_stext = ADDR(.entry_point) + SIZEOF(.entry_point));
50+
51+
/* ### .text */
52+
.text _stext :
53+
{
54+
*(.text .text.*);
55+
*(.HardFaultTrampoline);
56+
*(.HardFault.*);
57+
} > FLASH
58+
59+
/* ### .rodata */
60+
.rodata : ALIGN(4)
61+
{
62+
*(.rodata .rodata.*);
63+
64+
/* 4-byte align the end (VMA) of this section.
65+
This is required by LLD to ensure the LMA of the following .data
66+
section will have the correct alignment. */
67+
. = ALIGN(4);
68+
} > FLASH
69+
70+
/* ## Sections in RAM */
71+
/* ### .data */
72+
.data : ALIGN(4)
73+
{
74+
. = ALIGN(4);
75+
__sdata = .;
76+
*(.data .data.*);
77+
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
78+
__edata = .;
79+
} > RAM AT > FLASH
80+
81+
/* LMA of .data */
82+
__sidata = LOADADDR(.data);
83+
84+
/* ### .bss */
85+
.bss : ALIGN(4)
86+
{
87+
. = ALIGN(4);
88+
__sbss = .;
89+
*(.bss .bss.*);
90+
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
91+
__ebss = .;
92+
} > RAM
93+
94+
/* ### .uninit */
95+
.uninit (NOLOAD) : ALIGN(4)
96+
{
97+
. = ALIGN(4);
98+
*(.uninit .uninit.*);
99+
. = ALIGN(4);
100+
} > RAM
101+
102+
/* Place the heap right after `.uninit` */
103+
. = ALIGN(4);
104+
__sheap = .;
105+
106+
/* ## .got */
107+
/* Dynamic relocations are unsupported. This section is only used to detect relocatable code in
108+
the input files and raise an error if relocatable code is found */
109+
.got (NOLOAD) :
110+
{
111+
KEEP(*(.got .got.*));
112+
}
113+
114+
/* ## Discarded sections */
115+
/DISCARD/ :
116+
{
117+
/* Unused exception related info that only wastes space */
118+
*(.ARM.exidx);
119+
*(.ARM.exidx.*);
120+
*(.ARM.extab.*);
121+
}
122+
}
123+
124+
/* Do not exceed this mark in the error messages below | */
125+
/* # Alignment checks */
126+
ASSERT(ORIGIN(FLASH) % 4 == 0, "
127+
ERROR(cortex-m-rt): the start of the FLASH region must be 4-byte aligned");
128+
129+
ASSERT(ORIGIN(RAM) % 4 == 0, "
130+
ERROR(cortex-m-rt): the start of the RAM region must be 4-byte aligned");
131+
132+
ASSERT(__sdata % 4 == 0 && __edata % 4 == 0, "
133+
BUG(cortex-m-rt): .data is not 4-byte aligned");
134+
135+
ASSERT(__sidata % 4 == 0, "
136+
BUG(cortex-m-rt): the LMA of .data is not 4-byte aligned");
137+
138+
ASSERT(__sbss % 4 == 0 && __ebss % 4 == 0, "
139+
BUG(cortex-m-rt): .bss is not 4-byte aligned");
140+
141+
ASSERT(__sheap % 4 == 0, "
142+
BUG(cortex-m-rt): start of .heap is not 4-byte aligned");
143+
144+
/* # Position checks */
145+
146+
/* ## .text */
147+
ASSERT(_stext + SIZEOF(.text) < ORIGIN(FLASH) + LENGTH(FLASH), "
148+
ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
149+
Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'");
150+
151+
/* # Other checks */
152+
ASSERT(SIZEOF(.got) == 0, "
153+
ERROR(cortex-m-rt): .got section detected in the input object files
154+
Dynamic relocations are not supported. If you are linking to C code compiled using
155+
the 'cc' crate then modify your build script to compile the C code _without_
156+
the -fPIC flag. See the documentation of the `cc::Build.pic` method for details.");
157+
/* Do not exceed this mark in the error messages above | */

0 commit comments

Comments
 (0)