]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
support new GhostBSD release
authorlongpanda <admin@ventoy.net>
Tue, 20 Apr 2021 05:10:35 +0000 (13:10 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 20 Apr 2021 05:10:35 +0000 (13:10 +0800)
14 files changed:
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c
GRUB2/MOD_SRC/grub-2.04/install.sh
INSTALL/grub/arm64-efi/file.mod [deleted file]
INSTALL/grub/arm64-efi/moddep.lst
INSTALL/grub/grub.cfg
INSTALL/grub/i386-efi/file.mod [deleted file]
INSTALL/grub/i386-efi/moddep.lst
INSTALL/grub/i386-pc/moddep.lst
INSTALL/grub/mips64el-efi/file.mod [deleted file]
INSTALL/grub/mips64el-efi/moddep.lst
INSTALL/grub/x86_64-efi/file.mod [deleted file]
INSTALL/grub/x86_64-efi/moddep.lst

index 4f80c4305b3968bd8b79d68c1619108ba1d257bc..33f09142dedcb6205e7277cc4b53d112aeda9427 100644 (file)
@@ -4402,6 +4402,7 @@ static cmd_para ventoy_cmds[] =
     { "vt_parse_iso_create_date", ventoy_cmd_parse_create_date, 0, NULL, "", "", NULL },
     { "vt_parse_freenas_ver", ventoy_cmd_parse_freenas_ver, 0, NULL, "", "", NULL },
     { "vt_unix_parse_freebsd_ver", ventoy_cmd_unix_freebsd_ver, 0, NULL, "", "", NULL },
+    { "vt_unix_parse_freebsd_ver_elf", ventoy_cmd_unix_freebsd_ver_elf, 0, NULL, "", "", NULL },
     { "vt_unix_reset", ventoy_cmd_unix_reset, 0, NULL, "", "", NULL },
     { "vt_unix_replace_conf", ventoy_cmd_unix_replace_conf, 0, NULL, "", "", NULL },
     { "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL },
index 6fa12e80f6716e10ea4b9335425ed17e26290895..7e9204d637fe16982037f6d82f746bb28905d6b0 100644 (file)
@@ -983,6 +983,7 @@ grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc,
 grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args);
 grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
 grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
+grub_err_t ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc, char **args);
 int ventoy_check_device_result(int ret);
 int ventoy_check_device(grub_device_t dev);
 void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid);
index 626517a036e29171f5bf8431010c35c652164189..e74e73891027c51b7f8b09a41a602fcf63c51ccb 100644 (file)
@@ -33,6 +33,8 @@
 #include <grub/i18n.h>
 #include <grub/net.h>
 #include <grub/time.h>
+#include <grub/elf.h>
+#include <grub/elfload.h>
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
 
