|
| 1 | +/// Documentation taken from section 5.9.5.1 of the rp2350 datasheet. |
| 2 | +const std = @import("std"); |
| 3 | +const root = @import("root"); |
| 4 | +const microzig = @import("microzig"); |
| 5 | +const arch = @import("compatibility.zig").arch; |
| 6 | + |
| 7 | +pub const image_def_block: Block(extern struct { |
| 8 | + image_def: ImageDef, |
| 9 | + entry_point: EntryPoint(false), |
| 10 | +}) = .{ |
| 11 | + .items = .{ |
| 12 | + .image_def = .{ |
| 13 | + .image_type_flags = .{ |
| 14 | + .image_type = .exe, |
| 15 | + .exe_security = root.microzig_options.hal.image_def_exe_security, |
| 16 | + .cpu = std.meta.stringToEnum(ImageDef.ImageTypeFlags.Cpu, @tagName(arch)).?, |
| 17 | + .chip = .RP2350, |
| 18 | + .try_before_you_buy = false, |
| 19 | + }, |
| 20 | + }, |
| 21 | + .entry_point = .{ |
| 22 | + .entry = if (microzig.config.ram_image and arch == .arm) |
| 23 | + µzig.cpu.startup_logic.ram_image_entrypoint |
| 24 | + else |
| 25 | + µzig.cpu.startup_logic._start, |
| 26 | + .sp = microzig.config.end_of_stack, |
| 27 | + }, |
| 28 | + }, |
| 29 | + .link = root.microzig_options.hal.next_metadata_block, |
| 30 | +}; |
| 31 | + |
| 32 | +comptime { |
| 33 | + @export(&image_def_block, .{ |
| 34 | + .name = "_image_def_block", |
| 35 | + .section = ".bootmeta", |
| 36 | + .linkage = .strong, |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +pub fn Block(Items: type) type { |
| 41 | + return extern struct { |
| 42 | + header: u32 = 0xffffded3, |
| 43 | + items: Items, |
| 44 | + last_item: u32 = 0x000000ff | ((@sizeOf(Items) / 4) << 8), |
| 45 | + link: ?*const anyopaque = null, |
| 46 | + footer: u32 = 0xab123579, |
| 47 | + }; |
| 48 | +} |
| 49 | + |
| 50 | +pub const ImageDef = packed struct { |
| 51 | + item_type: u8 = 0x42, |
| 52 | + block_size: u8 = 0x01, |
| 53 | + image_type_flags: ImageTypeFlags, |
| 54 | + |
| 55 | + pub const ImageTypeFlags = packed struct { |
| 56 | + image_type: ImageType, |
| 57 | + exe_security: ExeSecurity, |
| 58 | + reserved0: u2 = 0, |
| 59 | + cpu: Cpu, |
| 60 | + reserved1: u1 = 0, |
| 61 | + chip: Chip, |
| 62 | + try_before_you_buy: bool, |
| 63 | + |
| 64 | + pub const ImageType = enum(u4) { |
| 65 | + invalid = 0, |
| 66 | + exe = 1, |
| 67 | + data = 2, |
| 68 | + }; |
| 69 | + |
| 70 | + pub const ExeSecurity = enum(u2) { |
| 71 | + unspecified = 0, |
| 72 | + non_secure = 1, |
| 73 | + secure = 2, |
| 74 | + }; |
| 75 | + |
| 76 | + pub const Cpu = enum(u3) { |
| 77 | + arm = 0, |
| 78 | + riscv = 1, |
| 79 | + }; |
| 80 | + |
| 81 | + pub const Chip = enum(u3) { |
| 82 | + RP2040 = 0, |
| 83 | + RP2350 = 1, |
| 84 | + }; |
| 85 | + }; |
| 86 | +}; |
| 87 | + |
| 88 | +pub fn EntryPoint(with_stack_limit: bool) type { |
| 89 | + if (with_stack_limit) { |
| 90 | + return extern struct { |
| 91 | + header: packed struct { |
| 92 | + item_type: u8 = 0x44, |
| 93 | + block_size: u8 = 0x04, |
| 94 | + padding: u16 = 0, |
| 95 | + } = .{}, |
| 96 | + entry: *const anyopaque, |
| 97 | + sp: u32, |
| 98 | + sp_limit: u32, |
| 99 | + }; |
| 100 | + } else { |
| 101 | + return extern struct { |
| 102 | + header: packed struct { |
| 103 | + item_type: u8 = 0x44, |
| 104 | + block_size: u8 = 0x03, |
| 105 | + padding: u16 = 0, |
| 106 | + } = .{}, |
| 107 | + entry: *const anyopaque, |
| 108 | + sp: u32, |
| 109 | + }; |
| 110 | + } |
| 111 | +} |
0 commit comments