mirror of
https://github.com/ventoy/Ventoy.git
synced 2026-07-24 10:48:12 +00:00
Fix the boot issue for latest GhostBSD (#3664)
This commit is contained in:
@@ -525,42 +525,18 @@ grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, cha
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
static int ventoy_freebsd_ver_elf(int bit64, grub_elf_t elf, const char *section, const char *env, char *data)
|
||||
{
|
||||
int j;
|
||||
int k;
|
||||
grub_elf_t elf = NULL;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int ret = 1;
|
||||
char *str = NULL;
|
||||
void *hdr = NULL;
|
||||
grub_off_t offset = 0;
|
||||
grub_uint32_t len = 0;
|
||||
char *str = NULL;
|
||||
char *data = NULL;
|
||||
void *hdr = NULL;
|
||||
char ver[64] = {0};
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
debug("Invalid argc %d\n", argc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
data = grub_zalloc(8192);
|
||||
if (!data)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
elf = grub_elf_open(args[0], GRUB_FILE_TYPE_LINUX_INITRD);
|
||||
if (!elf)
|
||||
{
|
||||
debug("Failed to open file %s\n", args[0]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (args[1][0] == '6')
|
||||
if (bit64)
|
||||
{
|
||||
Elf64_Ehdr *e = &(elf->ehdr.ehdr64);
|
||||
Elf64_Shdr *h;
|
||||
@@ -592,11 +568,11 @@ grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc,
|
||||
|
||||
for (t = h, i = 0; i < e->e_shnum; i++)
|
||||
{
|
||||
if (grub_strcmp(str + t->sh_name, ".data") == 0)
|
||||
if (grub_strcmp(str + t->sh_name, section) == 0)
|
||||
{
|
||||
offset = t->sh_offset;
|
||||
len = t->sh_size;
|
||||
debug("find .data section at %u %u\n", (grub_uint32_t)offset, len);
|
||||
debug("find %s section at %u %u\n", section, (grub_uint32_t)offset, len);
|
||||
break;
|
||||
}
|
||||
t = (Elf64_Shdr *)((char *)t + e->e_shentsize);
|
||||
@@ -634,11 +610,11 @@ grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc,
|
||||
|
||||
for (t = h, i = 0; i < e->e_shnum; i++)
|
||||
{
|
||||
if (grub_strcmp(str + t->sh_name, ".data") == 0)
|
||||
if (grub_strcmp(str + t->sh_name, section) == 0)
|
||||
{
|
||||
offset = t->sh_offset;
|
||||
len = t->sh_size;
|
||||
debug("find .data section at %u %u\n", (grub_uint32_t)offset, len);
|
||||
debug("find %s section at %u %u\n", section, (grub_uint32_t)offset, len);
|
||||
break;
|
||||
}
|
||||
t = (Elf32_Shdr *)((char *)t + e->e_shentsize);
|
||||
@@ -647,7 +623,7 @@ grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc,
|
||||
|
||||
if (offset == 0 || len == 0)
|
||||
{
|
||||
debug(".data section not found %s\n", args[0]);
|
||||
debug("%s section not found\n", section);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -672,21 +648,64 @@ grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ver[0])
|
||||
{
|
||||
k = (int)grub_strtoul(ver, NULL, 10);
|
||||
debug("freebsd version:<%s> <%d.x>\n", ver, k);
|
||||
debug("%s freebsd version:<%s> <%d.x>\n", section, ver, k);
|
||||
grub_snprintf(ver, sizeof(ver), "%d.x", k);
|
||||
ventoy_set_env(args[2], ver);
|
||||
ventoy_set_env(env, ver);
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("freebsd version:<%s>\n", "NOT FOUND");
|
||||
debug("%s freebsd version:<%s>\n", section, "NOT FOUND");
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
out:
|
||||
grub_check_free(str);
|
||||
grub_check_free(hdr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int ret = 0;
|
||||
int bit64 = 0;
|
||||
char *data = NULL;
|
||||
grub_elf_t elf = NULL;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
debug("Invalid argc %d\n", argc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
data = grub_zalloc(8192);
|
||||
if (!data)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
elf = grub_elf_open(args[0], GRUB_FILE_TYPE_LINUX_INITRD);
|
||||
if (!elf)
|
||||
{
|
||||
debug("Failed to open file %s\n", args[0]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
bit64 = (args[1][0] == '6') ? 1 : 0;
|
||||
|
||||
ret = ventoy_freebsd_ver_elf(bit64, elf, ".data", args[2], data);
|
||||
if (ret != 0)
|
||||
{
|
||||
ret = ventoy_freebsd_ver_elf(bit64, elf, ".rodata", args[2], data);
|
||||
}
|
||||
|
||||
out:
|
||||
grub_check_free(data);
|
||||
check_free(elf, grub_elf_close);
|
||||
|
||||
|
||||
@@ -489,19 +489,19 @@ function ventoy_freebsd_proc {
|
||||
ventoy_get_truenas_ver "$1" "${chosen_path}"
|
||||
elif vt_strstr "$vt_volume_id" "FURYBSD"; then
|
||||
ventoy_get_furybsd_ver "$1" "${chosen_path}"
|
||||
elif regexp --set 1:vtBsdVerNum "^(15|14|13|12|11|10|9)_[0-9]" "$vt_volume_id"; then
|
||||
elif regexp --set 1:vtBsdVerNum "^(1[0-9]|9)_[0-9]" "$vt_volume_id"; then
|
||||
set vt_freebsd_ver=${vtBsdVerNum}.x
|
||||
elif [ -d (loop)/usr/midnightbsd-dist ]; then
|
||||
ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
|
||||
set vtFreeBsdDistro=MidnightBSD
|
||||
elif [ -e (loop)/bin/freebsd-version ]; then
|
||||
vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
|
||||
if regexp --set 1:vtBsdVerNum "\"(15|14|13|12|11|10|9)\.[0-9]-" "$vt_userland_ver"; then
|
||||
if regexp --set 1:vtBsdVerNum "\"(1[0-9]|9)\.[0-9]-" "$vt_userland_ver"; then
|
||||
set vt_freebsd_ver=${vtBsdVerNum}.x
|
||||
fi
|
||||
elif [ -e (loop)/README.TXT ]; then
|
||||
vt_1st_line (loop)/README.TXT vt_freebsd_line1
|
||||
if regexp --set 1:vtBsdVerNum "FreeBSD (15|14|13|12|11|10|9)\.[0-9]-" "$vt_freebsd_line1"; then
|
||||
if regexp --set 1:vtBsdVerNum "FreeBSD (1[0-9]|9)\.[0-9]-" "$vt_freebsd_line1"; then
|
||||
set vt_freebsd_ver=${vtBsdVerNum}.x
|
||||
fi
|
||||
elif vt_strstr "${chosen_path}" "MidnightBSD"; then
|
||||
@@ -531,7 +531,7 @@ function ventoy_freebsd_proc {
|
||||
fi
|
||||
|
||||
if [ "$vt_freebsd_ver" = "xx" ]; then
|
||||
set vt_freebsd_ver=14.x
|
||||
set vt_freebsd_ver=15.x
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user