-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use include linker scripts #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 31 commits
b8f699f
6dc06e6
727cabd
3a83dc7
4b1a3ec
ae97a22
3811e67
a20f86a
6bd9e5b
2bf8555
fe2d56b
1bd7089
72adb67
e47fe09
9c0ed0c
e44bdea
dc3a2e8
8b9d9ec
91c3a9a
614f7f0
da23cf4
780c05e
2e7ca67
4180427
c122bf7
ea8320b
ad35ad8
8e3aca5
e9e9a09
519544e
3f0615d
a26a42b
df68b1e
41fd36e
ea9b114
c483e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain") | ||
|
|
||
| def _include_linker_script_dir_impl(ctx): | ||
| link_include_dir = str(ctx.label.package) | ||
| depset_direct = ["-L" + str(link_include_dir)] | ||
| if len(ctx.files.use_scripts): | ||
| for script in ctx.files.use_scripts: | ||
| depset_direct.append("-T" + str(script.path)) | ||
|
|
||
| linking_inputs = cc_common.create_linker_input( | ||
will-v-pi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| owner = ctx.label, | ||
| user_link_flags = depset( | ||
| direct = depset_direct, | ||
| ), | ||
| ) | ||
| return [ | ||
will-v-pi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))), | ||
| ] | ||
|
|
||
| include_linker_script_dir = rule( | ||
| implementation = _include_linker_script_dir_impl, | ||
| attrs = { | ||
| "use_scripts": attr.label_list(allow_files = [".ld"]), | ||
| }, | ||
| toolchains = use_cpp_toolchain(), | ||
| fragments = ["cpp"], | ||
| ) | ||
|
|
||
| def _use_linker_script_file_impl(ctx): | ||
will-v-pi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| link_file = ctx.file.script.path | ||
|
|
||
| linking_inputs = cc_common.create_linker_input( | ||
| owner = ctx.label, | ||
| user_link_flags = depset( | ||
| direct = ["-T" + str(link_file)], | ||
| ), | ||
| ) | ||
| return [ | ||
| CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))), | ||
| ] | ||
|
|
||
| use_linker_script_file = rule( | ||
| implementation = _use_linker_script_file_impl, | ||
| attrs = { | ||
| "script": attr.label(mandatory = True, allow_single_file = [".ld"]), | ||
| }, | ||
| toolchains = use_cpp_toolchain(), | ||
| fragments = ["cpp"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* Use blocked ram */ | ||
| RAM_ORIGIN = 0x21000000; | ||
|
|
||
| INCLUDE "memmap_default.incl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| INCLUDE "memmap_copy_to_ram.incl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| INCLUDE "memmap_default.incl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| INCLUDE "memmap_no_flash.incl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") | ||
|
|
||
| filegroup( | ||
| name = "rp2040_linker_script_incls", | ||
| srcs = glob([ | ||
| "*.incl", | ||
| ]), | ||
| ) | ||
|
|
||
| include_linker_script_dir( | ||
|
||
| name = "rp2040_linker_script_args", | ||
| use_scripts = ["default_locations.ld"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "rp2040_linker_scripts", | ||
| target_compatible_with = ["//bazel/constraint:rp2040"], | ||
| deps = [ | ||
| "default_locations.ld", | ||
| "rp2040_linker_script_args", | ||
| ], | ||
| additional_linker_inputs = [ | ||
| "rp2040_linker_script_incls", | ||
| ], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| RAM_ORIGIN_DEFAULT = 0x20000000; | ||
| RAM_LENGTH_DEFAULT = 256k; | ||
| SCRATCH_X_ORIGIN_DEFAULT = 0x20040000; | ||
| SCRATCH_X_LENGTH_DEFAULT = 4k; | ||
| SCRATCH_Y_ORIGIN_DEFAULT = 0x20041000; | ||
| SCRATCH_Y_LENGTH_DEFAULT = 4k; | ||
| XIP_RAM_ORIGIN_DEFAULT = 0x15000000; | ||
| XIP_RAM_LENGTH_DEFAULT = 16k; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| SECTIONS | ||
| { | ||
| /* Second stage bootloader is prepended to the image. It must be 256 bytes big | ||
| and checksummed. It is usually built by the boot_stage2 target | ||
| in the Raspberry Pi Pico SDK | ||
| */ | ||
|
|
||
| .boot2 : { | ||
| __boot2_start__ = .; | ||
| KEEP (*(.boot2)) | ||
| __boot2_end__ = .; | ||
| } > TEXT_STORE | ||
|
|
||
| ASSERT(__boot2_end__ - __boot2_start__ == 256, | ||
| "ERROR: Pico second stage bootloader must be exactly 256 bytes in size for RP2040") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* Defines the following symbols for use by code: | ||
| __logical_binary_start | ||
| __binary_info_header_end | ||
| __embedded_block_end | ||
| __reset_start, __reset_end | ||
| */ | ||
|
|
||
| SECTIONS | ||
| { | ||
| /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger | ||
| entry (ELF entry point), are *first* in the image, and the vector table | ||
| follows immediately afterward. This is because the bootrom enters RAM | ||
| binaries directly at their lowest address (preferring main RAM over XIP | ||
| cache-as-SRAM if both are used). | ||
| */ | ||
|
|
||
| .text : { | ||
| __logical_binary_start = .; | ||
| __reset_start = .; | ||
| KEEP (*(.reset)) | ||
| __reset_end = .; | ||
| KEEP (*(.binary_info_header)) | ||
| __binary_info_header_end = .; | ||
| KEEP (*(.embedded_block)) | ||
| __embedded_block_end = .; | ||
| . = ALIGN(256); | ||
| KEEP (*(.vectors)) | ||
| *(.text*) | ||
| . = ALIGN(4); | ||
| *(.init) | ||
| *(.fini) | ||
| /* Pull all c'tors into .text */ | ||
| *crtbegin.o(.ctors) | ||
| *crtbegin?.o(.ctors) | ||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) | ||
| *(SORT(.ctors.*)) | ||
| *(.ctors) | ||
| /* Followed by destructors */ | ||
| *crtbegin.o(.dtors) | ||
| *crtbegin?.o(.dtors) | ||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) | ||
| *(SORT(.dtors.*)) | ||
| *(.dtors) | ||
|
|
||
| *(.eh_frame*) | ||
| } > RAM | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SECTIONS | ||
| { | ||
| ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 */ | ||
|
|
||
| INCLUDE "section_flash_begin.incl" | ||
| INCLUDE "section_boot2.incl" | ||
| INCLUDE "section_copy_to_ram_flashtext.incl" | ||
| INCLUDE "section_copy_to_ram_rodata.incl" | ||
| INCLUDE "sections_arm_ex.incl" | ||
| INCLUDE "section_binary_info.incl" | ||
| INCLUDE "section_ram_vector_table.incl" | ||
| INCLUDE "section_uninitialized_data.incl" | ||
| INCLUDE "section_copy_to_ram_text.incl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /* This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 */ | ||
|
|
||
| INCLUDE "section_flash_begin.incl" | ||
| INCLUDE "section_boot2.incl" | ||
| INCLUDE "section_default_text.incl" | ||
| INCLUDE "section_default_rodata.incl" | ||
| INCLUDE "sections_arm_ex.incl" | ||
| INCLUDE "section_binary_info.incl" |
Uh oh!
There was an error while loading. Please reload this page.