Skip to content

Commit 3de7ca3

Browse files
authored
Add ram_image boolean to mz.Target and expose via microzig.config (#544)
1 parent c7434ee commit 3de7ca3

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

build-internals/build.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ pub const Target = struct {
4343
/// This should always be true except for platforms where compiler_rt cannot be built right now.
4444
bundle_compiler_rt: bool = true,
4545

46+
/// Determines whether the artifact produced for this target will exist solely in RAM. This will
47+
/// inform whether we need to do any special handling e.g. of vector tables and whether we need
48+
/// to explicitly copy .data and clear out .bss
49+
ram_image: bool = false,
50+
4651
/// (optional) Provides a default hardware abstraction layer that is used.
4752
/// If `null`, no `microzig.hal` will be available.
4853
hal: ?HardwareAbstractionLayer = null,
@@ -71,6 +76,7 @@ pub const Target = struct {
7176
chip: ?Chip = null,
7277
single_threaded: ?bool = null,
7378
bundle_compiler_rt: ?bool = null,
79+
ram_image: ?bool = null,
7480
hal: ?HardwareAbstractionLayer = null,
7581
board: ?Board = null,
7682
linker_script: ?LazyPath = null,
@@ -89,6 +95,7 @@ pub const Target = struct {
8995
.chip = options.chip orelse from.chip,
9096
.single_threaded = options.single_threaded orelse from.single_threaded,
9197
.bundle_compiler_rt = options.bundle_compiler_rt orelse from.bundle_compiler_rt,
98+
.ram_image = options.ram_image orelse from.ram_image,
9299
.hal = options.hal orelse from.hal,
93100
.board = options.board orelse from.board,
94101
.linker_script = options.linker_script orelse from.linker_script,

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ pub fn MicroBuild(port_select: PortSelect) type {
393393
config.addOption([]const u8, "chip_name", target.chip.name);
394394
config.addOption(?[]const u8, "board_name", if (maybe_board) |board| board.name else null);
395395
config.addOption(usize, "end_of_stack", first_ram.offset + first_ram.length);
396+
config.addOption(bool, "ram_image", target.ram_image);
396397

397398
const core_mod = b.createModule(.{
398399
.root_source_file = mb.core_dep.path("src/microzig.zig"),

core/src/cpus/cortex_m.zig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,7 @@ pub const startup_logic = struct {
675675
};
676676

677677
fn is_ramimage() bool {
678-
// HACK
679-
// TODO: Use microzig_options?
680-
if (microzig.config.board_name) |board_name|
681-
return std.mem.containsAtLeast(u8, board_name, 1, "ram image");
682-
return false;
678+
return microzig.config.ram_image;
683679
}
684680

685681
pub fn export_startup_logic() void {

port/raspberrypi/rp2xxx/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
167167
.pico_flashless = chip_rp2040.derive(.{
168168
.entry = .{ .symbol_name = "_entry_point" },
169169
.linker_script = b.path("rp2040_ram_image.ld"),
170+
.ram_image = true,
170171
.board = .{
171172
.name = "RaspberryPi Pico (ram image)",
172173
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico/",

0 commit comments

Comments
 (0)