1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18    These addresses are fake, but in a particular way that mesh with our expectations.
19    - ".flash" will contain all parts of the app that go into actual flash
20      *app header
21      * code
22      * RO data
23      * initial contents of RW data
24      * initial contents of the GOT
25      * list of relocs
26      * list of symbols
27    - ".ram" will contain all data that uses ram (and is not part of the flash image)
28      * RW data in its actua location
29      * BSS
30      * the GOT
31    - ".trash" contains sections taht GCC simply feel like it MUST produce (link error otherwise) but we have no use for. it will be tripped
32
33    After this image is produced a nonoapp_postprocess unitily will process relocs and symbols and compress them to a small reloc table
34    while also modifying the app code itself potentially to adjust for new reloc format. This shrinks relocs a lot. GCC produces relocs at 8
35    bytes per reloc and symbols at 16 bytes per symbol. We remove all symbol infos (as we do not need them) and compress the relevant data
36    from there into relocs and app image itself, generating 4 bytes per reloc of "nano reloc data"
37
38    Our format allows apps that are up to 256MB of flash and 256MB of ram in size.
39*/
40
41MEMORY
42{
43    flash   : ORIGIN = 0x10000000,  LENGTH = 256K /* we write this to flash */
44    ram     : ORIGIN = 0x80000000,  LENGTH = 128K /* we allocate this in ram */
45    trash   : ORIGIN = 0xF0000000,  LENGTH = 256K /* we throw this away soon after linking */
46}
47
48SECTIONS
49{
50    .flash : {
51        /***** start of struct BinHdr [see nanohub/nanohub.h] *****/
52        /* binary format marker: 'NBIN' (LE) */
53        LONG(0x4E49424E)
54
55        /* version */
56        KEEP(*(.app_version));
57
58        /* things we need to load app */
59        LONG(__data_start)
60        LONG(__data_end)
61        LONG(LOADADDR(.data))
62
63        LONG(__bss_start)
64        LONG(__bss_end)
65
66        /* things we need to run it */
67        LONG(__got_start)
68        LONG(__got_end)
69        LONG(__rel_start)
70        LONG(__rel_end)
71
72        KEEP(*(.app_init));
73        /***** end of struct BinHdr [see nanohub/nanohub.h] *****/
74
75        /* code */
76        *(.text) *(.text.*) ;
77        *(.rodata) *(.rodata.*) ;
78        . = ALIGN(4);
79    } > flash = 0xff
80
81    .data : {
82        . = ALIGN(4);
83        __data_start = ABSOLUTE(.);
84        __dso_handle = ABSOLUTE(__data_start);
85        *(.data);
86        *(.data.*);
87        . = ALIGN(4);
88        __data_end = ABSOLUTE(.);
89
90        . = ALIGN(4);
91        __init_array_start = ABSOLUTE(.);
92        KEEP(*(SORT(.init_array.*)))
93        KEEP(*(.init_array))
94        __init_array_end = ABSOLUTE(.);
95
96        . = ALIGN(4);
97        __fini_array_start = ABSOLUTE(.);
98        KEEP(*(SORT(.fini_array.*)))
99        KEEP(*(.fini_array))
100        __fini_array_end = ABSOLUTE(.);
101        LONG(0) /* size in 32-bit words, to add to bss section for dynamic destructor registration */
102
103        . = ALIGN(4);
104        __got_start = ABSOLUTE(.);
105        *(.got) *(.got.*) ;
106        __got_end = ABSOLUTE(.);
107
108    } > ram AT > flash
109
110    .relocs : {
111        . = ALIGN(4);
112        /* relocs */
113        __rel_start = ABSOLUTE(.);
114        *(.rel) *(.rel.*) *(.rel.data.rel.local)
115        __rel_end = ABSOLUTE(.);
116        . = ALIGN(4);
117
118    } > flash = 0xff
119
120    .dynsym : {
121        *(.dynsym); *(.dynsym.*);
122    } > flash = 0xff
123
124    .bss : {
125        . = ALIGN(4);
126        __bss_start = ABSOLUTE(.);
127        *(.bss) *(.bss.*) *(COMMON);
128        . = ALIGN(4);
129        __bss_end = ABSOLUTE(.);
130    } > ram
131
132    __data_data = LOADADDR(.data);
133
134    .dynstr : {
135        *(.dynstr); *(.dynstr.*);
136    } > trash
137    .hash : {
138        *(.hash); *(.hash.*);
139    } > trash
140    .dynamic : {
141        *(.dynamic); *(.dynamic.*);
142    } > trash
143}
144