@@ -97,7 +97,7 @@ static int main(char *arg,int flags)
9797 if (! g4e_data )
9898 return 0 ;
9999
100- if (* (unsigned int * )IMG (0x8278 ) < 20250524 )
100+ if (* (unsigned int * )IMG (0x8278 ) < 20250914 )
101101 {
102102 printf ("Please use grub4efi version above 2023-07-14.\n" );
103103 return 0 ;
@@ -209,8 +209,12 @@ static int main(char *arg,int flags)
209209 f ++ ;
210210#endif
211211 //确定wim文件尺寸
212- sprintf (tmp ,"cat --length=0 (tftp)%s" ,f ); //确定wim文件尺寸
213- run_line (tmp ,flags );
212+ // sprintf(tmp,"cat --length=0 (tftp)%s",f); //确定wim文件尺寸
213+ // run_line (tmp,flags);
214+ no_decompression = 1 ; //无减压 执行打开命令,不探测压缩文件,即不产生读行为。
215+ open (filename );
216+ no_decompression = 0 ; //恢复
217+ filesize = filemax ;
214218 printf_debug ("filename=%s, filesize=%x\n" ,filename ,filesize );
215219 //创建(rd)
216220 static efi_system_table_t * st ;
@@ -220,7 +224,6 @@ static int main(char *arg,int flags)
220224 grub_efi_status_t status ;
221225 status = bs -> allocate_pages (EFI_ALLOCATE_ANY_PAGES ,
222226 EFI_RESERVED_MEMORY_TYPE , //保留内存类型 0
223- // (grub_efi_uintn_t)((filesize + 0xc00000)&(-4096ULL)) >> 12, (unsigned long long *)(grub_size_t)&efi_pxe_buf); //调用(分配页面,分配类型->任意页面,存储类型->运行时服务数据(6),分配页,地址)
224227 (grub_efi_uintn_t )((filesize + 0x5d0000 )& (-4096ULL )) >> 12 , (unsigned long long * )(grub_size_t )& efi_pxe_buf ); //调用(分配页面,分配类型->任意页面,存储类型->运行时服务数据(6),分配页,地址)
225228 if (status != EFI_SUCCESS ) //如果失败
226229 {
@@ -229,68 +232,11 @@ static int main(char *arg,int flags)
229232 }
230233
231234 rd_base = efi_pxe_buf ;
232- // rd_size = (filesize + 0xc00000)&(-4096ULL);
233235 rd_size = (filesize + 0x5d0000 )& (-4096ULL );
234- unsigned long long len = filesize ;
235236 memset ((void * )rd_base , 0 , rd_size ); //清零
236237 printf_debug ("rd_base=%x, rd_size=%x\n" ,rd_base ,rd_size );
237- #if 0
238- //格式化(rd)
239- sprintf (tmp ,"(hd-1,0)/fat mkfs /A:4096 mbr (rd)" );
240- run_line (tmp ,flags );
241-
242- //在(rd)创建目录
243- run_line ("find --set-root --devices=h /fat" , flags ); //设置根
244- run_line ("/fat mkdir (rd)/boot" ,flags );
245- run_line ("/fat mkdir (rd)/efi" ,flags );
246- run_line ("/fat mkdir (rd)/efi/boot" ,flags );
247-
248- run_line ("/fat mkdir (rd)/efi/microsoft" ,flags );
249- run_line ("/fat mkdir (rd)/efi/microsoft/boot" ,flags );
250- run_line ("/fat mkdir (rd)/efi/microsoft/boot/fonts" ,flags );
251- run_line ("/fat mkdir (rd)/efi/microsoft/boot/resources" ,flags );
252-
253- //从(hd-1)复制文件到(rd)
254- run_line ("cat --length=0 /bcdnet" ,flags ); //获取文件尺寸
255- run_line ("/fat mkfile size=* (rd)/bcd" ,flags ); //创建文件信息,确定起始簇,分配簇.
256- run_line ("/fat copy /o /bcdnet (rd)/bcd" ,flags ); //复制具体内容
257- args -> bcd = (void * )(rd_base + (ext_data_1 << 9 )); //获得bcd在内存地址
258- args -> bcd_length = filesize ; //获得bcd尺寸
259- printf_debug ("args->bcd=%x, ext_data_1=%x, args->bcd_length=%x\n" ,args -> bcd ,ext_data_1 ,args -> bcd_length );
260-
261- run_line ("cat --length=0 /bootx64.efi" ,flags );
262- run_line ("/fat mkfile size=* (rd)/bootx64.efi" ,flags );
263- run_line ("/fat copy /o /bootx64.efi (rd)/bootx64.efi" ,flags );
264-
265- run_line ("cat --length=0 /boot/boot.sdi" ,flags );
266- run_line ("/fat mkfile size=* (rd)/boot/boot.sdi" ,flags );
267- run_line ("/fat copy /o /boot/boot.sdi (rd)/boot/boot.sdi" ,flags );
268-
269- run_line ("/fat mkfile size=0 (rd)/efi/boot/bootx64.efi" ,flags );
270- run_line ("/fat copy /o /efi/boot/bootx64.efi (rd)/efi/boot/bootx64.efi" ,flags );
271-
272- run_line ("cat --length=0 /efi/microsoft/boot/fonts/wgl4_boot.ttf" ,flags );
273- run_line ("/fat mkfile size=* (rd)/efi/microsoft/boot/fonts/wgl4_boot.ttf" ,flags );
274- run_line ("/fat copy /o /efi/microsoft/boot/fonts/wgl4_boot.ttf (rd)/efi/microsoft/boot/fonts/wgl4_boot.ttf" ,flags );
275-
276- run_line ("cat --length=0 /efi/microsoft/boot/fonts/segoe_slboot.ttf" ,flags );
277- run_line ("/fat mkfile size=* (rd)/efi/microsoft/boot/fonts/segoe_slboot.ttf" ,flags );
278- run_line ("/fat copy /o /efi/microsoft/boot/fonts/segoe_slboot.ttf (rd)/efi/microsoft/boot/fonts/segoe_slboot.ttf" ,flags );
279-
280- run_line ("cat --length=0 /efi/microsoft/boot/fonts/segmono_boot.ttf" ,flags );
281- run_line ("/fat mkfile size=* (rd)/efi/microsoft/boot/fonts/segmono_boot.ttf" ,flags );
282- run_line ("/fat copy /o /efi/microsoft/boot/fonts/segmono_boot.ttf (rd)/efi/microsoft/boot/fonts/segmono_boot.ttf" ,flags );
283-
284- run_line ("cat --length=0 /efi/microsoft/boot/resources/bootres.dll" ,flags );
285- run_line ("/fat mkfile size=* (rd)/efi/microsoft/boot/resources/bootres.dll" ,flags );
286- run_line ("/fat copy /o /efi/microsoft/boot/resources/bootres.dll (rd)/efi/microsoft/boot/resources/bootres.dll" ,flags );
287-
288- sprintf (tmp ,"/fat mkfile size=0x%x (rd)/boot.wim" ,len );
289- run_line (tmp ,flags );
290- bs -> stall (10000 ); //延时10毫秒
291- #endif
292- printf_debug ("ext_data_0=%x\n" ,ext_data_0 << 9 );
293238 //复制hd到rd
239+ printf_debug ("ext_data_0=%x\n" ,ext_data_0 << 9 );
294240 memmove ((void * )rd_base , (const void * )(ext_data_0 << 9 ), 0x5d2200 );
295241 //修改bcd名称
296242 modify_bcd_name ("bcdnet" , rd_base , flags );
@@ -317,12 +263,16 @@ static int main(char *arg,int flags)
317263 saved_drive = 0x21 ;
318264 saved_partition = 0xffffff ;
319265 //读wim文件
320- // efi_pxe_buf = rd_base + (ext_data_1 << 9); //(rd)/boot.wim 地址
321266 efi_pxe_buf = rd_base + BOOTWIM_ADDR ; //(rd)/boot.wim 地址
322267 printf_debug ("efi_pxe_buf=%x\n" ,efi_pxe_buf );
323268
324269 * (char * )IMG (0x8205 ) |= 0x80 ; //如果0x8205位7置1,使用efi_pxe_buf,不要分配内存
325- open (filename ); //读wim文件到efi_pxe_buf
270+ // if (!open (filename)) //读wim文件到efi_pxe_buf
271+ if (!read (efi_pxe_buf ,filesize ,GRUB_READ )) //读wim文件到efi_pxe_buf
272+ {
273+ bs -> free_pages ((unsigned long long )(grub_size_t )& efi_pxe_buf ,(grub_efi_uintn_t )((filesize + 0x5d0000 )& (-4096ULL )) >> 12 );
274+ return 0 ;
275+ }
326276 * (char * )IMG (0x8205 ) &= 0x7f ; //恢复
327277 bs -> stall (50000 ); //延时50毫秒
328278
0 commit comments