Generate a platform-specific linker script. Args: map_file (Path): Path to the map file. platform (str): Target platform. Returns: Path: Path to the generated linker script.
(map_file: Path, platform: str)
| 146 | |
| 147 | |
| 148 | def _generate_platform_linker_script(map_file: Path, platform: str) -> Path: |
| 149 | """ |
| 150 | Generate a platform-specific linker script. |
| 151 | |
| 152 | Args: |
| 153 | map_file (Path): Path to the map file. |
| 154 | platform (str): Target platform. |
| 155 | |
| 156 | Returns: |
| 157 | Path: Path to the generated linker script. |
| 158 | """ |
| 159 | print(f"Generating {platform} linker script...") |
| 160 | |
| 161 | if platform == "esp32": |
| 162 | # ESP32 memory layout |
| 163 | linker_script_content = """ |
| 164 | MEMORY |
| 165 | { |
| 166 | iram0_0_seg : org = 0x40080000, len = 0x20000 |
| 167 | dram0_0_seg : org = 0x3FFB0000, len = 0x50000 |
| 168 | flash_seg : org = 0x400D0020, len = 0x330000 |
| 169 | } |
| 170 | |
| 171 | SECTIONS |
| 172 | { |
| 173 | .iram0.text : { |
| 174 | *(.iram0.literal .iram0.text) |
| 175 | } > iram0_0_seg |
| 176 | |
| 177 | .flash.text : { |
| 178 | *(.literal .text .literal.* .text.*) |
| 179 | } > flash_seg |
| 180 | |
| 181 | .flash.rodata : { |
| 182 | *(.rodata .rodata.*) |
| 183 | } > flash_seg |
| 184 | |
| 185 | .dram0.data : { |
| 186 | *(.data .data.*) |
| 187 | } > dram0_0_seg |
| 188 | |
| 189 | .dram0.bss : { |
| 190 | *(.bss .bss.*) |
| 191 | } > dram0_0_seg |
| 192 | } |
| 193 | """ |
| 194 | elif platform == "avr": |
| 195 | # AVR memory layout |
| 196 | linker_script_content = """ |
| 197 | MEMORY |
| 198 | { |
| 199 | text (rx) : ORIGIN = 0x0000, LENGTH = 0x8000 |
| 200 | data (rw!x) : ORIGIN = 0x800100, LENGTH = 0x800 |
| 201 | eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x400 |
| 202 | } |
| 203 | |
| 204 | SECTIONS |
| 205 | { |