Skip to content

Commit

Permalink
. 配合外部命令进度条。
Browse files Browse the repository at this point in the history
. 改进 iso 启动。
  • Loading branch information
yaya committed Mar 27, 2023
1 parent be40ad1 commit 36f94df
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 28 deletions.
28 changes: 19 additions & 9 deletions stage2/asm.S
Expand Up @@ -293,14 +293,24 @@ VARIABLE(iso_types) //byte

VARIABLE(menu_tab) //0x8311 菜单标签 byte
.byte 0
//位2: 0/1=显示按键帮助/不显示按键帮助 04
//位3: 0/1=侧边对齐/中心对齐 08
//位4: 0/1=高亮项目背景短/满 10
//位5: 0/1=英文/中文 20
//位6: 0/1=左对齐/右对齐 40
//位7: 0/1=打印版本信息/不打印版本信息 80
.byte 0 //未使用
.byte 0 //未使用
/*
位2: 0/1=显示按键帮助/不显示按键帮助 04
位3: 0/1=侧边对齐/中心对齐 08
位4: 0/1=高亮项目背景短/满 10
位5: 0/1=英文/中文 20
位6: 0/1=左对齐/右对齐 40
位7: 0/1=打印版本信息/不打印版本信息 80
*/

VARIABLE(menu_tab_ext) //0x8312 菜单标签 byte
.byte 0
/*
位0: 1=已在图形模式 01
位1: 1=已加载背景图像 02
位2: 1=已加载字库 04
*/

.byte 0 //0x8313 未使用

VARIABLE(errnum) //0x8314 错误号 grub_error_t 64位是8字节?
.long 0
Expand Down Expand Up @@ -625,7 +635,7 @@ VARIABLE(system_functions) //IMG(0x8300)
.extent ABS(EXT_C(builtin_cmd)) //44
.extent ABS(EXT_C(get_datetime)) //45
.extent ABS(EXT_C(find_command)) //46
.extent 0 //47 reserved
.extent 0 //47 reserved g4d是get_mmap_entry
.extent ABS(EXT_C(grub_memalign)) //48 void *
.extent ABS(EXT_C(grub_zalloc)) //49 void *
.extent ABS(EXT_C(grub_malloc)) //50 void *
Expand Down
18 changes: 13 additions & 5 deletions stage2/builtins.c
Expand Up @@ -148,7 +148,7 @@ unsigned long long initrd_start_sector;
grub_efi_uint64_t part_addr;
grub_efi_uint64_t part_size;
grub_efi_uint32_t cd_boot_entry;
grub_efi_uint16_t cd_boot_start;
grub_efi_uint32_t cd_boot_start;
grub_efi_uint32_t cd_boot_size;
grub_efi_uint32_t cd_Image_part_start;
grub_efi_uint32_t cd_Image_disk_size;
Expand Down Expand Up @@ -1911,9 +1911,9 @@ configfile_func (char *arg, int flags)
return sprintf(CMD_RUN_ON_EXIT,"\xEC configfile %.128s",arg);
}
char *new_config = config_file;
#if 0
if (*arg == 0 && *config_file)
{
#if 0
if (pxe_restart_config == 0)
{
if (configfile_in_menu_init == 0)
Expand All @@ -1925,10 +1925,8 @@ configfile_func (char *arg, int flags)
saved_partition = install_partition;
*saved_dir = 0; /* clear saved_dir */
arg = config_file;
#else
return 1;
#endif
}
#endif
if (grub_strlen(saved_dir) + grub_strlen(arg) + 20 >= (int)sizeof(chainloader_file_orig))
return ! (errnum = ERR_WONT_FIT);

Expand Down Expand Up @@ -2851,6 +2849,7 @@ splashimage_func(char *arg, int flags)
}
fontx = backup_x;
fonty = backup_y;
menu_tab_ext |= 2;
return 1;
}

Expand Down Expand Up @@ -4728,6 +4727,9 @@ font_func (char *arg, int flags)
}
}
grub_close();
if (! valid_lines) // if no valid lines,
return valid_lines;
menu_tab_ext |= 4;
//old_narrow_char_indicator = narrow_indicator;
//#undef old_narrow_char_indicator

Expand Down Expand Up @@ -11820,6 +11822,7 @@ graphicsmode_func (char *arg, int flags)
//进入图形模式,加载袖珍字库,防止黑屏。这样也可以使防止加载精简中文字库(不包含英文字符)的问题。
grub_memmove ((char *)0x10000, mini_font_lzma, 820);
font_func ("(md)0x80+2", 1); //如果是gz压缩格式,要明确压缩文件尺寸,如:font_func ("(md)0x80+2,820", 1);
menu_tab_ext &= 0xfb;
}
}

Expand All @@ -11843,6 +11846,10 @@ graphicsmode_func (char *arg, int flags)
} //else if (safe_parse_maxint (&arg, &tmp_graphicsmode))
#endif
ok:
if (graphics_mode > 0xFF)
menu_tab_ext |= 1;
else
menu_tab_ext &= 0xfe;
return graphics_mode;
bad_arg:
errnum = ERR_BAD_ARGUMENT;
Expand Down Expand Up @@ -12959,6 +12966,7 @@ setmenu_func(char *arg, int flags)
else if (grub_memcmp (arg, "--u", 3) == 0)
{
menu_tab = 0;
menu_tab_ext = 0;
num_string = 0;
DateTime_enable = 0;
menu_font_spacing = 0;
Expand Down
2 changes: 2 additions & 0 deletions stage2/console.c
Expand Up @@ -359,6 +359,8 @@ grub_console_getkey (int flags) //控制台获得键 控制台终端输入->
DateTime_refresh();
if (ext_timer)
(*ext_timer)(0,-1);
if (timeout_enable)
timeout_refresh();

if (!key)
{
Expand Down
4 changes: 3 additions & 1 deletion stage2/disk_io.c
Expand Up @@ -3879,7 +3879,7 @@ vdisk_install (int drive, int partition) //安装虚拟磁盘(驱动器号)
grub_efi_handle_t *handles; //句柄集 api返回
grub_efi_handle_t *handle; //句柄
grub_efi_uintn_t count0 = 0, count1 = 0;
struct grub_part_data *p;
struct grub_part_data *p = 0;
struct grub_disk_data *d = get_device_by_drive(drive,0); //由驱动器号获得设备
grub_efi_guid_t dp_guid = GRUB_EFI_DEVICE_PATH_GUID; //设备路径GUID
grub_efi_guid_t blk_io_guid = GRUB_EFI_BLOCK_IO_GUID; //块IO_GUID
Expand Down Expand Up @@ -4030,6 +4030,8 @@ vdisk_install (int drive, int partition) //安装虚拟磁盘(驱动器号)
}
}

if (!p->part_handle)
return (errnum = 0x1234); //设置错误号>=MAX_ERR_NUM,不打印err_list[errnum],错误信息由相应程序处理。设置错误号,可以避免死机。 2023-03-15
return GRUB_EFI_SUCCESS;
}

Expand Down
13 changes: 8 additions & 5 deletions stage2/graphics.c
Expand Up @@ -1925,11 +1925,11 @@ void rectangle(int left, int top, int length, int width, int line)
y = 0;
z = current_bytes_per_pixel;
lfb = (unsigned char *)(grub_size_t)(current_phys_base + top * current_bytes_per_scanline + left * z);
source = current_color_64bit & 0xffffffff;

if (!length)
goto vert;

source = current_color_64bit & 0xffffffff;
for (i=0;i<line;++i)
{
p = lfb + current_bytes_per_scanline*i;
Expand Down Expand Up @@ -1969,17 +1969,20 @@ void rectangle(int left, int top, int length, int width, int line)
p = lfb + z * i;
for (x=(length ? (line*2) : 0);x<width;++x)
{
if (clear && (splashimage_loaded & 2)) //清除操作,并且加载了背景图像。否则采用当前32位颜色。
source = *(unsigned int *)(p - (unsigned char *)(grub_size_t)current_phys_base + (unsigned char *)SPLASH_IMAGE);

if (z == 3)
{
*(unsigned short *)(p+y) = *(unsigned short *)p = (unsigned short)current_color_64bit;
*(p+y+2) = *(p+2) = (unsigned char)(current_color_64bit>>16);
*(unsigned short *)(p+y) = *(unsigned short *)p = (unsigned short)source;
*(p+y+2) = *(p+2) = (unsigned char)(source>>16);
}
else if(z == 4)
{
*(unsigned int *)(p+y) = *(unsigned int *)p = (unsigned int)current_color_64bit;
*(unsigned int *)(p+y) = *(unsigned int *)p = (unsigned int)source;
}
else
*(unsigned short *)(p+y) = *(unsigned short *)p = (unsigned short)pixel_shift((unsigned int)current_color_64bit);
*(unsigned short *)(p+y) = *(unsigned short *)p = (unsigned short)pixel_shift((unsigned int)source);
p += current_bytes_per_scanline;
}
}
Expand Down
5 changes: 4 additions & 1 deletion stage2/shared.h
Expand Up @@ -1359,6 +1359,7 @@ extern int quit_print;
extern struct linux_kernel_header *linux_header;

