Andrew Walbran | 15068b0 | 2022-03-22 15:57:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | * https://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 | MEMORY |
| 18 | { |
| 19 | dtb_region : ORIGIN = 0x80000000, LENGTH = 2M |
| 20 | image : ORIGIN = 0x80200000, LENGTH = 2M |
Andrew Walbran | a0ecabd | 2022-04-11 14:26:18 +0000 | [diff] [blame] | 21 | writable_data : ORIGIN = 0x80400000, LENGTH = 2M |
Andrew Walbran | 15068b0 | 2022-03-22 15:57:34 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /* |
| 25 | * Code will start running at this symbol which is placed at the start of the |
| 26 | * image. |
| 27 | */ |
| 28 | ENTRY(entry) |
| 29 | |
| 30 | /* |
| 31 | * The following would be useful to check that .init code is not called back |
| 32 | * into once it has completed but it isn't supported by ld.lld. |
| 33 | * |
| 34 | * NOCROSSREFS_TO(.init .text) |
| 35 | */ |
| 36 | |
| 37 | SECTIONS |
| 38 | { |
| 39 | .dtb (NOLOAD) : { |
| 40 | dtb_begin = .; |
| 41 | . += LENGTH(dtb_region); |
| 42 | dtb_end = .; |
| 43 | } >dtb_region |
| 44 | |
| 45 | /* |
| 46 | * Collect together the code. This is page aligned so it can be mapped |
| 47 | * as executable-only. |
| 48 | */ |
| 49 | .init : ALIGN(4096) { |
| 50 | text_begin = .; |
| 51 | *(.init.entry) |
| 52 | *(.init.*) |
| 53 | } >image |
| 54 | .text : { |
| 55 | *(.text.*) |
| 56 | } >image |
| 57 | text_end = .; |
| 58 | |
| 59 | /* |
| 60 | * Collect together read-only data. This is page aligned so it can be |
| 61 | * mapped as read-only and non-executable. |
| 62 | */ |
| 63 | .rodata : ALIGN(4096) { |
| 64 | rodata_begin = .; |
| 65 | *(.rodata.*) |
| 66 | } >image |
| 67 | .got : { |
| 68 | *(.got) |
| 69 | } >image |
| 70 | rodata_end = .; |
| 71 | |
| 72 | /* |
| 73 | * Collect together the read-write data including .bss at the end which |
| 74 | * will be zero'd by the entry code. This is page aligned so it can be |
| 75 | * mapped as non-executable. |
| 76 | */ |
| 77 | .data : ALIGN(4096) { |
| 78 | data_begin = .; |
| 79 | *(.data.*) |
| 80 | /* |
| 81 | * The entry point code assumes that .data is a multiple of 32 |
| 82 | * bytes long. |
| 83 | */ |
| 84 | . = ALIGN(32); |
| 85 | data_end = .; |
Andrew Walbran | a0ecabd | 2022-04-11 14:26:18 +0000 | [diff] [blame] | 86 | } >writable_data AT>image |
| 87 | data_lma = LOADADDR(.data); |
| 88 | |
Andrew Walbran | 15068b0 | 2022-03-22 15:57:34 +0000 | [diff] [blame] | 89 | /* Everything beyond this point will not be included in the binary. */ |
| 90 | bin_end = .; |
| 91 | |
| 92 | /* The entry point code assumes that .bss is 16-byte aligned. */ |
| 93 | .bss : ALIGN(16) { |
| 94 | bss_begin = .; |
| 95 | *(.bss.*) |
| 96 | *(COMMON) |
| 97 | . = ALIGN(16); |
| 98 | bss_end = .; |
Andrew Walbran | a0ecabd | 2022-04-11 14:26:18 +0000 | [diff] [blame] | 99 | } >writable_data |
Andrew Walbran | 15068b0 | 2022-03-22 15:57:34 +0000 | [diff] [blame] | 100 | |
| 101 | .stack (NOLOAD) : ALIGN(4096) { |
| 102 | boot_stack_begin = .; |
| 103 | . += 40 * 4096; |
| 104 | . = ALIGN(4096); |
| 105 | boot_stack_end = .; |
Andrew Walbran | a0ecabd | 2022-04-11 14:26:18 +0000 | [diff] [blame] | 106 | } >writable_data |
Andrew Walbran | 15068b0 | 2022-03-22 15:57:34 +0000 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Remove unused sections from the image. |
| 110 | */ |
| 111 | /DISCARD/ : { |
| 112 | /* The image loads itself so doesn't need these sections. */ |
| 113 | *(.gnu.hash) |
| 114 | *(.hash) |
| 115 | *(.interp) |
| 116 | *(.eh_frame_hdr) |
| 117 | *(.eh_frame) |
| 118 | *(.note.gnu.build-id) |
| 119 | } |
| 120 | } |