Skip to content

Commit

Permalink
. 修正切换分辨率花屏问题。
Browse files Browse the repository at this point in the history
. 增加从入口点启动方法。
. 增加变量menu_tab_ext,避免重入主菜单时重复加载背景图及字库。
     例如:calc *0x8312&2 > nul || splashimage /boot/grub/lt.jpg
        calc *0x8312&4 > nul || font /boot/grub/unifont.hex.gz
  • Loading branch information
yaya2007 committed Sep 22, 2023
1 parent aa78c12 commit 5742764
Show file tree
Hide file tree
Showing 6 changed files with 752 additions and 53 deletions.
7 changes: 7 additions & 0 deletions ChangeLog_UEFI.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
更新说明:
2023-09-22 (yaya)
修正切换分辨率花屏问题。
增加从入口点启动方法。
增加变量menu_tab_ext,避免重入主菜单时重复加载背景图及字库。
例如:calc *0x8312&2 > nul || splashimage /boot/grub/lt.jpg
calc *0x8312&4 > nul || font /boot/grub/unifont.hex.gz

2023-08-18 (yaya)
改进find函数的查找分区顺序为0,1,2....
改进有些UEFI固件返回大写字母无法识别的问题。 issues #423
Expand Down
42 changes: 17 additions & 25 deletions stage2/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,9 @@ efi_open_protocol_wrapper (grub_efi_handle_t handle, grub_efi_guid_t *protocol,
return 0;
}
#endif
static grub_efi_char16_t *cmdline;
static grub_ssize_t cmdline_len;
extern grub_efi_char16_t *cmdline;
extern grub_ssize_t cmdline_len;
extern grub_efi_handle_t dev_handle;

/* chainloader */
static int chainloader_func (char *arg, int flags);
Expand Down Expand Up @@ -1383,18 +1384,6 @@ chainloader_func (char *arg, int flags)
//虚拟盘类型
if (! *filename)
{
#if 0
if (current_drive >= 0xa0) //如果是光盘,并且存在“/EFI/BOOT/BOOTX64.EFI(BOOTIA32.EFI)”,则优先加载
{
if (find_specified_file(current_drive, 0, EFI_REMOVABLE_MEDIA_FILE_NAME) == 1) //
{
sprintf (chainloader_file, "(%d)%s\0", current_drive, EFI_REMOVABLE_MEDIA_FILE_NAME);
arg = chainloader_file;
goto file;
}
errnum = 0;
}
#endif
part_data = 0;
if (current_partition == 0xFFFFFF) //如果没有指定启动分区
part_data = get_boot_partition (current_drive);
Expand Down Expand Up @@ -1493,12 +1482,7 @@ chainloader_func (char *arg, int flags)
cmdline[len] = 0;
cmdline_len = len * sizeof (grub_efi_char16_t);
}
#if 0
d = get_device_by_drive (current_drive,0);
if (!d)
return (!(errnum = ERR_NO_DISK));
dp = grub_efi_get_device_path (d->device_handle);
#else

if (current_partition == 0xFFFFFF)
{
d = get_device_by_drive (current_drive,0);
Expand All @@ -1515,9 +1499,10 @@ chainloader_func (char *arg, int flags)
dp = grub_efi_get_device_path (part_data->part_handle);
temp = part_data->part_handle;
}
#endif

