Skip to content

Commit bef2b6c

Browse files
committed
fixes and support for riscv
1 parent 05a8232 commit bef2b6c

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

port/raspberrypi/rp2xxx/build.zig

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ boards: struct {
1919
pico2_arm: *const microzig.Target,
2020
pico2_arm_flashless: *const microzig.Target,
2121
pico2_riscv: *const microzig.Target,
22+
pico2_riscv_flashless: *const microzig.Target,
2223
},
2324
waveshare: struct {
2425
rp2040_plus_4m: *const microzig.Target,
@@ -210,17 +211,17 @@ pub fn init(dep: *std.Build.Dependency) Self {
210211
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
211212
},
212213
}),
213-
// .pico2_riscv_flashless = chip_rp2350_riscv.derive(.{
214-
// .ram_image = true,
215-
// .linker_script = .{
216-
// .file = b.path("ld/rp2350/arm_ram_image_sections.ld"),
217-
// },
218-
// .board = .{
219-
// .name = "RaspberryPi Pico 2 (ram image)",
220-
// .url = "https://www.raspberrypi.com/products/raspberry-pi-pico2/",
221-
// .root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
222-
// },
223-
// }),
214+
.pico2_riscv_flashless = chip_rp2350_riscv.derive(.{
215+
.ram_image = true,
216+
.linker_script = .{
217+
.file = b.path("ld/rp2350/riscv_ram_image_sections.ld"),
218+
},
219+
.board = .{
220+
.name = "RaspberryPi Pico 2 (ram image)",
221+
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico2/",
222+
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
223+
},
224+
}),
224225
},
225226
.waveshare = .{
226227
.rp2040_plus_4m = chip_rp2040.derive(.{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SECTIONS {
2+
.bootmeta :
3+
{
4+
__bootmeta_start__ = .;
5+
KEEP(*(.bootmeta))
6+
__bootmeta_end__ = .;
7+
} > ram0
8+
9+
.vectors :
10+
{
11+
KEEP(*(core_vectors))
12+
} > ram0
13+
}
14+
INSERT AFTER .ram_start;
15+
16+
SECTIONS {
17+
.ram_vectors (NOLOAD) :
18+
{
19+
KEEP(*(ram_vectors))
20+
} > ram0
21+
}
22+
INSERT AFTER .bss;
23+

port/raspberrypi/rp2xxx/ld/rp2350/riscv_sections.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SECTIONS {
1515
INSERT AFTER .flash_start;
1616

1717
SECTIONS {
18-
.ram_vectors (NOLOAD) :
18+
.ram_vectors (NOLOAD) :
1919
{
2020
KEEP(*(ram_vectors))
2121
} > ram0

port/raspberrypi/rp2xxx/src/cpus/hazard3.zig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,24 +204,24 @@ pub const startup_logic = struct {
204204
pub export fn _start_c() callconv(.c) noreturn {
205205
if (!microzig.config.ram_image) {
206206
root.initialize_system_memories();
207+
}
207208

208-
// Move vector table to RAM if requested
209-
if (interrupt.has_ram_vectors()) {
210-
if (interrupt.has_ram_vectors_section()) {
211-
@export(&ram_vectors, .{
212-
.name = "_ram_vectors",
213-
.section = "ram_vectors",
214-
.linkage = .strong,
215-
});
216-
} else {
217-
@export(&ram_vectors, .{
218-
.name = "_ram_vectors",
219-
.linkage = .strong,
220-
});
221-
}
222-
223-
@memcpy(&ram_vectors, &startup_logic.external_interrupt_table);
209+
// Move vector table to RAM if requested
210+
if (interrupt.has_ram_vectors()) {
211+
if (interrupt.has_ram_vectors_section()) {
212+
@export(&ram_vectors, .{
213+
.name = "_ram_vectors",
214+
.section = "ram_vectors",
215+
.linkage = .strong,
216+
});
217+
} else {
218+
@export(&ram_vectors, .{
219+
.name = "_ram_vectors",
220+
.linkage = .strong,
221+
});
224222
}
223+
224+
@memcpy(&ram_vectors, &startup_logic.external_interrupt_table);
225225
}
226226

227227
microzig_main();
@@ -321,7 +321,7 @@ pub fn export_startup_logic() void {
321321

322322
@export(&startup_logic.external_interrupt_table, .{
323323
.name = "_external_interrupt_table",
324-
.section = if (!microzig.config.ram_image) "flash_vectors" else ".data",
324+
.section = if (!microzig.config.ram_image) "flash_vectors" else null,
325325
.linkage = .strong,
326326
});
327327
}

tools/generate_linker_script.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn main() !void {
218218
\\ microzig_data_end = .;
219219
\\ }} > {s}
220220
\\
221-
\\ .bss (NOLOAD) :
221+
\\ .bss {s}:
222222
\\ {{
223223
\\ microzig_bss_start = .;
224224
\\ *(.sbss*)
@@ -227,10 +227,11 @@ pub fn main() !void {
227227
\\ }} > {s}
228228
\\
229229
, .{
230-
if (parsed_args.ram_image)
231-
ram_region_name
230+
if (!parsed_args.ram_image)
231+
try std.fmt.allocPrint(allocator, "{s} AT> {s}", .{ ram_region_name, flash_region_name })
232232
else
233-
try std.fmt.allocPrint(allocator, "{s} AT> {s}", .{ ram_region_name, flash_region_name }),
233+
ram_region_name,
234+
if (!parsed_args.ram_image) "(NOLOAD) " else "",
234235
ram_region_name,
235236
});
236237

0 commit comments

Comments
 (0)