@@ -383,6 +385,174 @@ 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)
+{
+    int j;
+    int k;
+    grub_elf_t elf = 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')
+    {
+        Elf64_Ehdr *e = &(elf->ehdr.ehdr64);
+        Elf64_Shdr *h;
+        Elf64_Shdr *s;
+        Elf64_Shdr *t;
+        Elf64_Half i;
+        
+        h = hdr = grub_zalloc(e->e_shnum * e->e_shentsize);
+        if (!h)
+        {
+            goto out;
+        }
+
+        debug("read section header %u %u %u\n", e->e_shnum, e->e_shentsize, e->e_shstrndx);
+        grub_file_seek(elf->file, e->e_shoff);
+        grub_file_read(elf->file, h, e->e_shnum * e->e_shentsize);
+
+        s = (Elf64_Shdr *)((char *)h + e->e_shstrndx * e->e_shentsize);        
+        str = grub_malloc(s->sh_size + 1);
+        if (!str)
+        {
+            goto out;
+        }
+        str[s->sh_size] = 0;
+
+        debug("read string table %u %u\n", (grub_uint32_t)s->sh_offset, (grub_uint32_t)s->sh_size);
+        grub_file_seek(elf->file, s->sh_offset);
+        grub_file_read(elf->file, str, s->sh_size);
+
+        for (t = h, i = 0; i < e->e_shnum; i++)
+        {
+            if (grub_strcmp(str + t->sh_name, ".data") == 0)
+            {
+                offset = t->sh_offset;
+                len = t->sh_size;
+                debug("find .data section at %u %u\n", (grub_uint32_t)offset, len);
+                break;
+            }
+            t = (Elf64_Shdr *)((char *)t + e->e_shentsize);
+        }
+    }
+    else
+    {
+        Elf32_Ehdr *e = &(elf->ehdr.ehdr32);
+        Elf32_Shdr *h;
+        Elf32_Shdr *s;
+        Elf32_Shdr *t;
+        Elf32_Half i;
+        
+        h = hdr = grub_zalloc(e->e_shnum * e->e_shentsize);
+        if (!h)
+        {
+            goto out;
+        }
+
+        debug("read section header %u %u %u\n", e->e_shnum, e->e_shentsize, e->e_shstrndx);
+        grub_file_seek(elf->file, e->e_shoff);
+        grub_file_read(elf->file, h, e->e_shnum * e->e_shentsize);
+
+        s = (Elf32_Shdr *)((char *)h + e->e_shstrndx * e->e_shentsize);        
+        str = grub_malloc(s->sh_size + 1);
+        if (!str)
+        {
+            goto out;
+        }
+        str[s->sh_size] = 0;
+
+        debug("read string table %u %u\n", (grub_uint32_t)s->sh_offset, (grub_uint32_t)s->sh_size);
+        grub_file_seek(elf->file, s->sh_offset);
+        grub_file_read(elf->file, str, s->sh_size);
+
+        for (t = h, i = 0; i < e->e_shnum; i++)
+        {
+            if (grub_strcmp(str + t->sh_name, ".data") == 0)
+            {
+                offset = t->sh_offset;
+                len = t->sh_size;
+                debug("find .data section at %u %u\n", (grub_uint32_t)offset, len);
+                break;
+            }
+            t = (Elf32_Shdr *)((char *)t + e->e_shentsize);
+        }
+    }
+
+    if (offset == 0 || len == 0)
+    {
+        debug(".data section not found %s\n", args[0]);
+        goto out;
+    }
+
+    grub_file_seek(elf->file, offset + len - 8192);
+    grub_file_read(elf->file, data, 8192);
+
+    for (j = 0; j < 8192 - 12; j++)
+    {
+        if (grub_strncmp(data + j, "@(#)FreeBSD ", 12) == 0)
+        {
+            for (k = j + 12; k < 8192; k++)
+            {
+                if (0 == grub_isdigit(data[k]) && data[k] != '.')
+                {
+                    data[k] = 0;
+                    break;
+                }
+            }
+        
+            grub_snprintf(ver, sizeof(ver), "%s", data + j + 12);
+            break;
+        }
+    }
+
+    if (ver[0])
+    {
+        k = (int)grub_strtoul(ver, NULL, 10);
+        debug("freebsd version:<%s> <%d.x>\n", ver, k);
+        grub_snprintf(ver, sizeof(ver), "%d.x", k);
+        ventoy_set_env(args[2], ver);
+    }
+    else
+    {
+        debug("freebsd version:<%s>\n", "NOT FOUND");
+    }
+
+out:
+    grub_check_free(str);
+    grub_check_free(hdr);
+    grub_check_free(data);
+    check_free(elf, grub_elf_close);
+    
+    VENTOY_CMD_RETURN(GRUB_ERR_NONE);
+}
+
 grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     grub_uint32_t i;
index b5ad2e34b0d4529cb1051e5c7f159caf9809bd72..59d7d0ba39dcfbe6d96d8b9c725b19cd95bacb67 100644 (file)
@@ -12,14 +12,14 @@ make install
 PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
 
 net_modules_legacy="net tftp http"
-all_modules_legacy="setkey date drivemap blocklist regexp newc vga_text ntldr search at_keyboard usb_keyboard  gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal  linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal  udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
+all_modules_legacy="file setkey date drivemap blocklist regexp newc vga_text ntldr search at_keyboard usb_keyboard  gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal  linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal  udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
 
 net_modules_uefi="efinet net tftp http"
-all_modules_uefi="setkey blocklist ventoy test true regexp newc search at_keyboard usb_keyboard  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
+all_modules_uefi="file setkey blocklist ventoy test true regexp newc search at_keyboard usb_keyboard  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
 
-all_modules_arm64_uefi="setkey blocklist ventoy test true regexp newc search  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
+all_modules_arm64_uefi="file setkey blocklist ventoy test true regexp newc search  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
 
-all_modules_mips64el_uefi="setkey blocklist ventoy test true regexp newc search  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
+all_modules_mips64el_uefi="file setkey blocklist ventoy test true regexp newc search  gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain  priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
 
 
 if [ "$1" = "uefi" ]; then
diff --git a/INSTALL/grub/arm64-efi/file.mod b/INSTALL/grub/arm64-efi/file.mod
deleted file mode 100644 (file)
index f43584e..0000000
Binary files a/INSTALL/grub/arm64-efi/file.mod and /dev/null differ
index b1814bebcc9aea858b2e9929b6b3753aa9a1cb88..3342bd68175825fab7c5011256c393182adc69a0 100644 (file)
@@ -93,7 +93,7 @@ terminal:
 div:
 crypto:
 part_bsd: part_msdos
-ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
+ventoy: elf fshelp ext2 btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
 gcry_sha512: crypto
 password: crypto normal
 fshelp:
index a466f9f350cdd72476c33d72c282e9aef3ba59f2..d5bd4654e06a10c90b32fb191bd9b2e989ad69fc 100644 (file)
@@ -318,13 +318,8 @@ function distro_specify_initrd_file_phase2 {
 }
 
 function ventoy_get_ghostbsd_ver {
-
-    # vt_parse_iso_create_date "$1/${chosen_path}" vt_create_date    
-    # if regexp "^202005" "$vt_create_date"; then
-        # set vt_freebsd_ver=12.x
-    # fi
-    
-    set vt_freebsd_ver=12.x
+    # fallback to parse version from elf /boot/kernel/kernel
+    set vt_freebsd_ver=xx
 }
 
 function ventoy_get_furybsd_ver {
@@ -371,6 +366,7 @@ function ventoy_get_midnightbsd_ver {
 
 function ventoy_freebsd_proc {
     set vtFreeBsdDistro=FreeBSD
+    set vt_freebsd_ver=xx
 
     if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
         ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
@@ -421,8 +417,6 @@ function ventoy_freebsd_proc {
         fi
     elif vt_strstr "${chosen_path}" "MidnightBSD"; then
         set vt_freebsd_ver=9.x
-    else
-        set vt_freebsd_ver=12.x
     fi
     
     set vt_freebsd_bit=64
@@ -433,7 +427,17 @@ function ventoy_freebsd_proc {
             fi
             break
         fi
-    done    
+    done
+
+    if [ "$vt_freebsd_ver" = "xx" ]; then
+        if [ -e (loop)/boot/kernel/kernel ]; then
+            vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel $vt_freebsd_bit vt_freebsd_ver
+        fi
+        
+        if [ "$vt_freebsd_ver" = "xx" ]; then
+            set vt_freebsd_ver=13.x        
+        fi
+    fi
 
     if [ -n "${vtdebug_flag}" ]; then
         echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
diff --git a/INSTALL/grub/i386-efi/file.mod b/INSTALL/grub/i386-efi/file.mod
deleted file mode 100644 (file)
index 55d991b..0000000
Binary files a/INSTALL/grub/i386-efi/file.mod and /dev/null differ
index bd5d77dd1798c089e9fa5d79e45657dc233c09cf..3ab0a92b40e233d6b75c4a905d2c18c014da75ae 100644 (file)
@@ -120,7 +120,7 @@ ehci: cs5536 usb boot
 crypto:
 part_bsd: part_msdos
 cs5536:
-ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
+ventoy: elf fshelp ext2 btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
 gcry_sha512: crypto
 password: crypto normal
 fshelp:
index 9c4052a85ba9c39da58a9ee5bf75b8dc5c1623c2..4f8b330d719d8aa3327064e003578d27577f162b 100644 (file)
@@ -123,7 +123,7 @@ crypto:
 part_bsd: part_msdos
 cs5536: pci
 biosdisk:
-ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660 acpi
+ventoy: elf fshelp ext2 btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660 acpi
 lsapm:
 gcry_sha512: crypto
 password: crypto normal
diff --git a/INSTALL/grub/mips64el-efi/file.mod b/INSTALL/grub/mips64el-efi/file.mod
deleted file mode 100644 (file)
index e3594ee..0000000
Binary files a/INSTALL/grub/mips64el-efi/file.mod and /dev/null differ
index ea8911592b70aaf20d65502491c3185803e8aa9b..5b71692e46bc525ff41a687e6f18454bd1a96b10 100644 (file)
Binary files a/INSTALL/grub/mips64el-efi/moddep.lst and b/INSTALL/grub/mips64el-efi/moddep.lst differ
diff --git a/INSTALL/grub/x86_64-efi/file.mod b/INSTALL/grub/x86_64-efi/file.mod
deleted file mode 100644 (file)
index e727f5f..0000000
Binary files a/INSTALL/grub/x86_64-efi/file.mod and /dev/null differ
index ccdfd1e4e11e53f00d1ec2065e1b26713869c62c..f706b8282af88aaaab3d071f949b4cbfe952204b 100644 (file)
@@ -120,7 +120,7 @@ ehci: cs5536 usb boot
 crypto:
 part_bsd: part_msdos
 cs5536:
-ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
+ventoy: elf fshelp ext2 btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
 gcry_sha512: crypto
 password: crypto normal
 fshelp: