Support Lenovo EasyStartup

This commit is contained in:
longpanda 2021-08-23 16:56:17 +08:00
parent 112c557428
commit 05e208ea2a
8 changed files with 194 additions and 0 deletions

View file

@ -4970,6 +4970,7 @@ static cmd_para ventoy_cmds[] =
{ "vt_push_pager", ventoy_cmd_push_pager, 0, NULL, "", "", NULL },
{ "vt_pop_pager", ventoy_cmd_pop_pager, 0, NULL, "", "", NULL },
{ "vt_check_json_path_case", ventoy_cmd_chk_json_pathcase, 0, NULL, "", "", NULL },
{ "vt_append_extra_sector", ventoy_cmd_append_ext_sector, 0, NULL, "", "", NULL },
};
int ventoy_register_all_cmd(void)

View file

@ -568,6 +568,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);

View file

@ -38,6 +38,9 @@
GRUB_MOD_LICENSE ("GPLv3+");
#define VTOY_APPEND_EXT_SIZE 4096
static int g_append_ext_sector = 0;
char * ventoy_get_line(char *start)
{
if (start == NULL)
@ -658,6 +661,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
count++;
}
if (g_append_ext_sector > 0)
{
count++;
}
return count;
}
@ -671,6 +679,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
{
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align;
}
if (g_append_ext_sector > 0)
{
size += sizeof(ventoy_virt_chunk) + VTOY_APPEND_EXT_SIZE;
}
return size;
}
@ -727,6 +740,27 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
cur++;
}
/* Lenovo EasyStartup need an addional sector for boundary check */
if (g_append_ext_sector > 0)
{
cpio_secs = VTOY_APPEND_EXT_SIZE / 2048;
cur->mem_sector_start = sector;
cur->mem_sector_end = cur->mem_sector_start + cpio_secs;
cur->mem_sector_offset = offset;
cur->remap_sector_start = 0;
cur->remap_sector_end = 0;
cur->org_sector_start = 0;
grub_memset(override + offset, 0, VTOY_APPEND_EXT_SIZE);
chain->virt_img_size_in_bytes += VTOY_APPEND_EXT_SIZE;
offset += VTOY_APPEND_EXT_SIZE;
sector += cpio_secs;
cur++;
}
if (g_conf_replace_offset > 0)
{
cpio_secs = g_conf_replace_new_len_align / 2048;
@ -1119,6 +1153,24 @@ grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (args[0][0] == '1')
{
g_append_ext_sector = 1;
}
else
{
g_append_ext_sector = 0;
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;