if (debug > 1)
grub_efi_print_device_path(dp);
dev_handle = temp;
image_handle = grub_load_image (dp, arg1, boot_image);
if (!image_handle)
goto failure_exec_format_0;
Expand Down Expand Up @@ -3886,7 +3871,7 @@ command_func (char *arg, int flags)
unsigned int psp_len;
unsigned int prog_len;
char *program;
char *tmp;
char *tmp, *tmp0;
prog_len = filemax; //程序(文件)尺寸
psp_len = ((arg_len + strlen(file_path)+ 16) & ~0xF) + 0x10 + 0x20; //psp尺寸
// tmp = (char *)grub_malloc(prog_len + 4096 + 16 + psp_len + 512); //缓存
Expand Down Expand Up @@ -3932,7 +3917,12 @@ command_func (char *arg, int flags)
bat_md_start = (grub_size_t)(program + len + 8); //尾续文件起始
bat_md_count = filemax - (len + 8); //尾续文件尺寸
bat_md_count = (bat_md_count + 511) & (-512); //对齐512
char *tmp0 = grub_memalign(512, bat_md_count); //给尾续文件分配新地址
tmp0 = grub_memalign(512, bat_md_count); //给尾续文件分配新地址
if (tmp0 == NULL)
{
grub_free(tmp);
goto fail;
}
grub_memmove64((unsigned long long)(grub_size_t)tmp0,bat_md_start,bat_md_count); //复制(未解压缩)尾续文件到新地址
bat_md_start = (unsigned long long)(grub_size_t)tmp0 >> 9;
bat_md_count >>= 9;
Expand Down Expand Up @@ -4039,6 +4029,7 @@ command_func (char *arg, int flags)
pid = grub_exec_run(program, psp, flags);
/* on exit, release the memory. */
grub_free(tmp);
grub_free(tmp0);
if (!(--prog_pid) && *CMD_RUN_ON_EXIT)//errnum = -1 on exit run.
{
errnum = 0;
Expand Down Expand Up @@ -7420,6 +7411,7 @@ add_part_data (int drive)
// p->partition_size = cd_Image_disk_size;
// p->boot_start = cd_boot_start;
// p->boot_size = cd_boot_size;
p->partition_activity_flag = 0x60 + cd_map_count; //光盘启动镜像的驱动器号
p->partition_boot = 1;
p->next = 0;
if (!partition_info) //使用 'if (!p_final)' 会判断错误。 当 partition_info=bp=0 时,if (!partition_info) 返回1;而 if (!p_final) 返回0。
Expand Down Expand Up @@ -12245,10 +12237,10 @@ graphicsmode_func (char *arg, int flags)
grub_free (IMAGE_BUFFER);
// IMAGE_BUFFER = grub_malloc (current_x_resolution * current_y_resolution * current_bytes_per_pixel);//应当在加载图像前设置
//可能info->pixels_per_scanline >= info->width 2023-03-26
IMAGE_BUFFER = grub_malloc (current_bytes_per_scanline * current_y_resolution);//应当在加载图像前设置
IMAGE_BUFFER = grub_zalloc (current_bytes_per_scanline * current_y_resolution);//应当在加载图像前设置 使用grub_malloc,切换分辨率可能花屏。2023-08-24
if (!JPG_FILE)
{
JPG_FILE = grub_malloc (0x8000);
JPG_FILE = grub_zalloc (0x8000); //使用grub_malloc,切换分辨率可能花屏。2023-08-24
}
if (!UNIFONT_START)
{
Expand Down
12 changes: 12 additions & 0 deletions stage2/char_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,18 @@ grub_strcpy (char *dest, const char *src)
return dest;
}

char *grub_strncpy (char *dest, const char *src, int c);
char *
grub_strncpy (char *dest, const char *src, int c)
{
char *p = dest;

while ((*p++ = *src++) != '\0' && --c)
;

return dest;
}

/* The strtok.c comes from reactos. It follows GPLv2. */

/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
Expand Down
27 changes: 27 additions & 0 deletions stage2/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,33 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
}
}
#endif

grub_efi_status_t grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
grub_efi_uintn_t buffer_size, void **buffer);
grub_efi_status_t
grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
grub_efi_uintn_t buffer_size, void **buffer) //分配池
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;

b = grub_efi_system_table->boot_services;
status = efi_call_3 (b->allocate_pool, pool_type, buffer_size, buffer);
return status;
}

grub_efi_status_t grub_efi_free_pool (void *buffer);
grub_efi_status_t
grub_efi_free_pool (void *buffer) //释放池
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;

b = grub_efi_system_table->boot_services;
status = efi_call_1 (b->free_pool, buffer);
return status;
}

//第一次分配页时,会多分配一页,用于记录分配结构. 似乎每一结构占用0x80字节(实际结构每一这么大).此页不会释放.
//分配页后,紧接分配池.并记录分配结构.
/* Allocate pages. Return the pointer to the first of allocated pages. 分配页面。返回指向第一个分配页面的指针 */
Expand Down
Loading

0 comments on commit 5742764

Please sign in to comment.