extern unsigned char menu_tab;
extern unsigned char menu_tab_ext;
extern unsigned char num_string;
extern unsigned char menu_font_spacing;
extern unsigned char menu_line_spacing;
Expand Down Expand Up @@ -1882,6 +1883,8 @@ extern int show_menu;
extern int silent_hiddenmenu;
extern char *mbr;
extern int grub_timeout;
extern unsigned char timeout_enable;
extern void timeout_refresh(void);

extern char *wee_skip_to (char *cmdline, int flags);
extern char *skip_to (int flags, char *cmdline);
Expand Down Expand Up @@ -5818,7 +5821,7 @@ typedef struct grub_packed_guid grub_packed_guid_t;

extern grub_packed_guid_t VDISK_GUID;
extern grub_efi_uint32_t cd_boot_entry;
extern grub_efi_uint16_t cd_boot_start;
extern grub_efi_uint32_t cd_boot_start;
extern grub_efi_uint32_t cd_boot_size;
extern grub_efi_uint32_t cd_Image_part_start;
extern grub_efi_uint32_t cd_Image_disk_size;
Expand Down
44 changes: 37 additions & 7 deletions stage2/stage2.c
Expand Up @@ -819,6 +819,7 @@ clear_delay_display (int entryno)
current_term->setcolorstate (COLOR_STATE_HELPTEXT);

grub_timeout = -1;
timeout_enable = 0;
fallback_entryno = -1;
if (! (current_term->flags & TERM_DUMB))
gotoxy (MENU_BOX_E, MENU_BOX_Y + entryno);
Expand All @@ -830,16 +831,29 @@ int new_menu;
int new_hotkey;
int color_counting;
int password_x;
unsigned char timeout_enable = 0;
int time0 = 0, time1 = 0;
static int fallbacked_entries;
static int old_c;
static int old_c_count;
static int old_c_count_end;

void timeout_refresh(void);
void timeout_refresh(void)
{
time0++;
if (time0 == 1000)
{
time0 = 0;
time1++;
}
}

static void run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *heap, int entryno);
static void
run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *heap, int entryno)
{
int i, time1, time2 = -1, first_entry = 0;
int i, /*time1,*/ time2 = -1, first_entry = 0;
unsigned short c;
char *cur_entry = 0;
char *pass_config = 0;
Expand Down Expand Up @@ -885,8 +899,10 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
if (! show_menu)
{
/* Get current time. */
while ((time1 = getrtsecs ()) == 0xFF)
;
// while ((time1 = getrtsecs ()) == 0xFF)
// ;
if (grub_timeout >= 0)
timeout_enable = 1;

while (1)
{
Expand Down Expand Up @@ -916,18 +932,20 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
}
}
grub_timeout = -1;
timeout_enable = 0;
show_menu = 1;
break;
}

/* If GRUB_TIMEOUT is expired, boot the default entry. */
if (grub_timeout >=0
&& (time1 = getrtsecs ()) != time2
// && (time1 = getrtsecs ()) != time2
&& time1 != time2
/* && time1 != 0xFF */)
{
if (grub_timeout <= 0)
{
grub_timeout = -1;
// grub_timeout = -1;
goto boot_entry;
}

Expand Down Expand Up @@ -1093,7 +1111,9 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
if (menu_init_script_file[0] != 0 )
command_func(menu_init_script_file,BUILTIN_MENU);
/* XX using RT clock now, need to initialize value */
while ((time1 = getrtsecs()) == 0xFF);
// while ((time1 = getrtsecs()) == 0xFF);
if (grub_timeout >= 0)
timeout_enable = 1;

old_c = 0;
old_c_count = 0;
Expand All @@ -1105,11 +1125,13 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
while (1)
{
/* Initialize to NULL just in case... */
if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 /* && time1 != 0xFF */)
// if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 /* && time1 != 0xFF */)
if (grub_timeout >= 0 && time1 != time2 /* && time1 != 0xFF */)
{
if (grub_timeout <= 0)
{
grub_timeout = -1;
timeout_enable = 0;
break;
}

Expand Down Expand Up @@ -1715,6 +1737,13 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h

/* Attempt to boot an entry. */
boot_entry:
grub_timeout = -1;
timeout_enable = 0;
if (ext_timer)
{
grub_free (ext_timer);
ext_timer = 0;
}
setcursor (1); /* show cursor and disable splashimage */
animated_enable_backup = animated_enable;
animated_enable = 0;
Expand Down Expand Up @@ -1901,6 +1930,7 @@ reset (void)
fallback_entryno = -1;
fallback_entries[0] = -1;
grub_timeout = -1;
timeout_enable = 0;
menu_num_ctrl[0] = 0;
}

Expand Down

0 comments on commit 36f94df

Please sign in to comment.