@@ -101,31 +101,33 @@ pub fn efi_main() !uefi.Status {
101
101
return e ;
102
102
};
103
103
104
- const fileinfo = try tar .stat (tar_fp .reader (), "boot/vmlinuz" );
105
- try console .printf ("Found kernel: {s}\n " , .{fileinfo .? .filename ()});
106
-
104
+ const link = try tar .stat (tar_fp .reader (), "boot/vmlinuz" );
105
+ try console .printf ("Found kernel symlink: {s}\n " , .{link .? .filename ()});
107
106
try tar_fp .setPosition (0 ).err ();
108
107
108
+ const fileinfo = try tar .stat (tar_fp .reader (), link .? .filename ());
109
+ try console .printf ("Found kernel: {s} with size {}\n " , .{ fileinfo .? .filename (), fileinfo .? .size });
110
+ try tar_fp .setPosition (0 ).err ();
111
+ const size = fileinfo .? .size ;
109
112
var kernel : [* ]align (8 ) u8 = undefined ;
110
- const const_size = 100 * 1000 * 1000 ;
111
- try uefi .system_table .boot_services .? .allocatePool (uefi .efi_pool_memory_type , const_size , & kernel ).err ();
113
+ try uefi .system_table .boot_services .? .allocatePool (uefi .efi_pool_memory_type , size , & kernel ).err ();
112
114
defer uefi .system_table .boot_services .? .freePool (kernel ).err () catch {};
113
- const size = try tar .readFile (tar_fp .reader (), fileinfo .? .filename (), kernel );
115
+ _ = try tar .readFile (tar_fp .reader (), fileinfo .? .filename (), kernel );
114
116
115
117
try console .printf ("Kernel size {}\n " , .{size });
116
118
117
119
var args = try std .mem .concat (
118
120
pool_alloc ,
119
121
u16 ,
120
122
&[_ ][]const u16 {
121
- utf16str ("root=testitest console=ttyS0" ),
123
+ utf16str ("root=/dev/sda console=ttyS0" ),
122
124
&[_ ]u16 {0 },
123
125
},
124
126
);
125
127
defer pool_alloc .free (args );
126
128
127
129
var img : ? uefi.Handle = undefined ;
128
- try boot_services .loadImage (false , uefi .handle , null , kernel , const_size , & img ).err ();
130
+ try boot_services .loadImage (false , uefi .handle , null , kernel , size , & img ).err ();
129
131
130
132
try console .printf ("Loaded image\n " , .{});
131
133
@@ -144,3 +146,36 @@ pub fn efi_main() !uefi.Status {
144
146
145
147
return uefi .Status .Success ;
146
148
}
149
+
150
+ pub fn create_memory_device_path (self : * proto.DevicePath , allocator : Allocator , path : [:0 ]align (1 ) const u16 ) ! * proto.DevicePath {
151
+ var path_size = self .size ();
152
+
153
+ // 2 * (path.len + 1) for the path and its null terminator, which are u16s
154
+ // DevicePath for the extra node before the end
155
+ var buf = try allocator .alloc (u8 , path_size + 2 * (path .len + 1 ) + @sizeOf (proto .DevicePath ));
156
+
157
+ @memcpy (buf [0.. path_size ], @as ([* ]const u8 , @ptrCast (self ))[0.. path_size ]);
158
+
159
+ // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
160
+ // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).
161
+ var new = @as (* uefi .DevicePath .Hardware .MemoryMappedDevicePath , @ptrCast (buf .ptr + path_size - 4 ));
162
+
163
+ new .type = .Hardware ;
164
+ new .subtype = .MemoryMapped ;
165
+ new .length = @sizeOf (uefi .DevicePath .Hardware .MemoryMappedDevicePath ) + 2 * (@as (u16 , @intCast (path .len )) + 1 );
166
+
167
+ // The same as new.getPath(), but not const as we're filling it in.
168
+ var ptr = @as ([* :0 ]align (1 ) u16 , @ptrCast (@as ([* ]u8 , @ptrCast (new )) + @sizeOf (uefi .DevicePath .Hardware .MemoryMappedDevicePath )));
169
+
170
+ for (path , 0.. ) | s , i |
171
+ ptr [i ] = s ;
172
+
173
+ ptr [path .len ] = 0 ;
174
+
175
+ var end = @as (* uefi .DevicePath .End .EndEntireDevicePath , @ptrCast (@as (* proto .DevicePath , @ptrCast (new )).next ().? ));
176
+ end .type = .End ;
177
+ end .subtype = .EndEntire ;
178
+ end .length = @sizeOf (uefi .DevicePath .End .EndEntireDevicePath );
179
+
180
+ return @as (* proto .DevicePath , @ptrCast (buf .ptr ));
181
+ }
0 commit comments