Compare commits

...

209 Commits

Author SHA1 Message Date
longpanda
d8433985e7 1.0.48 release 2021-08-01 21:50:36 +08:00
Diacius
b003105925 Improve English Language (#963)
Changed `clear` to `clearing` and `detail` to `details`
2021-07-31 09:21:57 +08:00
fossdd
2ca2c83b6b Let the link to build from source also work on gitee and local copies. (#1009)
The Link linked to a GitHub page. But markdown also support link in the directory: Now the link works in your local markdown viewer, github and gitee, to their own page instead that all redirect to GitHub
2021-07-31 09:21:02 +08:00
VenusGirl
dff7e495ca Update languages.json (#1003)
Update Korean
2021-07-31 09:20:43 +08:00
VenusGirl
cf0f395c56 Update languages.json (#1002)
Update Korean
2021-07-31 09:20:23 +08:00
Tayfun Akkoyun
69bc90da42 Update languages.json (#1004)
New Lines of language.json file was translated for Turkish language. Can you update language.json file?
2021-07-31 09:20:06 +08:00
Hoàng Điềm Tĩnh
ffc40234ca Update Vietnamese for languages.json (#1018)
* Update languages.json

Update Vietnamese for languages.json

* Update languages.json

* Update languages.json
2021-07-31 09:19:52 +08:00
Thomas De Rocker
e57daa5065 Update languages.json (#1014) 2021-07-31 09:19:32 +08:00
ensag-dev
5c733a20f8 Update occitan (#1012) 2021-07-31 09:19:13 +08:00
longpanda
069342ab9a change ownership when cpio pack 2021-07-27 22:18:39 +08:00
longpanda
32a964eded add vtoytool 01 2021-07-27 21:28:47 +08:00
longpanda
51b92f398a misc update 2021-07-27 19:10:30 +08:00
longpanda
5d0ebf4510 support custom arch iso (#1021) 2021-07-27 19:08:40 +08:00
longpanda
cf94487ad5 misc update 2021-07-26 15:31:56 +08:00
longpanda
af83f46a3d Merge branch 'master' of https://github.com/ventoy/Ventoy 2021-07-26 15:30:54 +08:00
啊o额iu鱼
4910e9f380 Mirror action check owner (#1016) 2021-07-25 20:00:23 +08:00
longpanda
fb38b321c2 Code Optimization 2021-07-24 19:03:09 +08:00
longpanda
7b78fe555e Support nested boot.
For example: Ventoy-->rEFInd.iso-->Ventoy-->Windows.iso
2021-07-24 18:47:39 +08:00
longpanda
094ba61848 Fix Windows boot issue when Ventoy is booted from rEFInd 2021-07-24 18:45:51 +08:00
longpanda
faa0e46d3a Fix the missing program issue for EasyU 2021-07-23 23:26:27 +08:00
longpanda
537f0eaa7e 1.0.47 release 2021-07-17 17:42:06 +08:00
longpanda
c8cf9b7ce2 Speedup md5sum/sha1sum/sha256sum/sha512sum command 2021-07-16 01:36:10 +08:00
longpanda
4c71d7c190 Support WinPE which contains pecmd.exe 2021-07-16 01:03:01 +08:00
longpanda
47f9f2c42c Add support for MocaccinoOS distro 2021-07-15 17:48:03 +08:00
longpanda
fc3a5fae36 Fixed HBCD boot issue. (#992) 2021-07-11 10:14:16 +08:00
longpanda
b3982d4930 Fixed a bug when booting big boot.wim file. 2021-07-11 01:02:00 +08:00
longpanda
c280baae27 Add Ventoy Sparse Image Option 2021-07-10 09:41:52 +08:00
longpanda
425d640480 Fixed a bug for ventoy_openwrt.xz check. 2021-07-10 09:20:54 +08:00
longpanda
07d4140cf4 Optimization for booting openwrt 2021-07-09 17:35:19 +08:00
longpanda
90ae07d227 Update README.md 2021-07-08 16:39:32 +08:00
longpanda
e3e21eb6e6 issue template 2021-07-06 22:52:26 +08:00
longpanda
c8ce2ae85a issue template 2021-07-06 22:51:27 +08:00
longpanda
c02a6955c3 Add check for the built-in browser in WebDeepin.sh 2021-07-06 10:10:59 +08:00
David P
6b78603dd3 fix Parabola rEFInd booting (#989)
newer Parabola rEFInd ISOs need to run vt_linux_get_main_initrd_index to actually work, just like the systemd-boot ISOs
2021-07-06 10:07:21 +08:00
longpanda
07a386c963 Add issue template 2021-07-05 16:49:31 +08:00
longpanda
eb048c0075 Remove the 2TB limit for the reserved space in Ventoy2Disk.exe 2021-07-05 13:40:19 +08:00
longpanda
37ac3f312f Optimization for booting openwrt 2021-06-28 15:15:39 +08:00
longpanda
092cff8429 Support some floppy image in Memdisk mode 2021-06-25 12:34:28 +08:00
longpanda
b347c1b5da Optimization for booting OpenWrt 2021-06-25 11:49:45 +08:00
longpanda
da746c608f Set hidden attribute for VTOYEFI part in GPT partition style 2021-06-21 13:27:41 +08:00
longpanda
81aa56955a optimization for boot openwrt 2021-06-20 21:44:37 +08:00
longpanda
d1679871a6 optimization for booting openwrt 2021-06-20 20:20:17 +08:00
longpanda
f383052013 add debug info 2021-06-20 11:28:19 +08:00
longpanda
667f5bcc1b Fix the Memdisk/WIMBOOT mode/... tip message display error
When VTOY_DEFAULT_IMAGE was set to F6>xxxx, if you press F1 or ctrl+w, the tip message will show ??
2021-06-18 10:41:41 +08:00
longpanda
af69cb7f44 1.0.46 release 2021-06-13 20:29:11 +08:00
longpanda
7bb13fc18a Merge branch 'master' of https://github.com/ventoy/Ventoy 2021-06-11 20:36:29 +08:00
longpanda
7fce7e0aba Fix a bug when booting nitrux-release-amd64_2021.05.28.iso (#953) 2021-06-11 20:36:17 +08:00
VlatkoS
2a435084c2 Updated and enhanced Macedonian translation (#930)
Updated and enhanced Macedonian translation
2021-06-11 10:52:01 +08:00
Silejonu
c0c454a436 Update French translation (#931)
Added missing French translation strings and corrected a few already existing ones.
2021-06-11 10:51:47 +08:00
longpanda
63924fa8bd optimize for CRUX 2021-06-09 22:40:08 +08:00
longpanda
3e47f5e8de Fix a bug about ventoy version message position when VTOY_DEFAULT_IMG is set to F6>xxx 2021-06-09 20:55:45 +08:00
longpanda
b5eb347244 Add support for Lakka 3.0/3.1 img file 2021-06-08 23:43:26 +08:00
longpanda
9225c940a6 optimization for cdlinux 2021-05-31 21:02:46 +08:00
longpanda
a8edb99d28 priority key>parent in menu class plugin 2021-05-31 20:46:45 +08:00
longpanda
ac3ab97686 1.0.45 release 2021-05-29 19:42:16 +08:00
longpanda
c42a8c6d93 misc update 2021-05-23 22:39:30 +08:00
longpanda
4b1dd4d3af print progress for md5sum/sha1sum/sha256sum/sha512sum 2021-05-22 19:39:59 +08:00
longpanda
f342be1d6c Merge branch 'master' of https://github.com/ventoy/Ventoy 2021-05-21 10:06:43 +08:00
longpanda
f4774ee0e4 Fix pack error in vDisk env (#912) 2021-05-21 10:06:16 +08:00
MELERIX
d3cfa73631 Updated Spanish Translation (#911) 2021-05-19 15:45:00 +08:00
longpanda
331080fb95 Add parent option in auto_install and injection plugin. 2021-05-16 18:12:07 +08:00
longpanda
99fbd14f08 1.0.44 release 2021-05-15 19:44:20 +08:00
longpanda
1c5aeb35dc Fix a bug about unaligned read in UEFI mode. 2021-05-15 14:23:46 +08:00
longpanda
f7b3bd1729 Add parent option in password plugin 2021-05-15 08:57:26 +08:00
longpanda
672632a0c2 Add isopwd wimpwd efipwd imgpwd vhdpwd vtoypwd option in password plugin (#898) 2021-05-14 22:27:26 +08:00
longpanda
d07aa6ce07 Add -o option in CreatePersistentImg.sh (#903) 2021-05-14 12:12:07 +08:00
longpanda
93996cf7e2 1. Optimization for WIMBOOT mode.
2. Add WIMBOOT for UEFI mode.
2021-05-13 23:05:42 +08:00
longpanda
ca62128f9b Add WIMBOOT mode 2021-05-12 22:49:12 +08:00
longpanda
265b70f1c7 misc update 2021-05-10 18:13:41 +08:00
longpanda
491f0bea8a Fix issue when install Fedora 34 Server Edition 2021-05-10 16:03:40 +08:00
longpanda
47e77e003c 1.0.43 release 2021-05-08 18:05:04 +08:00
longpanda
d05eab2be1 support boot Windows VHD(x) at local disk 2021-05-08 15:33:11 +08:00
longpanda
849dfb463d 1. Change the UTF-16 languages.ini to UTF-8 languages.json
2. The update button is available even if data corrupted in VTOYEFI partition.
3. Set the default focus to No when you click Install button in Ventoy2Disk.exe.
4. Fix a BUG when booting Windows VHD(x) with the latest ventoy_vhdboot.img.
5. Support boot Windows VHD(x) files in local disk.
2021-05-08 14:22:37 +08:00
longpanda
7715bd705c 1.0.42 release 2021-04-27 18:22:10 +08:00
panchenbo
042ca4b5e3 add support for UnionTechOS fuyu (#864) 2021-04-27 17:28:35 +08:00
longpanda
e1099e1e5b Add parent option in menu_class plugin. 2021-04-25 10:31:03 +08:00
longpanda
c6be35f2c0 Support * fuzzy matching for file path in some plugins 2021-04-24 16:03:38 +08:00
longpanda
b15a96b747 1.0.41 release 2021-04-21 21:12:43 +08:00
longpanda
6bd0463d34 Support openwrt IMG file 2021-04-21 19:40:54 +08:00
longpanda
1ce568d971 Support for new MidnightBSD release 2021-04-21 17:00:40 +08:00
longpanda
f82475d950 support new GhostBSD release 2021-04-20 13:10:35 +08:00
longpanda
aad154616c languages.ini update 2021-04-19 09:05:05 +08:00
longpanda
83c3a932d3 misc update 2021-04-14 16:59:57 +08:00
longpanda
0aff8f5109 update vtoytool 2021-04-14 10:26:27 +08:00
longpanda
2750f0c5a7 misc update 2021-04-13 19:42:19 +08:00
longpanda
f71a1fcce9 misc update 2021-04-13 16:46:23 +08:00
longpanda
e252fab9a4 boot iso file with ventoy in ventoy_grub.cfg 2021-04-12 22:30:14 +08:00
longpanda
37212a8ea4 1. Fix a bug about source media missing when boot CentOS8
2. Support RED OS
2021-04-12 18:56:26 +08:00
longpanda
e71221cdba Fix a bug about source media missing when boot openEuler 2021-04-12 11:53:25 +08:00
longpanda
65a2cb1685 1.0.40 release 2021-04-10 20:01:39 +08:00
longpanda
e23e76f54e grub2 boot mode for UEFI 2021-04-10 13:57:20 +08:00
longpanda
8ded032c92 Update vietnamese language (#836) 2021-04-09 19:54:24 +08:00
longpanda
fc5cd0a00a update languages.ini (#829 #834) 2021-04-07 13:37:52 +08:00
longpanda
6cc400b8d4 experimental persistent support for Fedora (#791) 2021-04-06 14:28:34 +08:00
longpanda
ffc915ca53 persistence support for ArchLinux series (Arch/ArchMan/ArchBang/ArchLabs/BlackArch...) 2021-04-04 22:25:26 +08:00
longpanda
8ebe972f6e Fixup a bug when booting special Windows/WinPE ISO file. 2021-04-02 14:11:47 +08:00
longpanda
39975dd1c3 update CI script 2021-04-02 10:08:23 +08:00
longpanda
1a648d8689 update tool chain download link 2021-04-02 09:51:42 +08:00
longpanda
8234961228 debug CI 2021-04-01 13:46:28 +08:00
longpanda
e1ffbad431 Support RHEL6/CentOS6 auto install 2021-04-01 12:02:32 +08:00
longpanda
4a66104c6e Clear input key before show main menu 2021-04-01 09:51:52 +08:00
longpanda
32bcd8f87b Clear input key before show main menu 2021-04-01 09:42:57 +08:00
longpanda
26c1756e8d languages.ini update (#809 #816 #818) 2021-04-01 09:21:42 +08:00
longpanda
f4bbec65ba 1.0.39 release 2021-03-28 17:18:23 +08:00
longpanda
58d387f732 supoort veket 20.10 2021-03-24 22:08:30 +08:00
longpanda
2e10aabe94 Add VTOY_DEFAULT_KBD_LAYOUT in global control plugin 2021-03-24 22:08:10 +08:00
longpanda
a63a41f79d Serbian UI Language Update (#806) 2021-03-24 10:11:20 +08:00
longpanda
64748308a3 Add a workaround for buggy bootloader's out-of-range access 2021-03-24 10:07:07 +08:00
longpanda
33cc1e271a Support latest CentOS Stream 8 distro. (#799) 2021-03-18 12:27:21 +08:00
longpanda
291e0a3a38 add debug info 2021-03-17 22:17:51 +08:00
longpanda
0717195481 1.0.38 release 2021-03-16 19:35:19 +08:00
longpanda
26b3bca25b Add Swedish languages #795 2021-03-15 21:53:00 +08:00
longpanda
5d3285356e fix issue for image_black_list 2021-03-15 21:51:57 +08:00
longpanda
1e12969555 add support for openEuler 2021-03-13 18:55:05 +08:00
longpanda
db892d5e12 optimization for script for UOS 2021-03-10 14:18:24 +08:00
longpanda
7166164afe languages.ini update (#790 #768 #786 #789) 2021-03-10 09:47:40 +08:00
longpanda
67e839b9f2 script optimization for UOS 2021-03-09 21:01:34 +08:00
longpanda
dce5d1b769 support for tails.img 2021-03-09 17:17:46 +08:00
longpanda
83d91c525f support new veket_20 2021-03-08 16:18:22 +08:00
longpanda
78df21fc40 Update README.md 2021-03-06 22:36:30 +08:00
longpanda
1840cb8f38 1.0.37 release 2021-03-06 19:53:50 +08:00
longpanda
b63ce2a3df experimental support for loongson mips64el uefi 2021-03-05 23:03:34 +08:00
longpanda
bb7e10d93e Add VTOY_MAX_SEARCH_LEVEL option in global control plugin 2021-03-02 17:58:19 +08:00
longpanda
324c97883a Improvement for UEFI boot compatibility. 2021-03-02 15:39:27 +08:00
longpanda
3c35345e38 remove the ASSERT warning in UEFI mode when boot fail. 2021-03-01 17:49:10 +08:00
longpanda
9f357f8ed1 use uname -m to detect architecture (PR #774) 2021-03-01 15:17:26 +08:00
longpanda
eb1a014d5b issue (#769) 2021-02-27 23:40:19 +08:00
longpanda
cbbd57eee5 1.0.36 release 2021-02-27 17:57:41 +08:00
longpanda
7b08954e57 1. change icon from * to a lock icon
2. typo correct
3. misc update
2021-02-27 10:37:40 +08:00
longpanda
08634fba9f update languages.ini and license 2021-02-27 09:27:31 +08:00
longpanda
96c5a25263 update languages.ini 2021-02-26 21:38:09 +08:00
longpanda
43e8ec5785 Experimental Linux GUI based on web browser 2021-02-26 21:36:53 +08:00
longpanda
7279ba9bc8 Ventoy2Disk.exe add a star to identify secure boot 2021-02-25 21:03:56 +08:00
longpanda
3929ed55ca update disk sort compare 2021-02-24 00:07:44 +08:00
longpanda
fd6580be72 Update for Ventoy2Disk.exe
1. Add "Show All Devices" option
2. Add "Partition align with 4KB" option
3. Display size optimization
4. Doesn't check partition active flag anymore
2021-02-23 17:49:28 +08:00
longpanda
12e8ae26ae misc update 2021-02-18 16:15:13 +08:00
longpanda
82977d9b8a add support for nbd device (PR #746) 2021-02-18 09:43:27 +08:00
longpanda
3541735796 For 1.0.35 2021-02-08 18:38:11 +08:00
longpanda
c82e4296d3 update script for jenkins 2021-02-07 11:34:44 +08:00
longpanda
cc9ff41589 misc update 2021-02-07 01:01:04 +08:00
longpanda
08d218fd82 Add LiveCD binaries 2021-02-06 20:39:25 +08:00
longpanda
2185556dfd fix integer overflow issue for i386-pc 2021-02-06 15:41:43 +08:00
longpanda
97be7b8bfb fix integer overflow issue for i386-pc 2021-02-06 14:37:04 +08:00
longpanda
3dd3b7d26f Print a tip when enumerating image files. 2021-02-05 14:13:02 +08:00
longpanda
6ded335527 Optimization for booting TinyCore series distros 2021-02-05 01:14:22 +08:00
longpanda
3545dfa29f fix Docker CI repo issue 2021-02-04 17:47:29 +08:00
longpanda
b0208c8ce3 Only use acpi when secureboot if enabled in UEFI mode. 2021-02-04 13:36:26 +08:00
longpanda
b1d5237041 1.0.34 release 2021-02-03 21:07:17 +08:00
longpanda
a37c6af8d0 Display warning message if ISO file has an invalid size. 2021-02-03 13:56:28 +08:00
longpanda
61d4248d51 Optimization for slax-9.11.0 (#725) 2021-02-03 00:40:37 +08:00
longpanda
dccefc5277 Support Lenovo BIOS Update CD (#729) 2021-02-02 23:54:01 +08:00
longpanda
66d5946bd1 VentoyLiveCD x86_64 2021-02-02 23:24:19 +08:00
longpanda
198dcd94a6 update CI Script 2021-02-02 22:26:23 +08:00
longpanda
f26a927b3e VentoyLiveCD x86_64 2021-02-02 21:04:51 +08:00
longpanda
08e7da50ef Update CI Script 2021-02-02 20:30:25 +08:00
longpanda
c7bb6270cc debug CI 2021-02-02 20:02:25 +08:00
longpanda
a5e998bcaf Change VentoyliveCD from i386 to x86_64 2021-02-02 18:54:56 +08:00
longpanda
15570cd996 CI Debug 2021-02-02 12:03:53 +08:00
longpanda
e76edf9286 CI Debug 2021-01-29 21:53:17 +08:00
longpanda
195431479c Update BuildDoc 2021-01-29 20:59:06 +08:00
longpanda
18f35dafbf Update CI 2021-01-29 20:58:02 +08:00
longpanda
519fac719e Update CI 2021-01-29 17:54:04 +08:00
longpanda
ee81f89911 CI build 2021-01-29 14:47:39 +08:00
longpanda
b1ad99cde0 update CI script 2021-01-29 14:26:02 +08:00
longpanda
715f410832 update CI script 2021-01-29 13:35:39 +08:00
longpanda
17da2e2a21 update CI build script 2021-01-29 13:02:51 +08:00
longpanda
de6eb54853 update workflows/sync2gitee.yml 2021-01-29 10:14:17 +08:00
longpanda
85f6f3213f update build scripts 2021-01-29 10:11:30 +08:00
longpanda
80a088babb add support for Bliss-OS 2021-01-29 09:46:15 +08:00
longpanda
183175cad2 Create sync2gitee.yml 2021-01-26 23:05:37 +08:00
longpanda
390eec4218 add image_blacklist plugin option 2021-01-26 20:50:26 +08:00
longpanda
620bcad324 update for vdiskchain 2021-01-26 11:07:31 +08:00
longpanda
bae671bd68 fix issue #714 2021-01-23 13:50:00 +08:00
longpanda
1e75385146 update build script 2021-01-22 15:33:06 +08:00
longpanda
725a33f988 fix build error issue #713 2021-01-22 15:24:32 +08:00
longpanda
1f1769d235 issue #710 2021-01-22 09:36:48 +08:00
longpanda
a129996756 1.0.33 release 2021-01-21 15:40:50 +08:00
longpanda
8632e56561 add vdiskchain module 2021-01-20 10:59:21 +08:00
longpanda
8f711c9db9 Optimization for check secure boot status in list mode. (PR #703) 2021-01-18 09:38:23 +08:00
longpanda
b0cacd6686 update 2021-01-16 23:36:32 +08:00
longpanda
13b2192a59 support for 360Udisk 2021-01-16 23:30:12 +08:00
longpanda
807d313cd5 add support for austrumi64-4.3.5.iso/slacko64-7.0.iso 2021-01-15 14:09:59 +08:00
longpanda
2f45cea46e fix a bug for arm64 ubuntu-20.10-live-server-arm64.iso 2021-01-11 13:40:14 +08:00
longpanda
7cdc7386a8 Fix a bug when use workaround for Legacy BIOS access limitation with GPT partition style 2021-01-08 20:08:32 +08:00
longpanda
44bb72ca0a add missing source 2021-01-08 11:03:32 +08:00
longpanda
5e6b0800bd update edk build script for ia32 #690 2021-01-08 09:28:16 +08:00
longpanda
01c902e026 update build script 2021-01-07 20:40:30 +08:00
longpanda
a68629a931 Add support for keyboard layout
F5 ---> Keyboard Layouts
2021-01-07 20:32:38 +08:00
longpanda
c84855bbee 1.0.32 release 2021-01-06 16:00:03 +08:00
longpanda
f2ed81b004 update 2021-01-06 07:50:23 +08:00
longpanda
6434e453b2 support for latest snapshot FreeBSD 13.0 2021-01-01 22:37:22 +08:00
longpanda
041ccb7435 dragonfly 2021-01-01 19:17:56 +08:00
longpanda
bfe194c190 DragonFly BSD support 2020-12-31 21:56:58 +08:00
longpanda
fb7008f49a 1.0.31 release 2020-12-23 19:49:12 +08:00
longpanda
463d0b2004 rebuild lz4cat64 2020-12-22 22:41:31 +08:00
longpanda
4707b76bb2 Rebuild some binaries with musl-libc to avoid virus false positive (issue #660) 2020-12-22 21:21:44 +08:00
longpanda
ff0ad76d8d add support for latest blackarch distro (issue #654) 2020-12-17 16:40:53 +08:00
longpanda
c8b2cca7c2 add support for austrumi (issue #637) 2020-12-17 16:12:46 +08:00
longpanda
afbeba7cf5 fix issue #614 2020-12-17 16:11:17 +08:00
BL4CKH47H4CK3R
bb3789f6fc Set default label from ventoy to Ventoy (#656)
Windows version has default label Ventoy instead of ventoy.
Commited just for beautifications !
2020-12-17 12:33:02 +08:00
longpanda
ea8a9e83ab workaround for 2TB+ disk 2020-12-16 23:08:36 +08:00
longpanda
8b9901a6a5 add austrumi support.(issue #637) 2020-12-15 17:42:15 +08:00
longpanda
0ac83bffda support Anarchy Linux 1.3.1 issue #642 2020-12-15 16:21:41 +08:00
longpanda
40c0504dfb 1.0.30 release 2020-12-12 17:42:45 +08:00
longpanda
ebaa4d954a IA32 ARM64 support 2020-12-12 07:56:52 +08:00
longpanda
2936666a78 Code Optimize 2020-12-12 07:40:33 +08:00
longpanda
784e3ae879 add class for submenu of 'Ventoy UEFI Utilities' 2020-11-26 14:51:13 +08:00
longpanda
d8fbd79dda 1.0.29 release 2020-11-19 20:45:17 +08:00
David P
8c192a1807 grub.cfg: add support for new Parabola ISOs (#590) 2020-11-16 11:48:41 +08:00
1217 changed files with 131345 additions and 6807 deletions

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1 @@
blank_issues_enabled: false

View File

@@ -0,0 +1,93 @@
name: Issue Report
description: File an issue report
title: "[issue]: "
assignees:
- octocat
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this issue report!
- type: checkboxes
id: faq
attributes:
label: Official FAQ
description: Have you checked the official FAQ at [https://www.ventoy.net/en/faq.html](https://www.ventoy.net/en/faq.html) ?
options:
- label: I have checked the official FAQ.
required: true
- type: input
id: version
attributes:
label: Ventoy Version
description: What version of ventoy are you running?
placeholder: 1.0.48
validations:
required: true
- type: dropdown
id: latestrelease
attributes:
label: What about latest release
description: Have you tried with the latest release of Ventoy?
options:
- Yes. I have tried the latest release, but the bug still exist.
- No. I didn't try the latest release.
validations:
required: true
- type: dropdown
id: bios
attributes:
label: BIOS Mode
description: In which BIOS mode did you find the bug?
options:
- Legacy BIOS Mode
- UEFI Mode
- Both
validations:
required: true
- type: dropdown
id: partstyle
attributes:
label: Partition Style
description: Which partition style did you select when you install Ventoy?
options:
- MBR
- GPT
validations:
required: true
- type: input
id: capacity
attributes:
label: Disk Capacity
description: What is the capacity of the disk installed with Ventoy?
placeholder: 32GB
validations:
required: true
- type: dropdown
id: checksum
attributes:
label: Image file checksum (if applicable)
description: Have you checked the image file in Ventoy's menu as [https://www.ventoy.net/en/faq.html#faq_boot_checksum](https://www.ventoy.net/en/faq.html#faq_boot_checksum) ?
options:
- Yes.
- No.
validations:
required: false
- type: input
id: link
attributes:
label: Image file download link (if applicable)
description: What is the image file download link?
placeholder: https://xxx
validations:
required: false
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Tell me what happened. It's highly recommended to include some photo or video about the bug.
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true

View File

@@ -5,6 +5,8 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
@@ -13,12 +15,19 @@ jobs:
- uses: actions/checkout@v2
- name: Run docker-compose up
run: docker-compose up
- uses: actions/upload-artifact@v2
with:
name: ventoy-windows
path: INSTALL/ventoy-*windows*
- uses: actions/upload-artifact@v2
with:
name: ventoy-linux
path: INSTALL/ventoy-*linux*
- uses: actions/upload-artifact@v2
with:
name: ventoy-windows
path: INSTALL/ventoy-*windows*
name: ventoy-livecd
path: INSTALL/ventoy-*livecd*
- uses: actions/upload-artifact@v2
with:
name: xxx-build-log
path: DOC/build.log

25
.github/workflows/sync2gitee.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name: Mirror GitHub to Gitee
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
run:
name: Sync-GitHub-to-Gitee
if: ${{ github.repository_owner == 'ventoy' }}
runs-on: ubuntu-latest
steps:
- name: Mirror the Github repos to Gitee.
uses: Yikun/hub-mirror-action@master
with:
src: github/ventoy
dst: gitee/LongPanda
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
static_list: "Ventoy"
force_update: true

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/aarch64_xzcat.config Normal file

File diff suppressed because it is too large Load Diff

55
BUSYBOX/build.txt Normal file
View File

@@ -0,0 +1,55 @@
======== How to build ash/hexdump/xzcat for aarch64 ========
#How to get ash.config/hexdump.cofig/xzcat.config
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make allnoconfig
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make menuconfig
#----> enable static build
#----> enable xzcat
#get aarch64_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy aarch64_xzcat.config as .config
ARCH=arm64 CROSS_COMPILE=aarch64-linux- make
rename ./busybox to xzcat
======== How to build ash/hexdump/xzcat for mips64el ========
#download mips64el-musl cross toolchain from https://github.com/ventoy/musl-cross-make/releases/download/latest/
#How to get ash.config/hexdump.cofig/xzcat.config
#ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make allnoconfig "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
#ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make menuconfig "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
#----> enable static build
#----> enable xzcat
#get mips64el_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy mips64el_xzcat.config as .config
ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
rename ./busybox to xzcat
======== How to build full busybox =========
#make defconfig
#make menuconfig select static build
======== How to build ash/hexdump/xzcat for x86_64 ==========
#How to get ash.config/hexdump.cofig/xzcat.config
#make allnoconfig
#make menuconfig
#----> enable static build
#----> enable xzcat
#get x86_64_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy x86_64_xzcat.config as .config
modify Makefile
CC = gcc -specs "/usr/local/musl/lib/musl-gcc.specs"
MODFLAGS = -DMODULE -specs "/usr/local/musl/lib/musl-gcc.specs"
make
rename ./busybox to xzcat

View File

@@ -2,17 +2,30 @@
DSTDIR=../../IMG/cpio/ventoy/busybox
rm -f vtchmod32 vtchmod64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64
rm -f vtchmod32 vtchmod64 vtchmod64_musl vtchmodaa64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64 $DSTDIR/vtchmodm64e
/opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32
/opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64
aarch64-linux-gcc -Os -static vtchmod.c -o vtchmodaa64
aarch64-linux-strip --strip-all vtchmodaa64
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -Os -static vtchmod.c -o vtchmodm64e
mips64el-linux-musl-strip --strip-all vtchmodm64e
gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static vtchmod.c -o vtchmod64_musl
strip --strip-all vtchmod64_musl
chmod 777 vtchmod32
chmod 777 vtchmod64
chmod 777 vtchmodaa64
chmod 777 vtchmod64_musl
chmod 777 vtchmodm64e
cp -a vtchmod32 $DSTDIR/
cp -a vtchmod64 $DSTDIR/
cp -a vtchmodaa64 $DSTDIR/
cp -a vtchmod64_musl $DSTDIR/
cp -a vtchmodm64e $DSTDIR/

Binary file not shown.

BIN
BUSYBOX/chmod/vtchmodaa64 Normal file

Binary file not shown.

BIN
BUSYBOX/chmod/vtchmodm64e Normal file

Binary file not shown.

1181
BUSYBOX/config Normal file

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/mips64el_ash.config Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/x86_64_ash.config Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/x86_64_xzcat.config Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,49 +1,70 @@
Build a static linked, small dmsetup tool
======== Source Code ========
use an old version of dmsetup
http://vault.centos.org/5.3/os/SRPMS/device-mapper-1.02.28-2.el5.src.rpm
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz
======== Build Envrioment ========
build for 32bit, static linked with dietlibc
1. install centos 6.10 i386 with CentOS-6.10-i386-bin-DVD1.iso
2. yum install gcc kernel-devel package
3. install dietc libc (just make && make install)
4. export PATH=$PATH:/opt/diet/bin
======== Build Step ========
1. extract device mapper source code
2. CC="diet gcc" ./configure --disable-nls --disable-selinux --disable-shared
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
--- add 2 defines as follow:
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifndef UINT64_C
#define UINT64_C(c) c ## ULL
#endif
4. make
5. strip dmsetup/dmsetup
6. get dmsetup/dmsetup as the dmsetup32 binary file
======================== Build for 64bit dmsetup =========================
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
1. extract device mapper source code
2. extract mini-native-x86_64.tar.bz2
3. chroot to mini-native-x86_64
3. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link
4. make
5. strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetup64 binary file
Build a static linked, small dmsetup tool
======== Source Code ========
use an old version of dmsetup
http://vault.centos.org/5.3/os/SRPMS/device-mapper-1.02.28-2.el5.src.rpm
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz
======== Build Envrioment ========
build for 32bit, static linked with dietlibc
1. install centos 6.10 i386 with CentOS-6.10-i386-bin-DVD1.iso
2. yum install gcc kernel-devel package
3. install dietc libc (just make && make install)
4. export PATH=$PATH:/opt/diet/bin
======== Build Step ========
1. extract device mapper source code
2. CC="diet gcc" ./configure --disable-nls --disable-selinux --disable-shared
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
--- add 2 defines as follow:
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifndef UINT64_C
#define UINT64_C(c) c ## ULL
#endif
4. make
5. strip dmsetup/dmsetup
6. get dmsetup/dmsetup as the dmsetup32 binary file
======================== Build for 64bit dmsetup =========================
1. extract device mapper source code
2. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link CC='gcc -specs /usr/local/musl/lib/musl-gcc.specs'
3. touch include/linux/limits.h include/linux/types.h
echo '#include <sys/mount.h>' > include/linux/fs.h
4. make
5. strip --strip-all dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetup64 binary file
======================== Build for arm64 dmsetup =========================
1. extract device mapper source code
2. ./configure CC=aarch64-linux-gcc --target=arm --host=x86_64-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
4. make
5. aarch64-linux-strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetupaa64 binary file
======================== Build for mips64 dmsetup =========================
1. extract device mapper source code
2. ./configure CC="mips64el-linux-musl-gcc -mips64r2 -mabi=64" --target=mips --host=x86_64-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
4. make
5. mips64el-linux-musl-strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetupm64e binary file

Binary file not shown.

BIN
DMSETUP/dmsetupaa64 Normal file

Binary file not shown.

BIN
DMSETUP/dmsetupm64e Normal file

Binary file not shown.

View File

@@ -1,228 +1,260 @@
==========================================
1. Compile Enviroment
==========================================
My build envrioment is CentOS 7.8 x86_64. So here I first explain how to create the build environment from scratch.
Because Ventoy is based on many open source projects, so the environment is important. I suggest you test it on a virtual machine first.
1.1 Install CentOS 7.8
I use CentOS-7-x86_64-Everything-2003.iso and select Minimal install
1.2 Install Packages
yum install \
libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \
mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \
libvirt* vte* NetworkManager-bluetooth brlapi fuse-devel dejavu* gnu-efi* pesign shim \
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static
==========================================
2. Download Source Code
==========================================
2.1 Download Ventoy source code from github and decompress it.
Next I assume that you have unzipped the code into the /home directory (check /home/Ventoy-master/README.md file for the directory level).
2.2 Download third-part source code
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz ===> /home/Ventoy-master/DOC/dietlibc-0.34.tar.xz
https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz ===> /home/Ventoy-master/GRUB2/grub-2.04.tar.xz
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
==========================================
3. All in one script
==========================================
I have made the whole build process in all_in_one.sh, you can run this script to build and pack ventoy.
If you want to compile a certain part separately, you can continue to refer to the later chapters of this text.
cd /home/Ventoy-master/INSTALL
sh all_in_one.sh
It should be noted that, some part of Ventoy has 32bit&64bit version (like 4.9 4.10 4.11 follows)
all_in_one.sh only build 64bit version of them, if you want to rebuild the 32bit verison. You should create a 32bit CentOS environment and build them.
Fortunately these parts are few modified, you only need to build once or you can directly use the binary I have built.
Besides, after a fully compile and pack, you can only build the part you modified (for example grub2) and run ventoy_pack.sh to generate the package.
==========================================
4. Build every part of Ventoy
==========================================
4.1 == Build grub2 ==
cd /home/Ventoy-master/GRUB2
sh buildgrub.sh
4.2 == Build ipxe.krn ==
cd /home/Ventoy-master/IPXE
sh buildipxe.sh
4.3 == Build Ventoy2Disk.exe ==
Ventoy2Disk.exe is the installer in Windows platform. And it must be built in Windows with Microsoft Visual Studio (2013+).
Open /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk.sln with Visual Studio and build it.
4.4 == Build vtoyjump64.exe/vtoyjump32.exe ==
vtoyjump64.exe/vtoyjump32.exe is used to mount iso file in windows PE. You should install Microsoft Visual Studio (2013+) to build it.
Open /home/Ventoy-master/vtoyjump/vtoyjump.sln with Visual Studio and build it (64&32).
4.5 == Build dmsetup ==
Please refer to DMSETUP/build.txt
4.6 == Build ventoy_x64.efi ==
cd /home/Ventoy-master/EDK2
sh buildedk.sh
4.7 == Build VtoyTool ==
cd /home/Ventoy-master/VtoyTool
sh build.sh
4.8 == Build vtoyfat ==
cd /home/Ventoy-master/vtoyfat/fat_io_lib
sh buildlib.sh
cd /home/Ventoy-master/vtoyfat
sh build.sh
4.9 == Build exfat-util ==
cd /home/Ventoy-master/ExFAT
sh buidlibfuse.sh
sh buidexfat.sh
After that, copy EXFAT/shared/mkexfatfs ===> /home/Ventoy-master/INSTALL/tool/mkexfatfs_64
After that, copy EXFAT/shared/mount.exfat-fuse ===> /home/Ventoy-master/INSTALL/tool/mount.exfat-fuse_64
Use the same build step to build exfat-util 32bit in a 32bit CentOS system and get mkexfatfs_32 and mount.exfat-fuse_32
4.10 == Build vtoy_fuse_iso_64/vtoy_fuse_iso_32 ==
cd /home/Ventoy-master/FUSEISO
sh build_libfuse.sh
sh build.sh
Use the same build step to build in a 32bit CentOS system and get vtoy_fuse_iso_32
4.11 == Build unsquashfs_64/unsquashfs_32 ==
cd /home/Ventoy-master/SQUASHFS/SRC
sh build_lz4.sh
sh build_lzma.sh
sh build_lzo.sh
sh build_zstd.sh
cd /home/Ventoy-master/SQUASHFS/squashfs-tools-4.4/squashfs-tools
sh build.sh
Use the same build step to build in a 32bit CentOS system and get unsquashfs_32
4.12 == Build vblade_64/vblade_32 ==
cd /home/Ventoy-master/VBLADE/vblade-master
sh build.sh
4.13 == Build zstdcat ==
Please refer to ZSTD/build.txt
4.14 == Build vtoy_gen_uuid ==
cd /home/Ventoy-master/GenUUID
sh build.sh
4.15 == Build xzminidec32 ==
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
make -f ventoy_makefile
strip --strip-all xzminidec
4.16 == Build xzminidec64 ==
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
make -f ventoy_makefile64
strip --strip-all xzminidec
4.17 == Build iso9660_x64.efi ==
This efi driver is from https://github.com/pbatard/efifs
Follow all the build instructions in this project. I modified 3 files (the original and modified source are at /home/Ventoy-master/EDK2/efiffs)
4.18 IMG/cpio/ventoy/busybox/64h
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
https://busybox.net/downloads/busybox-1.32.0.tar.bz2
use BUSYBOX/64h.config and uclibc to build busybox-1.32
4.19 == Build lunzip32/lunzip64 ==
http://mirror.yongbok.net/nongnu/lzip/lunzip/lunzip-1.11.tar.gz
PATH=$PATH:/opt/diet/bin
./configure --disable-nls CC='diet gcc -nostdinc'
make
strip --strip-all lunzip
==========================================
5. Binaries
==========================================
There some binaries in Ventoy install package. These files are downloaded from other open source project's website, such as busybox.
Here is the list of the binaries, their SHA-256 and the download urls:
5.1 IMG/cpio/ventoy/tool/lz4cat
https://create.stephan-brumme.com/smallz4 smallz4cat-x32-v1.4
SHA-256: 13d293ddeedb469f51da41167f79b2cbdb904e681716f6e6191b233dbb162438
5.2 IMG/cpio/ventoy/tool/ar
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_AR
SHA-256: f29b7d81a983c0c85d22496f4a833c18f2528a1b666eb7d47c93084c1ed66ae0
5.3 IMG/cpio/ventoy/tool/inotifyd
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_INOTIFYD
SHA-256: 3532162a8695e91a1ed9ddea28b2cb22259a90e93d5d9c4a517b6c36842c686f
5.4 IMG/cpio/ventoy/busybox/ash
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_ASH
SHA-256: 44a6274bca580c2758ffc173fc76d18bb855b1fe8dcf70efd9ee75cbd57dee97
5.5 IMG/cpio/ventoy/busybox/tmpxz
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_XZ
SHA-256: f6cdb6293680424c29b89bde0685ca27f455166c9b302cd6082ef90681456291
5.6 INSTALL/tool/xzcat
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_XZCAT
SHA-256: 7399db642c2beaf52a16ab5264ffc55cfd1ff5699a524f63e5d48edf84e20f44
5.7 INSTALL/tool/hexdump
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_HEXDUMP
SHA-256: cde08b6a2cf5ad914f05203e18e3f7c2ed6060a63604e3d75536f19b55e8e0af
5.8 imdisk
download http://www.ltr-data.se/files/imdiskinst.exe and extract it by 7zip.
INSTALL/ventoy/imdisk/64/imdisk.sys --> sys/amd64/imdisk.sys SHA-256: 6702202220268787e361f5a82dae53362c8e6c6dcd240bb01b44dd77ae0788da
INSTALL/ventoy/imdisk/64/imdisk.exe --> cli/amd64/imdisk.exe SHA-256: 9759175380af836869443e5f21ce2e33022125d154bc6b3d1c04dc36b190de04
INSTALL/ventoy/imdisk/64/imdisk.cpl --> cpl/amd64/imdisk.cpl SHA-256: aea2ebbea2b073c947263744962af8a3eab025ff4c9d825c543e380e738a4c99
INSTALL/ventoy/imdisk/32/imdisk.sys --> sys/i386/imdisk.sys SHA-256: a94caec2f71a924d6a914c093ad4b905d7cfdea3f515ed48aaa8c3950b2dc191
INSTALL/ventoy/imdisk/32/imdisk.exe --> cli/i386/imdisk.exe SHA-256: 33b53858e2139704cf603b115a3e5e1dfd4daeaaed4d3e03c633f2df3b55dbaa
INSTALL/ventoy/imdisk/32/imdisk.cpl --> cpl/i386/imdisk.cpl SHA-256: b781d3e2d286ac8bf548f44e50cbbb3fe78203296e41e4d2e73b407668f88f2d
5.9 INSTALL/ventoy/memdisk
https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz
decompress it and memdisk is at syslinux-6.03/bios/memdisk/memdisk
SHA-256: 3f6cd656b8a14109cd3f906fee2dd2e75418f983a5e1bfdb64f44f7765588cbb
5.10 UEFIinSecureBoot
https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases Super-UEFIinSecureBoot-Disk_minimal_v3.zip
unzip it and get Super-UEFIinSecureBoot-Disk_minimal.img, extract the img by 7zip.
INSTALL/EFI/BOOT/BOOTX64.EFI --> EFI/BOOT/BOOTX64.EFI SHA-256: 475552c7476ad45e42344eee8b30d44c264d200ac2468428aa86fc8795fb6e34
INSTALL/EFI/BOOT/grubx64.efi --> EFI/BOOT/grubx64.efi SHA-256: 25d858157349dc52fa70f3cdf5c62fe1e0bae37ddfc3a6b6528af9a3c745775f
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
5.11 INSTALL/tool/ash
https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/ busybox_ASH
SHA-256: 2943f02f85fee0c9551aec47110a558a73f919c032b3c51e56d6f197b5ec4d7b
5.12 7za.exe
download from https://www.7-zip.org/a/7z1900-extra.7z
ISNTALL/ventoy/7z/64/7za.exe SHA-256: 8117e40ee7f824f63373a4f5625bb62749f69159d0c449b3ce2f35aad3b83549
ISNTALL/ventoy/7z/32/7za.exe SHA-256: ea308c76a2f927b160a143d94072b0dce232e04b751f0c6432a94e05164e716d
==========================================
1. Compile Enviroment
==========================================
My build envrioment is CentOS 7.8 x86_64. So here I first explain how to create the build environment from scratch.
Because Ventoy is based on many open source projects, so the environment is important. I suggest you test it on a virtual machine firstly.
1.1 Install CentOS 7.8
I use CentOS-7-x86_64-Everything-2003.iso and select Minimal install
1.2 Install Packages
yum install \
libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \
mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \
libvirt* vte* NetworkManager-bluetooth brlapi fuse-devel dejavu* gnu-efi* pesign shim \
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static xorriso
==========================================
2. Download Source Code
==========================================
2.1 Download Ventoy source code from github and decompress it.
Next I assume that you have unzipped the code into the /home directory (check /home/Ventoy-master/README.md file for the directory layout).
2.2 Download third-part source code and tool
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz ===> /home/Ventoy-master/DOC/dietlibc-0.34.tar.xz
https://musl.libc.org/releases/musl-1.2.1.tar.gz ===> /home/Ventoy-master/DOC/musl-1.2.1.tar.gz
https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz ===> /home/Ventoy-master/GRUB2/grub-2.04.tar.xz
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz ===> /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--uclibc--stable-2020.08-1.tar.bz2 ===> /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2
http://ftp.loongnix.org/toolchain/gcc/release/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz ===> /opt/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz
https://github.com/ventoy/musl-cross-make/releases/download/latest/output.tar.bz2 ===> /opt/output.tar.bz2
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/vmlinuz64 ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/vmlinuz64
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/corepure64.gz ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/corepure64.gz
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/modules64.gz ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/modules64.gz
2.3 Prepare third-part tools
cd /home/Ventoy-master/DOC/
tar xf musl-1.2.1.tar.gz
cd musl-1.2.1
./configure && make install
tar xf /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt
tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt
tar xf /opt/output.tar.bz2 -C /opt
mv /opt/output /opt/mips64el-linux-musl-gcc730
2.4 Set PATH envrioment
export PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:/opt/aarch64--uclibc--stable-2020.08-1/bin:/opt/mips64el-linux-musl-gcc730/bin
better to add this line to /root/.bashrc and relogin as root
==========================================
3. All in one script
==========================================
I have made a all_in_one.sh, you can run this script to build and pack ventoy.
If you want to compile a certain part separately, you can continue to refer to the later chapters of this text.
cd /home/Ventoy-master/INSTALL
sh all_in_one.sh
It should be noted that:
1. Only grub2/EDK2/IPXE will be recompiled in all_in_one.sh. Other part contains the binaries and are few modified, so will no be recompiled everytime.
You can rebuild these parts separately if you want.
2. some part of Ventoy has 32bit&64bit version (like 4.9 4.10 4.11 follows)
all_in_one.sh only build 64bit version of them, if you want to rebuild the 32bit verison. You should create a 32bit CentOS environment and build them.
Fortunately these parts are few modified, you only need to build once or you can directly use the binary I have built.
Besides, after a fully compile and pack, you can only build the part you modified (for example grub2) and run ventoy_pack.sh to generate the package.
==========================================
4. Build every part of Ventoy
==========================================
4.1 == Build grub2 ==
cd /home/Ventoy-master/GRUB2
sh buildgrub.sh
4.2 == Build ipxe.krn ==
cd /home/Ventoy-master/IPXE
sh buildipxe.sh
4.3 == Build Ventoy2Disk.exe ==
Ventoy2Disk.exe is the installer in Windows platform. And it must be built in Windows with Microsoft Visual Studio (2013+).
Open /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk.sln with Visual Studio and build it.
4.4 == Build vtoyjump64.exe/vtoyjump32.exe ==
vtoyjump64.exe/vtoyjump32.exe is used to mount iso file in windows PE. You should install Microsoft Visual Studio (2013+) to build it.
Open /home/Ventoy-master/vtoyjump/vtoyjump.sln with Visual Studio and build it (64&32).
4.5 == Build dmsetup ==
Please refer to DMSETUP/build.txt
4.6 == Build ventoy_x64.efi ==
cd /home/Ventoy-master/EDK2
sh buildedk.sh
4.7 == Build VtoyTool ==
cd /home/Ventoy-master/VtoyTool
sh build.sh
4.8 == Build vtoyfat ==
cd /home/Ventoy-master/vtoyfat/fat_io_lib
sh buildlib.sh
cd /home/Ventoy-master/vtoyfat
sh build.sh
4.9 == Build exfat-util ==
cd /home/Ventoy-master/ExFAT
sh buidlibfuse.sh
sh buidexfat.sh
After that, copy EXFAT/shared/mkexfatfs ===> /home/Ventoy-master/INSTALL/tool/mkexfatfs_64
After that, copy EXFAT/shared/mount.exfat-fuse ===> /home/Ventoy-master/INSTALL/tool/mount.exfat-fuse_64
Use the same build step to build exfat-util 32bit in a 32bit CentOS system and get mkexfatfs_32 and mount.exfat-fuse_32
4.10 == Build vtoy_fuse_iso_64/vtoy_fuse_iso_32 ==
cd /home/Ventoy-master/FUSEISO
sh build_libfuse.sh
sh build.sh
Use the same build step to build in a 32bit CentOS system and get vtoy_fuse_iso_32
4.11 == Build unsquashfs_64/unsquashfs_32 ==
cd /home/Ventoy-master/SQUASHFS/SRC
sh build_lz4.sh
sh build_lzma.sh
sh build_lzo.sh
sh build_zstd.sh
cd /home/Ventoy-master/SQUASHFS/squashfs-tools-4.4/squashfs-tools
sh build.sh
Use the same build step to build in a 32bit CentOS system and get unsquashfs_32
4.12 == Build vblade_64/vblade_32 ==
cd /home/Ventoy-master/VBLADE/vblade-master
sh build.sh
4.13 == Build zstdcat ==
Please refer to ZSTD/build.txt
4.14 == Build vtoy_gen_uuid ==
cd /home/Ventoy-master/GenUUID
sh build.sh
4.15 == Build xzminidec32 ==
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
make -f ventoy_makefile
strip --strip-all xzminidec
4.16 == Build xzminidec64 ==
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
make -f ventoy_makefile64
strip --strip-all xzminidec
4.17 == Build iso9660_x64.efi ==
This efi driver is from https://github.com/pbatard/efifs
Follow all the build instructions in this project. I modified 3 files (the original and modified source are at /home/Ventoy-master/EDK2/efiffs)
4.18 IMG/cpio/ventoy/busybox/64h
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
https://busybox.net/downloads/busybox-1.32.0.tar.bz2
use BUSYBOX/x86_64_ash.config and uclibc to build busybox-1.32
4.19 == Build lunzip32/lunzip64 ==
http://mirror.yongbok.net/nongnu/lzip/lunzip/lunzip-1.11.tar.gz
PATH=$PATH:/opt/diet/bin
./configure --disable-nls CC='diet gcc -nostdinc'
make
strip --strip-all lunzip
#aarch64
./configure --disable-nls CC='aarch64-buildroot-linux-uclibc-gcc -static'
make
aarch64-buildroot-linux-uclibc-strip --strip-all lunzip
==========================================
5. Binaries
==========================================
There some binaries in Ventoy install package. These files are downloaded from other open source project's website, such as busybox.
Here is the list of the binaries, their SHA-256 and the download urls:
5.1 IMG/cpio/ventoy/tool/lz4cat
https://create.stephan-brumme.com/smallz4 smallz4cat-x32-v1.4
SHA-256: 13d293ddeedb469f51da41167f79b2cbdb904e681716f6e6191b233dbb162438
5.2 IMG/cpio/ventoy/tool/ar
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_AR
SHA-256: f29b7d81a983c0c85d22496f4a833c18f2528a1b666eb7d47c93084c1ed66ae0
5.3 IMG/cpio/ventoy/tool/inotifyd
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_INOTIFYD
SHA-256: 3532162a8695e91a1ed9ddea28b2cb22259a90e93d5d9c4a517b6c36842c686f
5.4 IMG/cpio/ventoy/busybox/ash
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_ASH
SHA-256: 44a6274bca580c2758ffc173fc76d18bb855b1fe8dcf70efd9ee75cbd57dee97
5.5 IMG/cpio/ventoy/busybox/tmpxz
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_XZ
SHA-256: f6cdb6293680424c29b89bde0685ca27f455166c9b302cd6082ef90681456291
5.6 INSTALL/tool/i386/xzcat
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_XZCAT
SHA-256: 7399db642c2beaf52a16ab5264ffc55cfd1ff5699a524f63e5d48edf84e20f44
5.7 INSTALL/tool/i386/hexdump
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_HEXDUMP
SHA-256: cde08b6a2cf5ad914f05203e18e3f7c2ed6060a63604e3d75536f19b55e8e0af
5.8 imdisk
download http://www.ltr-data.se/files/imdiskinst.exe and extract it by 7zip.
INSTALL/ventoy/imdisk/64/imdisk.sys --> sys/amd64/imdisk.sys SHA-256: 6702202220268787e361f5a82dae53362c8e6c6dcd240bb01b44dd77ae0788da
INSTALL/ventoy/imdisk/64/imdisk.exe --> cli/amd64/imdisk.exe SHA-256: 9759175380af836869443e5f21ce2e33022125d154bc6b3d1c04dc36b190de04
INSTALL/ventoy/imdisk/64/imdisk.cpl --> cpl/amd64/imdisk.cpl SHA-256: aea2ebbea2b073c947263744962af8a3eab025ff4c9d825c543e380e738a4c99
INSTALL/ventoy/imdisk/32/imdisk.sys --> sys/i386/imdisk.sys SHA-256: a94caec2f71a924d6a914c093ad4b905d7cfdea3f515ed48aaa8c3950b2dc191
INSTALL/ventoy/imdisk/32/imdisk.exe --> cli/i386/imdisk.exe SHA-256: 33b53858e2139704cf603b115a3e5e1dfd4daeaaed4d3e03c633f2df3b55dbaa
INSTALL/ventoy/imdisk/32/imdisk.cpl --> cpl/i386/imdisk.cpl SHA-256: b781d3e2d286ac8bf548f44e50cbbb3fe78203296e41e4d2e73b407668f88f2d
5.9 INSTALL/ventoy/memdisk
https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz
decompress it and memdisk is at syslinux-6.03/bios/memdisk/memdisk
SHA-256: 3f6cd656b8a14109cd3f906fee2dd2e75418f983a5e1bfdb64f44f7765588cbb
5.10 UEFIinSecureBoot
https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases Super-UEFIinSecureBoot-Disk_minimal_v3.zip
unzip it and get Super-UEFIinSecureBoot-Disk_minimal.img, extract the img by 7zip.
INSTALL/EFI/BOOT/BOOTX64.EFI --> EFI/BOOT/BOOTX64.EFI SHA-256: 475552c7476ad45e42344eee8b30d44c264d200ac2468428aa86fc8795fb6e34
INSTALL/EFI/BOOT/grubx64.efi --> EFI/BOOT/grubx64.efi SHA-256: 25d858157349dc52fa70f3cdf5c62fe1e0bae37ddfc3a6b6528af9a3c745775f
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
5.11 INSTALL/tool/ash
https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/ busybox_ASH
SHA-256: 2943f02f85fee0c9551aec47110a558a73f919c032b3c51e56d6f197b5ec4d7b
5.12 7za.exe
download from https://www.7-zip.org/a/7z1900-extra.7z
ISNTALL/ventoy/7z/64/7za.exe SHA-256: 8117e40ee7f824f63373a4f5625bb62749f69159d0c449b3ce2f35aad3b83549
ISNTALL/ventoy/7z/32/7za.exe SHA-256: ea308c76a2f927b160a143d94072b0dce232e04b751f0c6432a94e05164e716d

9
DOC/prepare_env.sh Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
#[ -d /opt/diet64 ] || sh ./installdietlibc.sh
[ -d /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu ] || tar xf /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt
[ -d /opt/aarch64--uclibc--stable-2020.08-1 ] || tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt
[ -d /opt/mips-loongson-gcc7.3-linux-gnu ] || tar xf /opt/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz -C /opt

View File

@@ -1,17 +1,10 @@
FROM centos:7
RUN yum -y install \
RUN yum -y -q install \
libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \
mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
mpfr.i686 mpfr-devel.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \
libvirt* vte* NetworkManager-bluetooth brlapi fuse-devel dejavu* gnu-efi* pesign shim \
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static
CMD cd /ventoy \
&& wget -P DOC/ https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz \
&& wget -P GRUB2/ https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz \
&& wget -O EDK2/edk2-edk2-stable201911.zip https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 \
&& wget -O ExFAT/exfat-1.3.0.zip https://codeload.github.com/relan/exfat/zip/v1.3.0 \
&& wget -O ExFAT/libfuse-fuse-2.9.9.zip https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 \
&& cd INSTALL && ls -la && sh all_in_one.sh
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static xorriso
CMD cd /ventoy/INSTALL && ls -la && sh docker_ci_build.sh

59
EDK2/build.sh Normal file
View File

@@ -0,0 +1,59 @@
#!/bin/sh
if [ -z "$1" ]; then
EDKARCH=X64
postfix=x64
elif [ "$1" = "ia32" ]; then
EDKARCH=IA32
postfix=ia32
shift
elif [ "$1" = "aa64" ]; then
EDKARCH=AARCH64
postfix=aa64
shift
fi
cd edk2-edk2-stable201911
rm -rf ./Conf/.cache
rm -f ./Conf/.AutoGenIdFile.txt
VTEFI_PATH=Build/MdeModule/RELEASE_GCC48/$EDKARCH/MdeModulePkg/Application/Ventoy/Ventoy/OUTPUT/Ventoy.efi
DST_PATH=../../INSTALL/ventoy/ventoy_${postfix}.efi
VTEFI_PATH2=Build/MdeModule/RELEASE_GCC48/$EDKARCH/MdeModulePkg/Application/VtoyUtil/VtoyUtil/OUTPUT/VtoyUtil.efi
DST_PATH2=../../INSTALL/ventoy/vtoyutil_${postfix}.efi
VTEFI_PATH3=Build/MdeModule/RELEASE_GCC48/$EDKARCH/MdeModulePkg/Application/VDiskChain/VDiskChain/OUTPUT/VDiskChain.efi
DST_PATH3=../../VDiskChain/Tool/vdiskchain_${postfix}.efi
rm -f $VTEFI_PATH
rm -f $DST_PATH
rm -f $VTEFI_PATH2
rm -f $DST_PATH2
rm -f $VTEFI_PATH3
[ -d ../../VDiskChain ] && rm -f $DST_PATH3
unset WORKSPACE
source ./edksetup.sh
if [ "$EDKARCH" = "AARCH64" ]; then
GCC48_AARCH64_PREFIX=aarch64-linux-gnu- \
build -p MdeModulePkg/MdeModulePkg.dsc -a $EDKARCH -b RELEASE -t GCC48
else
build -p MdeModulePkg/MdeModulePkg.dsc -a $EDKARCH -b RELEASE -t GCC48
fi
if [ -e $VTEFI_PATH ] && [ -e $VTEFI_PATH2 ] && [ -e $VTEFI_PATH3 ]; then
echo -e '\n\n====================== SUCCESS ========================\n\n'
cp -a $VTEFI_PATH $DST_PATH
cp -a $VTEFI_PATH2 $DST_PATH2
[ -d ../../VDiskChain ] && cp -a $VTEFI_PATH3 $DST_PATH3
cd ..
else
echo -e '\n\n====================== FAILED ========================\n\n'
cd ..
exit 1
fi

View File

@@ -2,32 +2,20 @@
rm -rf edk2-edk2-stable201911
unzip edk2-edk2-stable201911.zip
unzip edk2-edk2-stable201911.zip > /dev/null
/bin/cp -a ./edk2_mod/edk2-edk2-stable201911 ./
cd edk2-edk2-stable201911
VTEFI_PATH=Build/MdeModule/RELEASE_GCC48/X64/MdeModulePkg/Application/Ventoy/Ventoy/OUTPUT/Ventoy.efi
DST_PATH=../../INSTALL/ventoy/ventoy_x64.efi
rm -f $VTEFI_PATH
rm -f $DST_PATH
make -j 4 -C BaseTools/
cd ..
source ./edksetup.sh
build -p MdeModulePkg/MdeModulePkg.dsc -a X64 -b RELEASE -t GCC48
if [ -e $VTEFI_PATH ]; then
echo -e '\n\n====================== SUCCESS ========================\n\n'
cp -a $VTEFI_PATH $DST_PATH
cd ..
else
echo -e '\n\n====================== FAILED ========================\n\n'
cd ..
exit 1
fi
echo '======== build EDK2 for i386-efi ==============='
sh ./build.sh ia32 || exit 1
echo '======== build EDK2 for arm64-efi ==============='
sh ./build.sh aa64 || exit 1
echo '======== build EDK2 for x86_64-efi ==============='
sh ./build.sh || exit 1

View File

@@ -0,0 +1,466 @@
/******************************************************************************
* VDiskChain.c
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiDecompressLib.h>
#include <Protocol/LoadedImage.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemInfo.h>
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <VDiskChain.h>
BOOLEAN gVDiskDebugPrint = FALSE;
vdisk_block_data gVDiskBlockData;
/* Boot filename */
CONST CHAR16 *gEfiBootFileName[] =
{
L"@",
EFI_REMOVABLE_MEDIA_FILE_NAME,
#if defined (MDE_CPU_IA32)
L"\\EFI\\BOOT\\GRUBIA32.EFI",
L"\\EFI\\BOOT\\BOOTia32.EFI",
L"\\EFI\\BOOT\\bootia32.efi",
L"\\efi\\boot\\bootia32.efi",
#elif defined (MDE_CPU_X64)
L"\\EFI\\BOOT\\GRUBX64.EFI",
L"\\EFI\\BOOT\\BOOTx64.EFI",
L"\\EFI\\BOOT\\bootx64.efi",
L"\\efi\\boot\\bootx64.efi",
#elif defined (MDE_CPU_ARM)
L"\\EFI\\BOOT\\GRUBARM.EFI",
L"\\EFI\\BOOT\\BOOTarm.EFI",
L"\\EFI\\BOOT\\bootarm.efi",
L"\\efi\\boot\\bootarm.efi",
#elif defined (MDE_CPU_AARCH64)
L"\\EFI\\BOOT\\GRUBAA64.EFI",
L"\\EFI\\BOOT\\BOOTaa64.EFI",
L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi",
#endif
};
UINT8 *g_disk_buf_addr = NULL;
UINT64 g_disk_buf_size = 0;
STATIC EFI_GET_VARIABLE g_org_get_variable = NULL;
STATIC EFI_EXIT_BOOT_SERVICES g_org_exit_boot_service = NULL;
VOID EFIAPI VDiskDebug(IN CONST CHAR8 *Format, ...)
{
VA_LIST Marker;
CHAR16 Buffer[512];
VA_START (Marker, Format);
UnicodeVSPrintAsciiFormat(Buffer, sizeof(Buffer), Format, Marker);
VA_END (Marker);
gST->ConOut->OutputString(gST->ConOut, Buffer);
}
VOID EFIAPI vdisk_clear_input(VOID)
{
EFI_INPUT_KEY Key;
gST->ConIn->Reset(gST->ConIn, FALSE);
while (EFI_SUCCESS == gST->ConIn->ReadKeyStroke(gST->ConIn, &Key))
{
;
}
gST->ConIn->Reset(gST->ConIn, FALSE);
}
STATIC EFI_STATUS EFIAPI vdisk_load_image
(
IN EFI_HANDLE ImageHandle,
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
IN CONST CHAR16 *FileName,
IN UINTN FileNameLen,
OUT EFI_HANDLE *Image
)
{
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 TmpBuf[256] = {0};
FILEPATH_DEVICE_PATH *pFilePath = NULL;
EFI_DEVICE_PATH_PROTOCOL *pImgPath = NULL;
pFilePath = (FILEPATH_DEVICE_PATH *)TmpBuf;
pFilePath->Header.Type = MEDIA_DEVICE_PATH;
pFilePath->Header.SubType = MEDIA_FILEPATH_DP;
pFilePath->Header.Length[0] = FileNameLen + sizeof(EFI_DEVICE_PATH_PROTOCOL);
pFilePath->Header.Length[1] = 0;
CopyMem(pFilePath->PathName, FileName, FileNameLen);
pImgPath = AppendDevicePathNode(pDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)pFilePath);
if (!pImgPath)
{
return EFI_NOT_FOUND;
}
Status = gBS->LoadImage(FALSE, ImageHandle, pImgPath, NULL, 0, Image);
debug("Load Image File %r DP: <%s>", Status, ConvertDevicePathToText(pImgPath, FALSE, FALSE));
FreePool(pImgPath);
return Status;
}
STATIC EFI_STATUS EFIAPI vdisk_decompress_vdisk(IN EFI_LOADED_IMAGE_PROTOCOL *pImageInfo)
{
UINT32 Size;
UINT32 DestinationSize;
UINT32 ScratchSize;
UINT8 *buf;
VOID *ScratchBuf;
EFI_STATUS Status = EFI_SUCCESS;
(VOID)pImageInfo;
vdisk_get_vdisk_raw(&buf, &Size);
UefiDecompressGetInfo(buf + VDISK_MAGIC_LEN, Size - VDISK_MAGIC_LEN, &DestinationSize, &ScratchSize);
debug("vdisk: size:%u realsize:%u", Size, DestinationSize);
g_disk_buf_size = DestinationSize;
g_disk_buf_addr = AllocatePool(DestinationSize);
ScratchBuf = AllocatePool(ScratchSize);
Status = UefiDecompress(buf + VDISK_MAGIC_LEN, g_disk_buf_addr, ScratchBuf);
FreePool(ScratchBuf);
debug("Status:%r %p %u", Status, g_disk_buf_addr, (UINT32)g_disk_buf_size);
return EFI_SUCCESS;
}
STATIC EFI_STATUS vdisk_patch_vdisk_path(CHAR16 *pos)
{
UINTN i;
UINTN j;
CHAR16 *end;
CHAR8 *buf = (char *)g_disk_buf_addr;
if (*pos == L'\"')
{
pos++;
}
end = StrStr(pos, L".vtoy");
end += 5;//string length
for (i = 0; i < g_disk_buf_size; i++)
{
if (*(UINT32 *)(buf + i) == 0x59595959)
{
for (j = 0; j < 300; j++)
{
if (buf[i + j] != 'Y')
{
break;
}
}
if (j >= 300)
{
break;
}
}
}
if (i >= g_disk_buf_size)
{
debug("No need to fill vdisk path");
return 0;
}
debug("Fill vdisk path at %d", i);
while (pos != end)
{
buf[i++] = (CHAR8)(*pos++);
}
buf[i++] = '\"';
while (buf[i] == 'Y' || buf[i] == '\"')
{
buf[i] = ' ';
i++;
}
return 0;
}
EFI_STATUS EFIAPI vdisk_get_variable_wrapper
(
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes, OPTIONAL
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
)
{
EFI_STATUS Status = EFI_SUCCESS;
Status = g_org_get_variable(VariableName, VendorGuid, Attributes, DataSize, Data);
if (StrCmp(VariableName, L"SecureBoot") == 0)
{
if ((*DataSize == 1) && Data)
{
*(UINT8 *)Data = 0;
}
}
return Status;
}
EFI_STATUS EFIAPI vdisk_exit_boot_service_wrapper
(
IN EFI_HANDLE ImageHandle,
IN UINTN MapKey
)
{
return g_org_exit_boot_service(ImageHandle, MapKey);
}
STATIC EFI_STATUS EFIAPI vdisk_disable_secure_boot(IN EFI_HANDLE ImageHandle)
{
/* step1: wrapper security protocol. */
/* Do we still need it since we have been loaded ? */
/* step2: fake SecureBoot variable */
g_org_exit_boot_service = gBS->ExitBootServices;
gBS->ExitBootServices = vdisk_exit_boot_service_wrapper;
g_org_get_variable = gRT->GetVariable;
gRT->GetVariable = vdisk_get_variable_wrapper;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI vdisk_parse_cmdline(IN EFI_HANDLE ImageHandle)
{
CHAR16 *Pos = NULL;
CHAR16 *pCmdLine = NULL;
EFI_STATUS Status = EFI_SUCCESS;
EFI_LOADED_IMAGE_PROTOCOL *pImageInfo = NULL;
Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&pImageInfo);
if (EFI_ERROR(Status))
{
VDiskDebug("Failed to handle load image protocol %r\n", Status);
return Status;
}
pCmdLine = (CHAR16 *)AllocatePool(pImageInfo->LoadOptionsSize + 4);
SetMem(pCmdLine, pImageInfo->LoadOptionsSize + 4, 0);
CopyMem(pCmdLine, pImageInfo->LoadOptions, pImageInfo->LoadOptionsSize);
if (StrStr(pCmdLine, L"debug"))
{
gVDiskDebugPrint = TRUE;
}
debug("cmdline:<%s>", pCmdLine);
vdisk_debug_pause();
Pos = StrStr(pCmdLine, L"vdisk=");
if (NULL == Pos || NULL == StrStr(pCmdLine, L".vtoy"))
{
VDiskDebug("vdisk parameter not found!\n");
return EFI_NOT_FOUND;
}
vdisk_decompress_vdisk(pImageInfo);
vdisk_patch_vdisk_path(Pos + 6);
if (StrStr(pCmdLine, L"secureboot=off"))
{
vdisk_disable_secure_boot(ImageHandle);
}
FreePool(pCmdLine);
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI vdisk_boot(IN EFI_HANDLE ImageHandle)
{
UINTN t = 0;
UINTN i = 0;
UINTN j = 0;
UINTN Find = 0;
UINTN Count = 0;
EFI_HANDLE Image = NULL;
EFI_HANDLE *Handles = NULL;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevPath = NULL;
for (t = 0; t < 3; t++)
{
Count = 0;
Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
debug("vdisk_boot fs count:%u", Count);
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&pFile);
if (EFI_ERROR(Status))
{
continue;
}
debug("FS:%u Protocol:%p OpenVolume:%p", i, pFile, pFile->OpenVolume);
Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&pDevPath,
ImageHandle,
Handles[i],
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(Status))
{
debug("Failed to open device path protocol %r", Status);
continue;
}
debug("Handle:%p FS DP: <%s>", Handles[i], ConvertDevicePathToText(pDevPath, FALSE, FALSE));
if (CompareMem(gVDiskBlockData.Path, pDevPath, gVDiskBlockData.DevicePathCompareLen))
{
debug("Not ventoy disk file system");
continue;
}
for (j = 1; j < ARRAY_SIZE(gEfiBootFileName); j++)
{
Status = vdisk_load_image(ImageHandle, pDevPath, gEfiBootFileName[j],
StrSize(gEfiBootFileName[j]), &Image);
if (EFI_SUCCESS == Status)
{
break;
}
debug("Failed to load image %r <%s>", Status, gEfiBootFileName[j]);
}
if (j >= ARRAY_SIZE(gEfiBootFileName))
{
continue;
}
Find++;
debug("Find boot file, now try to boot .....");
vdisk_debug_pause();
if (gVDiskDebugPrint)
{
gST->ConIn->Reset(gST->ConIn, FALSE);
}
/* can't add debug print here */
//ventoy_wrapper_system();
Status = gBS->StartImage(Image, NULL, NULL);
if (EFI_ERROR(Status))
{
debug("Failed to start image %r", Status);
sleep(3);
gBS->UnloadImage(Image);
break;
}
}
FreePool(Handles);
if (Find == 0)
{
debug("Fs not found, now wait and retry...");
sleep(2);
}
}
if (Find == 0)
{
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI VDiskChainEfiMain
(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status = EFI_SUCCESS;
gST->ConOut->ClearScreen(gST->ConOut);
vdisk_clear_input();
Status = vdisk_parse_cmdline(ImageHandle);
if (EFI_ERROR(Status))
{
return Status;
}
vdisk_install_blockio(ImageHandle, g_disk_buf_size);
vdisk_debug_pause();
Status = vdisk_boot(ImageHandle);
gBS->DisconnectController(gVDiskBlockData.Handle, NULL, NULL);
gBS->UninstallMultipleProtocolInterfaces(gVDiskBlockData.Handle,
&gEfiBlockIoProtocolGuid, &gVDiskBlockData.BlockIo,
&gEfiDevicePathProtocolGuid, gVDiskBlockData.Path,
NULL);
if (EFI_NOT_FOUND == Status)
{
gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC L"!\r\n");
sleep(30);
}
vdisk_clear_input();
gST->ConOut->ClearScreen(gST->ConOut);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,97 @@
/******************************************************************************
* VDiskChain.h
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __VENTOY_H__
#define __VENTOY_H__
#define VDISK_MAGIC_LEN 32
#define VDISK_BLOCK_DEVICE_PATH_GUID \
{ 0x6ed2134e, 0xc2ea, 0x4943, { 0x99, 0x54, 0xa7, 0x76, 0xe5, 0x9c, 0x12, 0xc3 }}
#define VDISK_BLOCK_DEVICE_PATH_NAME L"vdisk"
#if defined (MDE_CPU_IA32)
#define VENTOY_UEFI_DESC L"IA32 UEFI"
#elif defined (MDE_CPU_X64)
#define VENTOY_UEFI_DESC L"X64 UEFI"
#elif defined (MDE_CPU_EBC)
#elif defined (MDE_CPU_ARM)
#define VENTOY_UEFI_DESC L"ARM UEFI"
#elif defined (MDE_CPU_AARCH64)
#define VENTOY_UEFI_DESC L"ARM64 UEFI"
#else
#error Unknown Processor Type
#endif
typedef struct vdisk_block_data
{
EFI_HANDLE Handle;
EFI_BLOCK_IO_MEDIA Media; /* Media descriptor */
EFI_BLOCK_IO_PROTOCOL BlockIo; /* Block I/O protocol */
UINTN DevicePathCompareLen;
EFI_DEVICE_PATH_PROTOCOL *Path; /* Device path protocol */
EFI_HANDLE RawBlockIoHandle;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo;
EFI_DEVICE_PATH_PROTOCOL *pDiskDevPath;
/* ventoy disk part2 ESP */
EFI_HANDLE DiskFsHandle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pDiskFs;
EFI_DEVICE_PATH_PROTOCOL *pDiskFsDevPath;
EFI_HANDLE IsoDriverImage;
}vdisk_block_data;
#define debug(expr, ...) if (gVDiskDebugPrint) VDiskDebug("[VDISK] "expr"\r\n", ##__VA_ARGS__)
#define trace(expr, ...) VDiskDebug("[VDISK] "expr"\r\n", ##__VA_ARGS__)
#define sleep(sec) gBS->Stall(1000000 * (sec))
#define vdisk_debug_pause() \
if (gVDiskDebugPrint) \
{ \
UINTN __Index = 0; \
gST->ConOut->OutputString(gST->ConOut, L"[VDISK] ###### Press Enter to continue... ######\r\n");\
gST->ConIn->Reset(gST->ConIn, FALSE); \
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &__Index);\
}
extern BOOLEAN gVDiskDebugPrint;
VOID EFIAPI VDiskDebug(IN CONST CHAR8 *Format, ...);
EFI_STATUS EFIAPI vdisk_block_io_read
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
);
extern UINT8 *g_disk_buf_addr;
extern UINT64 g_disk_buf_size;
extern vdisk_block_data gVDiskBlockData;
EFI_STATUS EFIAPI vdisk_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize);
int vdisk_get_vdisk_raw(UINT8 **buf, UINT32 *size);
#endif

View File

@@ -0,0 +1,82 @@
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = VDiskChain
FILE_GUID = 5bce96e3-ba11-4440-833b-299cf5849193
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = VDiskChainEfiMain
[Sources]
VDiskChain.h
VDiskChain.c
VDiskRawData.c
VDiskChainProtocol.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
ShellPkg/ShellPkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
DebugLib
UefiDecompressLib
[Guids]
gShellVariableGuid
gEfiVirtualCdGuid
gEfiFileInfoGuid
[Protocols]
gEfiLoadedImageProtocolGuid
gEfiBlockIoProtocolGuid
gEfiDevicePathProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiRamDiskProtocolGuid
gEfiAbsolutePointerProtocolGuid
gEfiAcpiTableProtocolGuid
gEfiBlockIo2ProtocolGuid
gEfiBusSpecificDriverOverrideProtocolGuid
gEfiComponentNameProtocolGuid
gEfiComponentName2ProtocolGuid
gEfiDriverBindingProtocolGuid
gEfiDiskIoProtocolGuid
gEfiDiskIo2ProtocolGuid
gEfiGraphicsOutputProtocolGuid
gEfiHiiConfigAccessProtocolGuid
gEfiHiiFontProtocolGuid
gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid
gEfiLoadedImageProtocolGuid
gEfiLoadedImageDevicePathProtocolGuid
gEfiPciIoProtocolGuid
gEfiSerialIoProtocolGuid
gEfiSimpleTextInProtocolGuid
gEfiSimpleTextInputExProtocolGuid
gEfiSimpleTextOutProtocolGuid

View File

@@ -0,0 +1,264 @@
/******************************************************************************
* VDiskChainProtocol.c
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Protocol/LoadedImage.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemInfo.h>
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <VDiskChain.h>
/* EFI block device vendor device path GUID */
EFI_GUID gVDiskBlockDevicePathGuid = VDISK_BLOCK_DEVICE_PATH_GUID;
EFI_STATUS EFIAPI vdisk_block_io_reset
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
(VOID)This;
(VOID)ExtendedVerification;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI vdisk_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL *This)
{
(VOID)This;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI vdisk_block_io_read
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
(VOID)This;
(VOID)MediaId;
debug("vdisk_block_io_read %lu %lu\n", Lba, BufferSize / 512);
CopyMem(Buffer, g_disk_buf_addr + (Lba * 512), BufferSize);
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI vdisk_block_io_write
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
(VOID)This;
(VOID)MediaId;
(VOID)Buffer;
debug("vdisk_block_io_read %lu %lu\n", Lba, BufferSize / 512);
return EFI_WRITE_PROTECTED;
}
EFI_STATUS EFIAPI vdisk_fill_device_path(VOID)
{
UINTN NameLen = 0;
UINT8 TmpBuf[128] = {0};
VENDOR_DEVICE_PATH *venPath = NULL;
venPath = (VENDOR_DEVICE_PATH *)TmpBuf;
NameLen = StrSize(VDISK_BLOCK_DEVICE_PATH_NAME);
venPath->Header.Type = HARDWARE_DEVICE_PATH;
venPath->Header.SubType = HW_VENDOR_DP;
venPath->Header.Length[0] = sizeof(VENDOR_DEVICE_PATH) + NameLen;
venPath->Header.Length[1] = 0;
CopyMem(&venPath->Guid, &gVDiskBlockDevicePathGuid, sizeof(EFI_GUID));
CopyMem(venPath + 1, VDISK_BLOCK_DEVICE_PATH_NAME, NameLen);
gVDiskBlockData.Path = AppendDevicePathNode(NULL, (EFI_DEVICE_PATH_PROTOCOL *)TmpBuf);
gVDiskBlockData.DevicePathCompareLen = sizeof(VENDOR_DEVICE_PATH) + NameLen;
debug("gVDiskBlockData.Path=<%s>\n", ConvertDevicePathToText(gVDiskBlockData.Path, FALSE, FALSE));
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI vdisk_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST CHAR16 *DrvName)
{
UINTN i = 0;
UINTN Count = 0;
CHAR16 *DriverName = NULL;
EFI_HANDLE *Handles = NULL;
EFI_HANDLE DrvHandles[2] = { NULL };
EFI_STATUS Status = EFI_SUCCESS;
EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
debug("vdisk_connect_driver <%s>...", DrvName);
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentName2ProtocolGuid, (VOID **)&Name2Protocol);
if (EFI_ERROR(Status))
{
continue;
}
Status = Name2Protocol->GetDriverName(Name2Protocol, "en", &DriverName);
if (EFI_ERROR(Status) || NULL == DriverName)
{
continue;
}
if (StrStr(DriverName, DrvName))
{
debug("Find driver name2:<%s>: <%s>", DriverName, DrvName);
DrvHandles[0] = Handles[i];
break;
}
}
if (i < Count)
{
Status = gBS->ConnectController(ControllerHandle, DrvHandles, NULL, TRUE);
debug("vdisk_connect_driver:<%s> <%r>", DrvName, Status);
goto end;
}
debug("%s NOT found, now try COMPONENT_NAME", DrvName);
Count = 0;
FreePool(Handles);
Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentNameProtocolGuid, (VOID **)&NameProtocol);
if (EFI_ERROR(Status))
{
continue;
}
Status = NameProtocol->GetDriverName(NameProtocol, "en", &DriverName);
if (EFI_ERROR(Status))
{
continue;
}
if (StrStr(DriverName, DrvName))
{
debug("Find driver name:<%s>: <%s>", DriverName, DrvName);
DrvHandles[0] = Handles[i];
break;
}
}
if (i < Count)
{
Status = gBS->ConnectController(ControllerHandle, DrvHandles, NULL, TRUE);
debug("vdisk_connect_driver:<%s> <%r>", DrvName, Status);
goto end;
}
Status = EFI_NOT_FOUND;
end:
FreePool(Handles);
return Status;
}
EFI_STATUS EFIAPI vdisk_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gVDiskBlockData.BlockIo);
vdisk_fill_device_path();
debug("install block io protocol %p", ImageHandle);
vdisk_debug_pause();
gVDiskBlockData.Media.BlockSize = 512;
gVDiskBlockData.Media.LastBlock = ImgSize / 512 - 1;
gVDiskBlockData.Media.ReadOnly = TRUE;
gVDiskBlockData.Media.MediaPresent = 1;
gVDiskBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
pBlockIo->Media = &(gVDiskBlockData.Media);
pBlockIo->Reset = vdisk_block_io_reset;
pBlockIo->ReadBlocks = vdisk_block_io_read;
pBlockIo->WriteBlocks = vdisk_block_io_write;
pBlockIo->FlushBlocks = vdisk_block_io_flush;
Status = gBS->InstallMultipleProtocolInterfaces(&gVDiskBlockData.Handle,
&gEfiBlockIoProtocolGuid, &gVDiskBlockData.BlockIo,
&gEfiDevicePathProtocolGuid, gVDiskBlockData.Path,
NULL);
debug("Install protocol %r %p", Status, gVDiskBlockData.Handle);
if (EFI_ERROR(Status))
{
return Status;
}
Status = vdisk_connect_driver(gVDiskBlockData.Handle, L"Disk I/O Driver");
debug("Connect disk IO driver %r", Status);
Status = vdisk_connect_driver(gVDiskBlockData.Handle, L"Partition Driver");
debug("Connect partition driver %r", Status);
if (EFI_ERROR(Status))
{
Status = gBS->ConnectController(gVDiskBlockData.Handle, NULL, NULL, TRUE);
debug("Connect all controller %r", Status);
}
vdisk_debug_pause();
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,2 @@
#include <Uefi.h>
int vdisk_get_vdisk_raw(UINT8 **buf, UINT32 *size) { *buf = NULL; *size = 0; return 0; }

View File

@@ -34,13 +34,17 @@
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DriverBinding.h>
#include <Ventoy.h>
BOOLEAN gDebugPrint = FALSE;
BOOLEAN gBootFallBack = FALSE;
BOOLEAN gDotEfiBoot = FALSE;
BOOLEAN gLoadIsoEfi = FALSE;
BOOLEAN gIsoUdf = FALSE;
ventoy_ram_disk g_ramdisk_param;
ventoy_chain_head *g_chain;
void *g_vtoy_img_location_buf;
ventoy_img_chunk *g_chunk;
UINT8 *g_os_param_reserved;
UINT32 g_img_chunk_num;
@@ -56,6 +60,7 @@ ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE;
@@ -69,10 +74,28 @@ CONST CHAR16 *gEfiBootFileName[] =
{
L"@",
EFI_REMOVABLE_MEDIA_FILE_NAME,
#if defined (MDE_CPU_IA32)
L"\\EFI\\BOOT\\GRUBIA32.EFI",
L"\\EFI\\BOOT\\BOOTia32.EFI",
L"\\EFI\\BOOT\\bootia32.efi",
L"\\efi\\boot\\bootia32.efi",
#elif defined (MDE_CPU_X64)
L"\\EFI\\BOOT\\GRUBX64.EFI",
L"\\EFI\\BOOT\\BOOTx64.EFI",
L"\\EFI\\BOOT\\bootx64.efi",
L"\\efi\\boot\\bootx64.efi",
#elif defined (MDE_CPU_ARM)
L"\\EFI\\BOOT\\GRUBARM.EFI",
L"\\EFI\\BOOT\\BOOTarm.EFI",
L"\\EFI\\BOOT\\bootarm.efi",
L"\\efi\\boot\\bootarm.efi",
#elif defined (MDE_CPU_AARCH64)
L"\\EFI\\BOOT\\GRUBAA64.EFI",
L"\\EFI\\BOOT\\BOOTaa64.EFI",
L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi",
#endif
};
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
@@ -249,6 +272,7 @@ static int ventoy_update_image_location(ventoy_os_param *param)
}
address = (UINTN)buffer;
g_vtoy_img_location_buf = buffer;
if (address % 4096)
{
@@ -339,10 +363,22 @@ EFI_HANDLE EFIAPI ventoy_get_parent_handle(IN EFI_DEVICE_PATH_PROTOCOL *pDevPath
return Handle;
}
STATIC ventoy_ram_disk g_backup_ramdisk_param;
STATIC ventoy_os_param g_backup_os_param_var;
EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
{
UINTN DataSize;
EFI_STATUS Status = EFI_SUCCESS;
EFI_GUID VarGuid = VENTOY_GUID;
DataSize = sizeof(g_backup_ramdisk_param);
Status = gRT->GetVariable(L"VentoyRamDisk", &VarGuid, NULL, &DataSize, &g_backup_ramdisk_param);
if (!EFI_ERROR(Status))
{
debug("find previous ramdisk variable <%llu>", g_backup_ramdisk_param.DiskSize);
}
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@@ -356,21 +392,38 @@ EFI_STATUS EFIAPI ventoy_delete_ramdisk_param(VOID)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_GUID VarGuid = VENTOY_GUID;
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
if (g_backup_ramdisk_param.DiskSize > 0 && g_backup_ramdisk_param.PhyAddr > 0)
{
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_backup_ramdisk_param), &g_backup_ramdisk_param);
debug("resotre ramdisk variable %r", Status);
}
else
{
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0, NULL);
debug("delete efi variable %r", Status);
debug("delete ramdisk variable %r", Status);
}
return Status;
}
EFI_STATUS EFIAPI ventoy_save_variable(VOID)
{
UINTN DataSize;
EFI_STATUS Status = EFI_SUCCESS;
EFI_GUID VarGuid = VENTOY_GUID;
DataSize = sizeof(g_backup_os_param_var);
Status = gRT->GetVariable(L"VentoyOsParam", &VarGuid, NULL, &DataSize, &g_backup_os_param_var);
if (!EFI_ERROR(Status))
{
debug("find previous efi variable <%a>", g_backup_os_param_var.vtoy_img_path);
}
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_chain->os_param), &(g_chain->os_param));
@@ -383,11 +436,21 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_GUID VarGuid = VENTOY_GUID;
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
if (0 == CompareMem(&(g_backup_os_param_var.guid), &VarGuid, sizeof(EFI_GUID)))
{
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_backup_os_param_var), &(g_backup_os_param_var));
debug("restore efi variable %r", Status);
}
else
{
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0, NULL);
debug("delete efi variable %r", Status);
debug("delete efi variable %r", Status);
}
return Status;
}
@@ -608,12 +671,23 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
EFI_HANDLE Image = NULL;
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 LogVar[4] = L"5";
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gIso9660EfiDriverPath,
sizeof(gIso9660EfiDriverPath),
&Image);
debug("load iso efi driver status:%r", Status);
if (gIsoUdf)
{
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gUdfEfiDriverPath,
sizeof(gUdfEfiDriverPath),
&Image);
debug("load iso UDF efi driver status:%r", Status);
}
else
{
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gIso9660EfiDriverPath,
sizeof(gIso9660EfiDriverPath),
&Image);
debug("load iso 9660 efi driver status:%r", Status);
}
if (gDebugPrint)
{
@@ -663,6 +737,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
gDebugPrint = TRUE;
}
if (StrStr(pCmdLine, L"fallback"))
{
gBootFallBack = TRUE;
}
if (StrStr(pCmdLine, L"dotefi"))
{
gDotEfiBoot = TRUE;
@@ -672,6 +751,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{
gLoadIsoEfi = TRUE;
}
if (StrStr(pCmdLine, L"iso_udf"))
{
gIsoUdf = TRUE;
}
pPos = StrStr(pCmdLine, L"FirstTry=@");
if (pPos)
@@ -837,12 +921,15 @@ EFI_STATUS EFIAPI ventoy_clean_env(VOID)
ventoy_delete_variable();
if (g_chain->os_param.vtoy_img_location_addr)
if (g_vtoy_img_location_buf)
{
FreePool((VOID *)(UINTN)g_chain->os_param.vtoy_img_location_addr);
FreePool(g_vtoy_img_location_buf);
}
FreePool(g_chain);
if (!gMemdiskMode)
{
FreePool(g_chain);
}
return EFI_SUCCESS;
}
@@ -994,7 +1081,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
}
debug("Fs not found, now wait and retry...");
sleep(2);
sleep(1);
}
}
@@ -1038,6 +1125,8 @@ EFI_STATUS EFIAPI VentoyEfiMain
return Status;
}
ventoy_disable_ex_filesystem();
if (gMemdiskMode)
{
g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_iso_data_buf;
@@ -1094,7 +1183,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
ventoy_clean_env();
}
if (FALSE == gDotEfiBoot)
if (FALSE == gDotEfiBoot && FALSE == gBootFallBack)
{
if (EFI_NOT_FOUND == Status)
{
@@ -1112,6 +1201,8 @@ EFI_STATUS EFIAPI VentoyEfiMain
grub_env_set("vtoy_dotefi_retry", "YES");
}
ventoy_enable_ex_filesystem();
return EFI_SUCCESS;
}

View File

@@ -168,19 +168,25 @@ typedef struct ventoy_virt_chunk
#define VTOY_BLOCK_DEVICE_PATH_GUID \
{ 0x37b87ac6, 0xc180, 0x4583, { 0xa7, 0x05, 0x41, 0x4d, 0xa8, 0xf7, 0x7e, 0xd2 }}
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
#define VTOY_BLOCK_DEVICE_PATH_NAME L"ventoy"
#if defined (MDE_CPU_IA32)
#define VENTOY_UEFI_DESC L"IA32 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_ia32.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_ia32.efi"
#elif defined (MDE_CPU_X64)
#define VENTOY_UEFI_DESC L"X64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_x64.efi"
#elif defined (MDE_CPU_EBC)
#elif defined (MDE_CPU_ARM)
#define VENTOY_UEFI_DESC L"ARM UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_arm.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_arm.efi"
#elif defined (MDE_CPU_AARCH64)
#define VENTOY_UEFI_DESC L"ARM64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_aa64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_aa64.efi"
#else
#error Unknown Processor Type
#endif
@@ -337,6 +343,14 @@ typedef struct ventoy_system_wrapper
EFI_LOCATE_DEVICE_PATH OriLocateDevicePath;
} ventoy_system_wrapper;
#define MAX_DRIVER_BIND_WRAPPER 64
typedef struct DriverBindWrapper
{
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
EFI_DRIVER_BINDING_SUPPORTED pfOldSupport;
}DRIVER_BIND_WRAPPER;
#define ventoy_wrapper(bs, wrapper, func, newfunc) \
{\
wrapper.Ori##func = bs->func;\
@@ -344,6 +358,22 @@ typedef struct ventoy_system_wrapper
bs->func = wrapper.New##func;\
}
#define VENTOY_GET_COMPONENT_NAME(Protocol, DriverName) \
{\
DriverName = NULL;\
Status = Protocol->GetDriverName(Protocol, "en", &DriverName);\
if (EFI_ERROR(Status) || NULL == DriverName) \
{\
DriverName = NULL;\
Status = Protocol->GetDriverName(Protocol, "eng", &DriverName);\
if (EFI_ERROR(Status) || NULL == DriverName) \
{\
continue;\
}\
}\
}
extern BOOLEAN gDebugPrint;
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
@@ -389,6 +419,8 @@ EFI_STATUS ventoy_hook_keyboard_stop(VOID);
BOOLEAN ventoy_is_cdrom_dp_exist(VOID);
EFI_STATUS ventoy_hook_1st_cdrom_start(VOID);
EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID);
EFI_STATUS ventoy_disable_ex_filesystem(VOID);
EFI_STATUS ventoy_enable_ex_filesystem(VOID);
#endif

View File

@@ -1,81 +1,81 @@
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Ventoy
FILE_GUID = 1c3a0915-09dc-49c2-873d-0aaaa7733299
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = VentoyEfiMain
[Sources]
Ventoy.h
Ventoy.c
VentoyDebug.c
VentoyProtocol.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
ShellPkg/ShellPkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
DebugLib
[Guids]
gShellVariableGuid
gEfiVirtualCdGuid
gEfiFileInfoGuid
[Protocols]
gEfiLoadedImageProtocolGuid
gEfiBlockIoProtocolGuid
gEfiDevicePathProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiRamDiskProtocolGuid
gEfiAbsolutePointerProtocolGuid
gEfiAcpiTableProtocolGuid
gEfiBlockIo2ProtocolGuid
gEfiBusSpecificDriverOverrideProtocolGuid
gEfiComponentNameProtocolGuid
gEfiComponentName2ProtocolGuid
gEfiDriverBindingProtocolGuid
gEfiDiskIoProtocolGuid
gEfiDiskIo2ProtocolGuid
gEfiGraphicsOutputProtocolGuid
gEfiHiiConfigAccessProtocolGuid
gEfiHiiFontProtocolGuid
gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid
gEfiLoadedImageProtocolGuid
gEfiLoadedImageDevicePathProtocolGuid
gEfiPciIoProtocolGuid
gEfiSerialIoProtocolGuid
gEfiSimpleTextInProtocolGuid
gEfiSimpleTextInputExProtocolGuid
gEfiSimpleTextOutProtocolGuid
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Ventoy
FILE_GUID = 1c3a0915-09dc-49c2-873d-0aaaa7733299
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = VentoyEfiMain
[Sources]
Ventoy.h
Ventoy.c
VentoyDebug.c
VentoyProtocol.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
ShellPkg/ShellPkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
DebugLib
[Guids]
gShellVariableGuid
gEfiVirtualCdGuid
gEfiFileInfoGuid
[Protocols]
gEfiLoadedImageProtocolGuid
gEfiBlockIoProtocolGuid
gEfiDevicePathProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiRamDiskProtocolGuid
gEfiAbsolutePointerProtocolGuid
gEfiAcpiTableProtocolGuid
gEfiBlockIo2ProtocolGuid
gEfiBusSpecificDriverOverrideProtocolGuid
gEfiComponentNameProtocolGuid
gEfiComponentName2ProtocolGuid
gEfiDriverBindingProtocolGuid
gEfiDiskIoProtocolGuid
gEfiDiskIo2ProtocolGuid
gEfiGraphicsOutputProtocolGuid
gEfiHiiConfigAccessProtocolGuid
gEfiHiiFontProtocolGuid
gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid
gEfiLoadedImageProtocolGuid
gEfiLoadedImageDevicePathProtocolGuid
gEfiPciIoProtocolGuid
gEfiSerialIoProtocolGuid
gEfiSimpleTextInProtocolGuid
gEfiSimpleTextInputExProtocolGuid
gEfiSimpleTextOutProtocolGuid

View File

@@ -34,6 +34,7 @@
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DriverBinding.h>
#include <Ventoy.h>
#define PROCOTOL_SLEEP_MSECONDS 0

View File

@@ -34,6 +34,7 @@
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DriverBinding.h>
#include <Ventoy.h>
UINT8 *g_iso_data_buf = NULL;
@@ -73,6 +74,9 @@ STATIC UINT8 g_sector_buf[2048];
STATIC EFI_BLOCK_READ g_sector_2048_read = NULL;
STATIC EFI_BLOCK_WRITE g_sector_2048_write = NULL;
STATIC UINTN g_DriverBindWrapperCnt = 0;
STATIC DRIVER_BIND_WRAPPER g_DriverBindWrapperList[MAX_DRIVER_BIND_WRAPPER];
BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
{
UINTN i = 0;
@@ -148,7 +152,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
ventoy_override_chunk *pOverride = g_override_chunk;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;
debug("read iso sector %lu count %u", Sector, Count);
debug("read iso sector %lu count %u Buffer:%p Align:%u", Sector, Count, Buffer, pRawBlockIo->Media->IoAlign);
ReadStart = Sector * 2048;
ReadEnd = (Sector + Count) * 2048;
@@ -161,9 +165,17 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
{
MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector;
}
else
else if (g_chain->disk_sector_size == 1024)
{
MapLba = (Sector - pchunk->img_start_sector) * 2048 / g_chain->disk_sector_size + pchunk->disk_start_sector;
MapLba = (Sector - pchunk->img_start_sector) * 2 + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 2048)
{
MapLba = (Sector - pchunk->img_start_sector) + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 4096)
{
MapLba = ((Sector - pchunk->img_start_sector) >> 1) + pchunk->disk_start_sector;
}
secLeft = pchunk->img_end_sector + 1 - Sector;
@@ -173,7 +185,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
MapLba, secRead * 2048, pCurBuf);
if (EFI_ERROR(Status))
{
debug("Raw disk read block failed %r LBA:%lu Count:%u", Status, MapLba, secRead);
debug("Raw disk read block failed %r LBA:%lu Count:%u %p", Status, MapLba, secRead, pCurBuf);
return Status;
}
@@ -277,10 +289,19 @@ STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
{
MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector;
}
else
else if (g_chain->disk_sector_size == 1024)
{
MapLba = (Sector - pchunk->img_start_sector) * 2048 / g_chain->disk_sector_size + pchunk->disk_start_sector;
MapLba = (Sector - pchunk->img_start_sector) * 2 + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 2048)
{
MapLba = (Sector - pchunk->img_start_sector) + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 4096)
{
MapLba = ((Sector - pchunk->img_start_sector) >> 1) + pchunk->disk_start_sector;
}
secLeft = pchunk->img_end_sector + 1 - Sector;
secRead = (Count < secLeft) ? Count : secLeft;
@@ -407,7 +428,7 @@ end:
return Lba;
}
EFI_STATUS EFIAPI ventoy_block_io_read
EFI_STATUS EFIAPI ventoy_block_io_read_real
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
@@ -420,6 +441,8 @@ EFI_STATUS EFIAPI ventoy_block_io_read
UINT32 j = 0;
UINT32 lbacount = 0;
UINT32 secNum = 0;
UINT32 TmpNum = 0;
UINT64 VirtSec = 0;
UINT64 offset = 0;
EFI_LBA curlba = 0;
EFI_LBA lastlba = 0;
@@ -427,7 +450,7 @@ EFI_STATUS EFIAPI ventoy_block_io_read
ventoy_sector_flag *cur_flag;
ventoy_virt_chunk *node;
//debug("### ventoy_block_io_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
debug("### block_io_read_real sector:%u count:%u Buffer:%p", (UINT32)Lba, (UINT32)BufferSize / 2048, Buffer);
secNum = BufferSize / 2048;
@@ -443,6 +466,28 @@ EFI_STATUS EFIAPI ventoy_block_io_read
{
return ventoy_read_iso_sector(Lba, secNum, Buffer);
}
else if (offset < g_chain->real_img_size_in_bytes)
{
TmpNum = (g_chain->real_img_size_in_bytes - offset) / 2048;
ventoy_read_iso_sector(Lba, TmpNum, Buffer);
Lba += TmpNum;
secNum -= TmpNum;
Buffer = (UINT8 *)Buffer + (g_chain->real_img_size_in_bytes - offset);
offset = Lba * 2048;
}
VirtSec = g_chain->virt_img_size_in_bytes / 2048;
if (Lba >= VirtSec)
{
return EFI_SUCCESS;
}
else if (Lba + secNum > VirtSec)
{
secNum = VirtSec - Lba;
}
debug("XXX block_io_read_real sector:%u count:%u Buffer:%p", (UINT32)Lba, (UINT32)BufferSize / 2048, Buffer);
if (secNum > g_sector_flag_num)
{
@@ -511,6 +556,42 @@ EFI_STATUS EFIAPI ventoy_block_io_read
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_block_io_read
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
UINT32 IoAlign = 0;
VOID *NewBuf = NULL;
EFI_STATUS Status = EFI_OUT_OF_RESOURCES;
if (gBlockData.pRawBlockIo && gBlockData.pRawBlockIo->Media)
{
IoAlign = gBlockData.pRawBlockIo->Media->IoAlign;
}
if ((IoAlign == 0) || (((UINTN) Buffer & (IoAlign - 1)) == 0))
{
Status = ventoy_block_io_read_real(This, MediaId, Lba, BufferSize, Buffer);
}
else
{
NewBuf = AllocatePages(EFI_SIZE_TO_PAGES(BufferSize + IoAlign));
if (NewBuf)
{
Status = ventoy_block_io_read_real(This, MediaId, Lba, BufferSize, NewBuf);
CopyMem(Buffer, NewBuf, BufferSize);
FreePages(NewBuf, EFI_SIZE_TO_PAGES(BufferSize + IoAlign));
}
}
return Status;
}
EFI_STATUS EFIAPI ventoy_block_io_write
(
IN EFI_BLOCK_IO_PROTOCOL *This,
@@ -543,26 +624,74 @@ EFI_STATUS EFIAPI ventoy_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL *This)
return EFI_SUCCESS;
}
STATIC UINTN ventoy_get_current_device_path_id(VOID)
{
UINTN i = 0;
UINTN Count = 0;
UINTN MaxId = 0;
UINTN CurId = 0;
BOOLEAN Find = FALSE;
EFI_HANDLE *Handles = NULL;
EFI_STATUS Status = EFI_SUCCESS;
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
VENDOR_DEVICE_PATH *venPath = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return 0;
}
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
if (EFI_ERROR(Status))
{
continue;
}
if (DevicePath->Type == HARDWARE_DEVICE_PATH && DevicePath->SubType == HW_VENDOR_DP)
{
venPath = (VENDOR_DEVICE_PATH *)DevicePath;
if (CompareGuid(&venPath->Guid, &gVtoyBlockDevicePathGuid))
{
CurId = StrDecimalToUintn((CHAR16 *)(venPath + 1) + StrLen(L"ventoy_"));
MaxId = MAX(MaxId, CurId);
Find = TRUE;
}
}
}
FreePool(Handles);
return Find ? (MaxId + 1) : 0;
}
EFI_STATUS EFIAPI ventoy_fill_device_path(VOID)
{
UINTN CurVtoyDpId = 0;
UINTN NameLen = 0;
UINT8 TmpBuf[128] = {0};
VENDOR_DEVICE_PATH *venPath = NULL;
CHAR16 VtoyDpName[32];
CurVtoyDpId = ventoy_get_current_device_path_id();
UnicodeSPrintAsciiFormat(VtoyDpName, sizeof(VtoyDpName), "ventoy_%03lu", CurVtoyDpId);
venPath = (VENDOR_DEVICE_PATH *)TmpBuf;
NameLen = StrSize(VTOY_BLOCK_DEVICE_PATH_NAME);
NameLen = StrSize(VtoyDpName);
venPath->Header.Type = HARDWARE_DEVICE_PATH;
venPath->Header.SubType = HW_VENDOR_DP;
venPath->Header.Length[0] = sizeof(VENDOR_DEVICE_PATH) + NameLen;
venPath->Header.Length[1] = 0;
CopyMem(&venPath->Guid, &gVtoyBlockDevicePathGuid, sizeof(EFI_GUID));
CopyMem(venPath + 1, VTOY_BLOCK_DEVICE_PATH_NAME, NameLen);
CopyMem(venPath + 1, VtoyDpName, NameLen);
gBlockData.Path = AppendDevicePathNode(NULL, (EFI_DEVICE_PATH_PROTOCOL *)TmpBuf);
gBlockData.DevicePathCompareLen = sizeof(VENDOR_DEVICE_PATH) + NameLen;
debug("gBlockData.Path=<%s>\n", ConvertDevicePathToText(gBlockData.Path, FALSE, FALSE));
debug("gBlockData.Path=<%lu><%s>\n", CurVtoyDpId, ConvertDevicePathToText(gBlockData.Path, FALSE, FALSE));
return EFI_SUCCESS;
}
@@ -595,11 +724,7 @@ EFI_STATUS EFIAPI ventoy_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST
continue;
}
Status = Name2Protocol->GetDriverName(Name2Protocol, "en", &DriverName);
if (EFI_ERROR(Status) || NULL == DriverName)
{
continue;
}
VENTOY_GET_COMPONENT_NAME(Name2Protocol, DriverName);
if (StrStr(DriverName, DrvName))
{
@@ -637,11 +762,7 @@ EFI_STATUS EFIAPI ventoy_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST
continue;
}
Status = NameProtocol->GetDriverName(NameProtocol, "en", &DriverName);
if (EFI_ERROR(Status))
{
continue;
}
VENTOY_GET_COMPONENT_NAME(NameProtocol, DriverName);
if (StrStr(DriverName, DrvName))
{
@@ -666,6 +787,229 @@ end:
return Status;
}
STATIC BOOLEAN ventoy_filesystem_need_wrapper(IN CONST CHAR16 *DrvName)
{
UINTN i;
CHAR16 UpperDrvName[256];
StrCpyS(UpperDrvName, 256, DrvName);
for (i = 0; i < 256 && UpperDrvName[i]; i++)
{
if (UpperDrvName[i] >= 'a' && UpperDrvName[i] <= 'z')
{
UpperDrvName[i] = 'A' + (UpperDrvName[i] - 'a');
}
}
/*
* suppress some file system drivers
* 1. rEFInd File System Driver
*
*/
if (StrStr(UpperDrvName, L"ISO9660") || StrStr(UpperDrvName, L"UDF"))
{
return TRUE;
}
if (StrStr(UpperDrvName, L"REFIND") && StrStr(UpperDrvName, L"FILE SYSTEM"))
{
return TRUE;
}
return FALSE;
}
STATIC VOID ventoy_add_filesystem_wrapper
(
IN EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol,
IN CONST CHAR16 *DriverName
)
{
UINTN j;
if (g_DriverBindWrapperCnt >= MAX_DRIVER_BIND_WRAPPER)
{
debug("driver binding wrapper overflow %lu", g_DriverBindWrapperCnt);
return;
}
if (!ventoy_filesystem_need_wrapper(DriverName))
{
return;
}
for (j = 0; j < g_DriverBindWrapperCnt; j++)
{
if (g_DriverBindWrapperList[j].DriverBinding == DriverBindProtocol)
{
debug("Duplicate driverbinding <%s> %p %lu %lu", DriverName, DriverBindProtocol, j, g_DriverBindWrapperCnt);
break;
}
}
if (j >= g_DriverBindWrapperCnt)
{
g_DriverBindWrapperList[g_DriverBindWrapperCnt].DriverBinding = DriverBindProtocol;
g_DriverBindWrapperList[g_DriverBindWrapperCnt].pfOldSupport = DriverBindProtocol->Supported;
g_DriverBindWrapperCnt++;
debug("Add driverbinding <%s> %p %lu", DriverName, DriverBindProtocol, g_DriverBindWrapperCnt);
}
}
STATIC EFI_STATUS ventoy_find_filesystem_driverbind(VOID)
{
UINTN i = 0;
UINTN Count = 0;
CHAR16 *DriverName = NULL;
EFI_HANDLE *Handles = NULL;
EFI_STATUS Status = EFI_SUCCESS;
EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol = NULL;
debug("ventoy_find_filesystem_driverbind...");
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentName2ProtocolGuid, (VOID **)&Name2Protocol);
if (EFI_ERROR(Status))
{
continue;
}
VENTOY_GET_COMPONENT_NAME(Name2Protocol, DriverName);
Status = gBS->HandleProtocol(Handles[i], &gEfiDriverBindingProtocolGuid, (VOID **)&DriverBindProtocol);
if (EFI_ERROR(Status))
{
debug("### 2 No DriverBind <%s> <%r>", DriverName, Status);
continue;
}
ventoy_add_filesystem_wrapper(DriverBindProtocol, DriverName);
}
Count = 0;
FreePool(Handles);
Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentNameProtocolGuid, (VOID **)&NameProtocol);
if (EFI_ERROR(Status))
{
debug();
continue;
}
VENTOY_GET_COMPONENT_NAME(NameProtocol, DriverName);
Status = gBS->HandleProtocol(Handles[i], &gEfiDriverBindingProtocolGuid, (VOID **)&DriverBindProtocol);
if (EFI_ERROR(Status))
{
debug("### 1 No DriverBind <%s> <%r>", DriverName, Status);
continue;
}
ventoy_add_filesystem_wrapper(DriverBindProtocol, DriverName);
}
FreePool(Handles);
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI ventoy_wrapper_driver_bind_support
(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
UINTN i;
EFI_STATUS Status = EFI_SUCCESS;
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
EFI_DRIVER_BINDING_SUPPORTED pfOldSupport = NULL;
for (i = 0; i < g_DriverBindWrapperCnt; i++)
{
if (g_DriverBindWrapperList[i].DriverBinding == This)
{
pfOldSupport = g_DriverBindWrapperList[i].pfOldSupport;
break;
}
}
debug("ventoy_wrapper_driver_bind_support %lu %p", i, pfOldSupport);
if (!pfOldSupport)
{
return EFI_UNSUPPORTED;
}
Status = gBS->HandleProtocol(ControllerHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
if (EFI_ERROR(Status))
{
goto out;
}
if (0 == CompareMem(gBlockData.Path, DevicePath, gBlockData.DevicePathCompareLen))
{
debug("return EFI_UNSUPPORTED for ventoy");
return EFI_UNSUPPORTED;
}
out:
return pfOldSupport(This, ControllerHandle, RemainingDevicePath);
}
EFI_STATUS ventoy_disable_ex_filesystem(VOID)
{
UINTN i;
ventoy_find_filesystem_driverbind();
for (i = 0; i < g_DriverBindWrapperCnt; i++)
{
g_DriverBindWrapperList[i].DriverBinding->Supported = ventoy_wrapper_driver_bind_support;
}
debug("Wrapper Ex Driver Binding %lu", g_DriverBindWrapperCnt);
ventoy_debug_pause();
return EFI_SUCCESS;
}
EFI_STATUS ventoy_enable_ex_filesystem(VOID)
{
UINTN i;
for (i = 0; i < g_DriverBindWrapperCnt; i++)
{
g_DriverBindWrapperList[i].DriverBinding->Supported = g_DriverBindWrapperList[i].pfOldSupport;
}
g_DriverBindWrapperCnt = 0;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_block_io_read_512
(
IN EFI_BLOCK_IO_PROTOCOL *This,
@@ -680,7 +1024,7 @@ EFI_STATUS EFIAPI ventoy_block_io_read_512
UINT8 *CurBuf = NULL;
EFI_STATUS Status = EFI_SUCCESS;
debug("ventoy_block_io_read_512 %lu %lu\n", Lba, BufferSize / 512);
debug("ventoy_block_io_read_512 %lu %lu Buffer:%p\n", Lba, BufferSize / 512, Buffer);
CurBuf = (UINT8 *)Buffer;

View File

@@ -79,6 +79,14 @@ STATIC EFI_STATUS ParseCmdline(IN EFI_HANDLE ImageHandle)
SetMem(pCmdLine, pImageInfo->LoadOptionsSize + 4, 0);
CopyMem(pCmdLine, pImageInfo->LoadOptions, pImageInfo->LoadOptionsSize);
if (StrStr(pCmdLine, L"vtoyefitest"))
{
gST->ConOut->OutputString(gST->ConOut, L"\r\n##########################");
gST->ConOut->OutputString(gST->ConOut, L"\r\n######### VTOY #########");
gST->ConOut->OutputString(gST->ConOut, L"\r\n##########################");
return EFI_SUCCESS;
}
if (StrStr(pCmdLine, L"debug"))
{
gVtoyDebugPrint = TRUE;
@@ -100,8 +108,9 @@ STATIC EFI_STATUS ParseCmdline(IN EFI_HANDLE ImageHandle)
}
gCurFeature = pPos + StrLen(L"feature=");
gCmdLine = pCmdLine;
return EFI_SUCCESS;
}
@@ -116,7 +125,7 @@ EFI_STATUS EFIAPI VtoyUtilEfiMain
ParseCmdline(ImageHandle);
for (i = 0; i < ARRAY_SIZE(gFeatureList); i++)
for (i = 0; gCurFeature && i < ARRAY_SIZE(gFeatureList); i++)
{
Len = StrLen(gFeatureList[i].Cmd);
if (StrnCmp(gFeatureList[i].Cmd, gCurFeature, Len) == 0)
@@ -127,8 +136,11 @@ EFI_STATUS EFIAPI VtoyUtilEfiMain
}
}
FreePool(gCmdLine);
gCmdLine = NULL;
if (gCmdLine)
{
FreePool(gCmdLine);
gCmdLine = NULL;
}
return EFI_SUCCESS;
}

View File

@@ -205,6 +205,7 @@
[Components]
MdeModulePkg/Application/Ventoy/Ventoy.inf
MdeModulePkg/Application/VtoyUtil/VtoyUtil.inf
MdeModulePkg/Application/VDiskChain/VDiskChain.inf
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf
MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf

View File

@@ -743,8 +743,8 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
if (!ctx.filename && dirent.namelen == 1 && name[0] == 1)
ctx.filename = (char *) "..";
if (g_fs_name_nocase)
ctx.type |= GRUB_FSHELP_CASE_INSENSITIVE;
if (g_fs_name_nocase)
ctx.type |= GRUB_FSHELP_CASE_INSENSITIVE;
/* The filename was not stored in a rock ridge entry. Read it
from the iso9660 filesystem. */

View File

@@ -70,10 +70,10 @@ SetLogging(VOID)
CHAR16 LogVar[4];
UINTN i, LogVarSize = sizeof(LogVar);
i = LogVarSize;
i = LogVarSize;
Status = RT->GetVariable(L"FS_NAME_NOCASE", &ShellVariable, NULL, &i, LogVar);
if (Status == EFI_SUCCESS)
g_fs_name_nocase = 1;
if (Status == EFI_SUCCESS)
g_fs_name_nocase = 1;
Status = RT->GetVariable(L"FS_LOGGING", &ShellVariable, NULL, &LogVarSize, LogVar);
if (Status == EFI_SUCCESS)

View File

@@ -0,0 +1,32 @@
#!/bin/bash
CUR="$PWD"
if ! [ -e LIBFUSE ]; then
./buidlibfuse.sh
fi
rm -f EXFAT/shared/*
rm -rf exfat-1.3.0
unzip exfat-1.3.0.zip
sed "/printf.*VERSION/a\ if (access(\"/etc/initrd-release\", F_OK) >= 0) argv[0][0] = '@';" -i exfat-1.3.0/fuse/main.c
cd exfat-1.3.0
autoreconf --install
./configure --prefix="$CUR" CFLAGS='-O2 -D_FILE_OFFSET_BITS=64' FUSE_CFLAGS="-I$CUR/LIBFUSE/include/" FUSE_LIBS="$CUR/LIBFUSE/lib/libfuse.a -lpthread -ldl"
make
strip --strip-all fuse/mount.exfat-fuse
strip --strip-all mkfs/mkexfatfs
cp fuse/mount.exfat-fuse ../EXFAT/shared/mount.exfat-fuse
cp mkfs/mkexfatfs ../EXFAT/shared/mkexfatfs
cd ..
rm -rf exfat-1.3.0

View File

@@ -0,0 +1,29 @@
#!/bin/bash
CUR="$PWD"
rm -rf libfuse
rm -rf LIBFUSE
if [ -e mirrors-libfuse-fuse-2.9.9.zip ]; then
unzip mirrors-libfuse-fuse-2.9.9.zip
cd libfuse
else
unzip libfuse-fuse-2.9.9.zip
cd libfuse-fuse-2.9.9
fi
./makeconf.sh
./configure --prefix="$CUR/LIBFUSE"
sed '/#define *__u64/d' -i include/fuse_kernel.h
sed '/#define *__s64/d' -i include/fuse_kernel.h
sed 's/__u64/uint64_t/g' -i include/fuse_kernel.h
sed 's/__s64/int64_t/g' -i include/fuse_kernel.h
make -j 16
make install
cd ..
rm -rf libfuse

View File

@@ -11,10 +11,16 @@ else
opt=-lrt
fi
#
# use musl-c to build for x86_64
#
export C_INCLUDE_PATH=$LIBFUSE_DIR/include
rm -f $name
gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -o $name $LIBFUSE_DIR/lib/libfuse.a -lpthread -ldl $opt
gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c $LIBFUSE_DIR/lib/libfuse.a -o $name
strip --strip-all $name
if [ -e $name ]; then
echo -e "\n############### SUCCESS $name ##################\n"

21
FUSEISO/build_aarch64.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE
name=vtoy_fuse_iso_aa64
export C_INCLUDE_PATH=$LIBFUSE_DIR/include
rm -f $name
aarch64-buildroot-linux-uclibc-gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -o $name $LIBFUSE_DIR/lib/libfuse.a
if [ -e $name ]; then
echo -e "\n############### SUCCESS $name ##################\n"
else
echo -e "\n############### FAILED $name ##################\n"
fi
aarch64-buildroot-linux-uclibc-strip --strip-all $name

View File

@@ -7,6 +7,8 @@
#
#
# use mini-native-x86_64 UCLIBC to build for x86_64
CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE
@@ -31,7 +33,7 @@ fi
./makeconf.sh
./configure --prefix="$LIBFUSE_DIR"
./configure --prefix="$LIBFUSE_DIR" CFLAGS='-specs /usr/local/musl/lib/musl-gcc.specs'
make -j 16
make install
cd ..

View File

@@ -0,0 +1,46 @@
#!/bin/bash
#
#
# Package Dependency:
# gcc automake autoconf gettext gettext-devel libtool unzip
#
#
CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE
rm -rf libfuse
rm -rf $LIBFUSE_DIR
# please download https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9
if [ -e ../ExFAT/mirrors-libfuse-fuse-2.9.9.zip ]; then
rm -rf libfuse
unzip ../ExFAT/mirrors-libfuse-fuse-2.9.9.zip
cd libfuse
elif [ -e ../ExFAT/libfuse-fuse-2.9.9.zip ]; then
rm -rf libfuse-fuse-2.9.9
unzip ../ExFAT/libfuse-fuse-2.9.9.zip
cd libfuse-fuse-2.9.9
else
echo "Please download mirrors-libfuse-fuse-2.9.9.zip first"
exit 1
fi
./makeconf.sh
sed '/#define *__u64/d' -i include/fuse_kernel.h
sed '/#define *__s64/d' -i include/fuse_kernel.h
sed 's/__u64/uint64_t/g' -i include/fuse_kernel.h
sed 's/__s64/int64_t/g' -i include/fuse_kernel.h
./configure --prefix="$LIBFUSE_DIR" --host=aarch64 CC=aarch64-buildroot-linux-uclibc-gcc
make -j 16
make install
cd ..
rm -rf libfuse

Binary file not shown.

Binary file not shown.

BIN
FUSEISO/vtoy_fuse_iso_aa64 Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,909 @@
#! /usr/bin/python
# GRUB -- GRand Unified Bootloader
# Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
__metaclass__ = type
from optparse import OptionParser
import re
#
# This is the python script used to generate Makefile.*.am
#
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
"i386_xen", "x86_64_xen", "i386_xen_pvh",
"mips_loongson", "mips64_efi", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
"arm_coreboot", "riscv32_efi", "riscv64_efi" ]
GROUPS = {}
GROUPS["common"] = GRUB_PLATFORMS[:]
# Groups based on CPU
GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
GROUPS["x86_64"] = [ "x86_64_efi" ]
GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
GROUPS["mips64"] = [ "mips64_efi" ]
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
GROUPS["arm64"] = [ "arm64_efi" ]
GROUPS["riscv32"] = [ "riscv32_efi" ]
GROUPS["riscv64"] = [ "riscv64_efi" ]
# Groups based on firmware
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", "mips64_efi",
"riscv32_efi", "riscv64_efi" ]
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
GROUPS["uboot"] = [ "arm_uboot" ]
GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ]
GROUPS["coreboot"] = [ "i386_coreboot", "arm_coreboot" ]
# emu is a special case so many core functionality isn't needed on this platform
GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
# Groups based on hardware features
GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips",
"sparc64_ieee1275", "powerpc_ieee1275"]
GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi");
GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"]
GROUPS["usb"] = GROUPS["pci"] + ["arm_coreboot"]
# If gfxterm is main output console integrate it into kernel
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
# Similar for terminfo
GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips", "i386_xen_pvh" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"];
GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
# Flattened Device Trees (FDT)
GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ]
# Needs software helpers for division
# Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"]
GROUPS["no_softdiv"] = GRUB_PLATFORMS[:]
for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i)
# Miscellaneous groups scheduled to disappear in future
GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc")
#
# Create platform => groups reverse map, where groups covering that
# platform are ordered by their sizes
#
RMAP = {}
for platform in GRUB_PLATFORMS:
# initialize with platform itself as a group
RMAP[platform] = [ platform ]
for k in GROUPS.keys():
v = GROUPS[k]
# skip groups that don't cover this platform
if platform not in v: continue
bigger = []
smaller = []
# partition currently known groups based on their size
for group in RMAP[platform]:
if group in GRUB_PLATFORMS: smaller.append(group)
elif len(GROUPS[group]) < len(v): smaller.append(group)
else: bigger.append(group)
# insert in the middle
RMAP[platform] = smaller + [ k ] + bigger
#
# Input
#
# We support a subset of the AutoGen definitions file syntax. Specifically,
# compound names are disallowed; some preprocessing directives are
# disallowed (though #if/#endif are allowed; note that, like AutoGen, #if
# skips everything to the next #endif regardless of the value of the
# conditional); and shell-generated strings, Scheme-generated strings, and
# here strings are disallowed.
class AutogenToken:
(autogen, definitions, eof, var_name, other_name, string, number,
semicolon, equals, comma, lbrace, rbrace, lbracket, rbracket) = range(14)
class AutogenState:
(init, need_def, need_tpl, need_semi, need_name, have_name, need_value,
need_idx, need_rbracket, indx_name, have_value, done) = range(12)
class AutogenParseError(Exception):
def __init__(self, message, path, line):
super(AutogenParseError, self).__init__(message)
self.path = path
self.line = line
def __str__(self):
return (
super(AutogenParseError, self).__str__() +
" at file %s line %d" % (self.path, self.line))
class AutogenDefinition(list):
def __getitem__(self, key):
try:
return super(AutogenDefinition, self).__getitem__(key)
except TypeError:
for name, value in self:
if name == key:
return value
def __contains__(self, key):
for name, value in self:
if name == key:
return True
return False
def get(self, key, default):
for name, value in self:
if name == key:
return value
else:
return default
def find_all(self, key):
for name, value in self:
if name == key:
yield value
class AutogenParser:
def __init__(self):
self.definitions = AutogenDefinition()
self.def_stack = [("", self.definitions)]
self.curdef = None
self.new_name = None
self.cur_path = None
self.cur_line = 0
@staticmethod
def is_unquotable_char(c):
return (ord(c) in range(ord("!"), ord("~") + 1) and
c not in "#,;<=>[\\]`{}?*'\"()")
@staticmethod
def is_value_name_char(c):
return c in ":^-_" or c.isalnum()
def error(self, message):
raise AutogenParseError(message, self.cur_file, self.cur_line)
def read_tokens(self, f):
data = f.read()
end = len(data)
offset = 0
while offset < end:
while offset < end and data[offset].isspace():
if data[offset] == "\n":
self.cur_line += 1
offset += 1
if offset >= end:
break
c = data[offset]
if c == "#":
offset += 1
try:
end_directive = data.index("\n", offset)
directive = data[offset:end_directive]
offset = end_directive
except ValueError:
directive = data[offset:]
offset = end
name, value = directive.split(None, 1)
if name == "if":
try:
end_if = data.index("\n#endif", offset)
new_offset = end_if + len("\n#endif")
self.cur_line += data[offset:new_offset].count("\n")
offset = new_offset
except ValueError:
self.error("#if without matching #endif")
else:
self.error("Unhandled directive '#%s'" % name)
elif c == "{":
yield AutogenToken.lbrace, c
offset += 1
elif c == "=":
yield AutogenToken.equals, c
offset += 1
elif c == "}":
yield AutogenToken.rbrace, c
offset += 1
elif c == "[":
yield AutogenToken.lbracket, c
offset += 1
elif c == "]":
yield AutogenToken.rbracket, c
offset += 1
elif c == ";":
yield AutogenToken.semicolon, c
offset += 1
elif c == ",":
yield AutogenToken.comma, c
offset += 1
elif c in ("'", '"'):
s = []
while True:
offset += 1
if offset >= end:
self.error("EOF in quoted string")
if data[offset] == "\n":
self.cur_line += 1
if data[offset] == "\\":
offset += 1
if offset >= end:
self.error("EOF in quoted string")
if data[offset] == "\n":
self.cur_line += 1
# Proper escaping unimplemented; this can be filled
# out if needed.
s.append("\\")
s.append(data[offset])
elif data[offset] == c:
offset += 1
break
else:
s.append(data[offset])
yield AutogenToken.string, "".join(s)
elif c == "/":
offset += 1
if data[offset] == "*":
offset += 1
try:
end_comment = data.index("*/", offset)
new_offset = end_comment + len("*/")
self.cur_line += data[offset:new_offset].count("\n")
offset = new_offset
except ValueError:
self.error("/* without matching */")
elif data[offset] == "/":
try:
offset = data.index("\n", offset)
except ValueError:
pass
elif (c.isdigit() or
(c == "-" and offset < end - 1 and
data[offset + 1].isdigit())):
end_number = offset + 1
while end_number < end and data[end_number].isdigit():
end_number += 1
yield AutogenToken.number, data[offset:end_number]
offset = end_number
elif self.is_unquotable_char(c):
end_name = offset
while (end_name < end and
self.is_value_name_char(data[end_name])):
end_name += 1
if end_name < end and self.is_unquotable_char(data[end_name]):
while (end_name < end and
self.is_unquotable_char(data[end_name])):
end_name += 1
yield AutogenToken.other_name, data[offset:end_name]
offset = end_name
else:
s = data[offset:end_name]
if s.lower() == "autogen":
yield AutogenToken.autogen, s
elif s.lower() == "definitions":
yield AutogenToken.definitions, s
else:
yield AutogenToken.var_name, s
offset = end_name
else:
self.error("Invalid input character '%s'" % c)
yield AutogenToken.eof, None
def do_need_name_end(self, token):
if len(self.def_stack) > 1:
self.error("Definition blocks were left open")
def do_need_name_var_name(self, token):
self.new_name = token
def do_end_block(self, token):
if len(self.def_stack) <= 1:
self.error("Too many close braces")
new_name, parent_def = self.def_stack.pop()
parent_def.append((new_name, self.curdef))
self.curdef = parent_def
def do_empty_val(self, token):
self.curdef.append((self.new_name, ""))
def do_str_value(self, token):
self.curdef.append((self.new_name, token))
def do_start_block(self, token):
self.def_stack.append((self.new_name, self.curdef))
self.curdef = AutogenDefinition()
def do_indexed_name(self, token):
self.new_name = token
def read_definitions_file(self, f):
self.curdef = self.definitions
self.cur_line = 0
state = AutogenState.init
# The following transition table was reduced from the Autogen
# documentation:
# info -f autogen -n 'Full Syntax'
transitions = {
AutogenState.init: {
AutogenToken.autogen: (AutogenState.need_def, None),
},
AutogenState.need_def: {
AutogenToken.definitions: (AutogenState.need_tpl, None),
},
AutogenState.need_tpl: {
AutogenToken.var_name: (AutogenState.need_semi, None),
AutogenToken.other_name: (AutogenState.need_semi, None),
AutogenToken.string: (AutogenState.need_semi, None),
},
AutogenState.need_semi: {
AutogenToken.semicolon: (AutogenState.need_name, None),
},
AutogenState.need_name: {
AutogenToken.autogen: (AutogenState.need_def, None),
AutogenToken.eof: (AutogenState.done, self.do_need_name_end),
AutogenToken.var_name: (
AutogenState.have_name, self.do_need_name_var_name),
AutogenToken.rbrace: (
AutogenState.have_value, self.do_end_block),
},
AutogenState.have_name: {
AutogenToken.semicolon: (
AutogenState.need_name, self.do_empty_val),
AutogenToken.equals: (AutogenState.need_value, None),
AutogenToken.lbracket: (AutogenState.need_idx, None),
},
AutogenState.need_value: {
AutogenToken.var_name: (
AutogenState.have_value, self.do_str_value),
AutogenToken.other_name: (
AutogenState.have_value, self.do_str_value),
AutogenToken.string: (
AutogenState.have_value, self.do_str_value),
AutogenToken.number: (
AutogenState.have_value, self.do_str_value),
AutogenToken.lbrace: (
AutogenState.need_name, self.do_start_block),
},
AutogenState.need_idx: {
AutogenToken.var_name: (
AutogenState.need_rbracket, self.do_indexed_name),
AutogenToken.number: (
AutogenState.need_rbracket, self.do_indexed_name),
},
AutogenState.need_rbracket: {
AutogenToken.rbracket: (AutogenState.indx_name, None),
},
AutogenState.indx_name: {
AutogenToken.semicolon: (
AutogenState.need_name, self.do_empty_val),
AutogenToken.equals: (AutogenState.need_value, None),
},
AutogenState.have_value: {
AutogenToken.semicolon: (AutogenState.need_name, None),
AutogenToken.comma: (AutogenState.need_value, None),
},
}
for code, token in self.read_tokens(f):
if code in transitions[state]:
state, handler = transitions[state][code]
if handler is not None:
handler(token)
else:
self.error(
"Parse error in state %s: unexpected token '%s'" % (
state, token))
if state == AutogenState.done:
break
def read_definitions(self, path):
self.cur_file = path
with open(path) as f:
self.read_definitions_file(f)
defparser = AutogenParser()
#
# Output
#
outputs = {}
def output(s, section=''):
if s == "":
return
outputs.setdefault(section, [])
outputs[section].append(s)
def write_output(section=''):
for s in outputs.get(section, []):
print(s, end='')
#
# Global variables
#
def gvar_add(var, value):
output(var + " += " + value + "\n")
#
# Per PROGRAM/SCRIPT variables
#
seen_vars = set()
def vars_init(defn, *var_list):
name = defn['name']
if name not in seen_target and name not in seen_vars:
for var in var_list:
output(var + " = \n", section='decl')
seen_vars.add(name)
def var_set(var, value):
output(var + " = " + value + "\n")
def var_add(var, value):
output(var + " += " + value + "\n")
#
# Variable names and rules
#
canonical_name_re = re.compile(r'[^0-9A-Za-z@_]')
canonical_name_suffix = ""
def set_canonical_name_suffix(suffix):
global canonical_name_suffix
canonical_name_suffix = suffix
def cname(defn):
return canonical_name_re.sub('_', defn['name'] + canonical_name_suffix)
def rule(target, source, cmd):
if cmd[0] == "\n":
output("\n" + target + ": " + source + cmd.replace("\n", "\n\t") + "\n")
else:
output("\n" + target + ": " + source + "\n\t" + cmd.replace("\n", "\n\t") + "\n")
#
# Handle keys with platform names as values, for example:
#
# kernel = {
# nostrip = emu;
# ...
# }
#
def platform_tagged(defn, platform, tag):
for value in defn.find_all(tag):
for group in RMAP[platform]:
if value == group:
return True
return False
def if_platform_tagged(defn, platform, tag, snippet_if, snippet_else=None):
if platform_tagged(defn, platform, tag):
return snippet_if
elif snippet_else is not None:
return snippet_else
#
# Handle tagged values
#
# module = {
# extra_dist = ...
# extra_dist = ...
# ...
# };
#
def foreach_value(defn, tag, closure):
r = []
for value in defn.find_all(tag):
r.append(closure(value))
return ''.join(r)
#
# Handle best matched values for a platform, for example:
#
# module = {
# cflags = '-Wall';
# emu_cflags = '-Wall -DGRUB_EMU=1';
# ...
# }
#
def foreach_platform_specific_value(defn, platform, suffix, nonetag, closure):
r = []
for group in RMAP[platform]:
values = list(defn.find_all(group + suffix))
if values:
for value in values:
r.append(closure(value))
break
else:
for value in defn.find_all(nonetag):
r.append(closure(value))
return ''.join(r)
#
# Handle values from sum of all groups for a platform, for example:
#
# module = {
# common = kern/misc.c;
# emu = kern/emu/misc.c;
# ...
# }
#
def foreach_platform_value(defn, platform, suffix, closure):
r = []
for group in RMAP[platform]:
for value in defn.find_all(group + suffix):
r.append(closure(value))
return ''.join(r)
def platform_conditional(platform, closure):
output("\nif COND_" + platform + "\n")
closure(platform)
output("endif\n")
#
# Handle guarding with platform-specific "enable" keys, for example:
#
# module = {
# name = pci;
# noemu = bus/pci.c;
# emu = bus/emu/pci.c;
# emu = commands/lspci.c;
#
# enable = emu;
# enable = i386_pc;
# enable = x86_efi;
# enable = i386_ieee1275;
# enable = i386_coreboot;
# };
#
def foreach_enabled_platform(defn, closure):
if 'enable' in defn:
for platform in GRUB_PLATFORMS:
if platform_tagged(defn, platform, "enable"):
platform_conditional(platform, closure)
else:
for platform in GRUB_PLATFORMS:
platform_conditional(platform, closure)
#
# Handle guarding with platform-specific automake conditionals, for example:
#
# module = {
# name = usb;
# common = bus/usb/usb.c;
# noemu = bus/usb/usbtrans.c;
# noemu = bus/usb/usbhub.c;
# enable = emu;
# enable = i386;
# enable = mips_loongson;
# emu_condition = COND_GRUB_EMU_SDL;
# };
#
def under_platform_specific_conditionals(defn, platform, closure):
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "if " + cond + "\n"))
closure(defn, platform)
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "endif " + cond + "\n"))
def platform_specific_values(defn, platform, suffix, nonetag):
return foreach_platform_specific_value(defn, platform, suffix, nonetag,
lambda value: value + " ")
def platform_values(defn, platform, suffix):
return foreach_platform_value(defn, platform, suffix, lambda value: value + " ")
def extra_dist(defn):
return foreach_value(defn, "extra_dist", lambda value: value + " ")
def platform_sources(defn, p): return platform_values(defn, p, "")
def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist")
def platform_startup(defn, p): return platform_specific_values(defn, p, "_startup", "startup")
def platform_ldadd(defn, p): return platform_specific_values(defn, p, "_ldadd", "ldadd")
def platform_dependencies(defn, p): return platform_specific_values(defn, p, "_dependencies", "dependencies")
def platform_cflags(defn, p): return platform_specific_values(defn, p, "_cflags", "cflags")
def platform_ldflags(defn, p): return platform_specific_values(defn, p, "_ldflags", "ldflags")
def platform_cppflags(defn, p): return platform_specific_values(defn, p, "_cppflags", "cppflags")
def platform_ccasflags(defn, p): return platform_specific_values(defn, p, "_ccasflags", "ccasflags")
def platform_stripflags(defn, p): return platform_specific_values(defn, p, "_stripflags", "stripflags")
def platform_objcopyflags(defn, p): return platform_specific_values(defn, p, "_objcopyflags", "objcopyflags")
#
# Emit snippet only the first time through for the current name.
#
seen_target = set()
def first_time(defn, snippet):
if defn['name'] not in seen_target:
return snippet
return ''
def is_platform_independent(defn):
if 'enable' in defn:
return False
for suffix in [ "", "_nodist" ]:
template = platform_values(defn, GRUB_PLATFORMS[0], suffix)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_values(defn, platform, suffix):
return False
for suffix in [ "startup", "ldadd", "dependencies", "cflags", "ldflags", "cppflags", "ccasflags", "stripflags", "objcopyflags", "condition" ]:
template = platform_specific_values(defn, GRUB_PLATFORMS[0], "_" + suffix, suffix)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_specific_values(defn, platform, "_" + suffix, suffix):
return False
for tag in [ "nostrip" ]:
template = platform_tagged(defn, GRUB_PLATFORMS[0], tag)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_tagged(defn, platform, tag):
return False
return True
def module(defn, platform):
name = defn['name']
set_canonical_name_suffix(".module")
gvar_add("platform_PROGRAMS", name + ".module")
gvar_add("MODULE_FILES", name + ".module$(EXEEXT)")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources")
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("MOD_FILES", name + ".mod")
gvar_add("MARKER_FILES", name + ".marker")
gvar_add("CLEANFILES", name + ".marker")
output("""
""" + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES)
$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
grep 'MARKER' $@.new > $@; rm -f $@.new
""")
def kernel(defn, platform):
name = defn['name']
set_canonical_name_suffix(".exec")
gvar_add("platform_PROGRAMS", name + ".exec")
var_set(cname(defn) + "_SOURCES", platform_startup(defn, platform))
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_KERNEL) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_KERNEL) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(defn, platform))
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF)")
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("platform_DATA", name + ".img")
gvar_add("CLEANFILES", name + ".img")
rule(name + ".img", name + ".exec$(EXEEXT)",
if_platform_tagged(defn, platform, "nostrip",
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
$(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -wd1106 -nu -nd $< $@; \
elif test ! -z '$(TARGET_OBJ2ELF)'; then \
$(TARGET_OBJ2ELF) $< $@ || (rm -f $@; exit 1); \
else cp $< $@; fi""",
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
$(TARGET_STRIP) -S -x $(""" + cname(defn) + """) -o $@.bin $<; \
$(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -ed2016 -wd1106 -nu -nd $@.bin $@; \
rm -f $@.bin; \
elif test ! -z '$(TARGET_OBJ2ELF)'; then \
""" + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@.bin $< && \
$(TARGET_OBJ2ELF) $@.bin $@ || (rm -f $@; rm -f $@.bin; exit 1); \
rm -f $@.bin; \
else """ + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@ $<; \
fi"""))
def image(defn, platform):
name = defn['name']
set_canonical_name_suffix(".image")
gvar_add("platform_PROGRAMS", name + ".image")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + "## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_IMAGE) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_IMAGE) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_OBJCOPYFLAGS", "$(OBJCOPYFLAGS_IMAGE) " + platform_objcopyflags(defn, platform))
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("platform_DATA", name + ".img")
gvar_add("CLEANFILES", name + ".img")
rule(name + ".img", name + ".image$(EXEEXT)", """
if test x$(TARGET_APPLE_LINKER) = x1; then \
$(MACHO2IMG) $< $@; \
else \
$(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx $< $@; \
fi
""")
def library(defn, platform):
name = defn['name']
set_canonical_name_suffix("")
vars_init(defn,
cname(defn) + "_SOURCES",
"nodist_" + cname(defn) + "_SOURCES",
cname(defn) + "_CFLAGS",
cname(defn) + "_CPPFLAGS",
cname(defn) + "_CCASFLAGS")
# cname(defn) + "_DEPENDENCIES")
if name not in seen_target:
gvar_add("noinst_LIBRARIES", name)
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_add("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
var_add(cname(defn) + "_CFLAGS", first_time(defn, "$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(defn, platform))
var_add(cname(defn) + "_CPPFLAGS", first_time(defn, "$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(defn, platform))
var_add(cname(defn) + "_CCASFLAGS", first_time(defn, "$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(defn, platform))
# var_add(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
if name not in seen_target:
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
def installdir(defn, default="bin"):
return defn.get('installdir', default)
def manpage(defn, adddeps):
name = defn['name']
mansection = defn['mansection']
output("if COND_MAN_PAGES\n")
gvar_add("man_MANS", name + "." + mansection)
rule(name + "." + mansection, name + " " + adddeps, """
chmod a+x """ + name + """
PATH=$(builddir):$$PATH pkgdatadir=$(builddir) $(HELP2MAN) --section=""" + mansection + """ -i $(top_srcdir)/docs/man/""" + name + """.h2m -o $@ """ + name + """
""")
gvar_add("CLEANFILES", name + "." + mansection)
output("endif\n")
def program(defn, platform, test=False):
name = defn['name']
set_canonical_name_suffix("")
if 'testcase' in defn:
gvar_add("check_PROGRAMS", name)
gvar_add("TESTS", name)
else:
var_add(installdir(defn) + "_PROGRAMS", name)
if 'mansection' in defn:
manpage(defn, "")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_PROGRAM) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(defn, platform))
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
def data(defn, platform):
var_add("dist_" + installdir(defn) + "_DATA", platform_sources(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
def transform_data(defn, platform):
name = defn['name']
var_add(installdir(defn) + "_DATA", name)
rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:-
chmod a+x """ + name + """
""")
gvar_add("CLEANFILES", name)
gvar_add("EXTRA_DIST", extra_dist(defn))
gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
def script(defn, platform):
name = defn['name']
if 'testcase' in defn:
gvar_add("check_SCRIPTS", name)
gvar_add ("TESTS", name)
else:
var_add(installdir(defn) + "_SCRIPTS", name)
if 'mansection' in defn:
manpage(defn, "grub-mkconfig_lib")
rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:-
chmod a+x """ + name + """
""")
gvar_add("CLEANFILES", name)
gvar_add("EXTRA_DIST", extra_dist(defn))
gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
def rules(target, closure):
seen_target.clear()
seen_vars.clear()
for defn in defparser.definitions.find_all(target):
if is_platform_independent(defn):
under_platform_specific_conditionals(defn, GRUB_PLATFORMS[0], closure)
else:
foreach_enabled_platform(
defn,
lambda p: under_platform_specific_conditionals(defn, p, closure))
# Remember that we've seen this target.
seen_target.add(defn['name'])
parser = OptionParser(usage="%prog DEFINITION-FILES")
_, args = parser.parse_args()
for arg in args:
defparser.read_definitions(arg)
rules("module", module)
rules("kernel", kernel)
rules("image", image)
rules("library", library)
rules("program", program)
rules("script", script)
rules("data", data)
rules("transform_data", transform_data)
write_output(section='decl')
write_output()

View File

@@ -0,0 +1,507 @@
AUTOMAKE_OPTIONS = subdir-objects -Wno-portability
DEPDIR=.deps-core
include $(top_srcdir)/conf/Makefile.common
CC=$(TARGET_CC)
CPP=$(TARGET_CC)
CCAS=$(TARGET_CC)
RANLIB=$(TARGET_RANLIB)
STRIP=$(TARGET_STRIP)
MACHO2IMG=$(top_builddir)/grub-macho2img
AM_CFLAGS = $(TARGET_CFLAGS)
AM_LDFLAGS = $(TARGET_LDFLAGS)
AM_CPPFLAGS = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT)
AM_CCASFLAGS = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT)
CFLAGS_PROGRAM += $(CFLAGS_PLATFORM)
LDFLAGS_PROGRAM += $(LDFLAGS_PLATFORM)
CPPFLAGS_PROGRAM += $(CPPFLAGS_PLATFORM)
CCASFLAGS_PROGRAM += $(CCASFLAGS_PLATFORM)
CFLAGS_LIBRARY += $(CFLAGS_PLATFORM) -fno-builtin
CPPFLAGS_LIBRARY += $(CPPFLAGS_PLATFORM)
CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
build-grub-pep2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=64 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pep2elf\" $^
CLEANFILES += build-grub-pep2elf$(BUILD_EXEEXT)
build-grub-pe2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=32 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pe2elf\" $^
CLEANFILES += build-grub-pe2elf$(BUILD_EXEEXT)
# gentrigtables
gentrigtables$(BUILD_EXEEXT): gentrigtables.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $< $(BUILD_LIBM)
CLEANFILES += gentrigtables$(BUILD_EXEEXT)
build-grub-module-verifier$(BUILD_EXEEXT): $(top_srcdir)/util/grub-module-verifier.c $(top_srcdir)/util/grub-module-verifier32.c $(top_srcdir)/util/grub-module-verifier64.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-module-verifier\" $^
CLEANFILES += build-grub-module-verifier$(BUILD_EXEEXT)
# trigtables.c
trigtables.c: gentrigtables$(BUILD_EXEEXT) gentrigtables.c $(top_srcdir)/configure.ac
./gentrigtables$(BUILD_EXEEXT) > $@
CLEANFILES += trigtables.c
# XXX Use Automake's LEX & YACC support
grub_script.tab.h: script/parser.y
$(YACC) -d -p grub_script_yy -b grub_script $<
grub_script.tab.c: grub_script.tab.h
CLEANFILES += grub_script.tab.c grub_script.tab.h
# For the lexer.
grub_script.yy.h: script/yylex.l
$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $<
grub_script.yy.c: grub_script.yy.h
rs_decoder.h: $(srcdir)/lib/reed_solomon.c
$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 -ffreestanding
CLEANFILES += grub_script.yy.c grub_script.yy.h
include $(srcdir)/Makefile.core.am
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h
if COND_emu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h
else
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h
endif
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
if COND_i386_pc
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_xen_pvh
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
endif
if COND_i386_efi
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
endif
if COND_i386_coreboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_i386_multiboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_i386_qemu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_ieee1275
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_xen
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
endif
if COND_x86_64_xen
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/x86_64/xen/hypercall.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
endif
if COND_x86_64_efi
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
endif
if COND_ia64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h
endif
if COND_mips_arc
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
endif
if COND_mips_qemu_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_mips_loongson
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/time.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_mips_qemu_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
endif
if COND_mips64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loongson.h
endif
if COND_powerpc_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_sparc64_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_arm_uboot
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/uboot.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
endif
if COND_arm_coreboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h
endif
if COND_arm_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_arm64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_riscv32_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_riscv64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_emu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
if COND_GRUB_EMU_SDL
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
endif
if COND_GRUB_EMU_PCI
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libpciaccess.h
endif
endif
symlist.h: $(top_builddir)/config.h $(KERNEL_HEADER_FILES)
@list='$^'; \
for p in $$list; do \
echo "#include <$$p>" >> $@ || (rm -f $@; exit 1); \
done
CLEANFILES += symlist.h
BUILT_SOURCES += symlist.h
symlist.c: symlist.h gensymlist.sh
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1)
cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
rm -f symlist.p
CLEANFILES += symlist.c
BUILT_SOURCES += symlist.c
if COND_HAVE_ASM_USCORE
ASM_PREFIX=_
else
ASM_PREFIX=
endif
noinst_DATA += kernel_syms.lst
kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input
cat kernel_syms.input | grep -v '^#' | sed -n \
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
| sort -u >$@
rm -f kernel_syms.input
CLEANFILES += kernel_syms.lst
if COND_emu
kern/emu/grub_emu-main.$(OBJEXT):grub_emu_init.h
grub_emu-grub_emu_init.$(OBJEXT):grub_emu_init.h
kern/emu/grub_emu_dyn-main.$(OBJEXT):grub_emu_init.h
grub_emu_dyn-grub_emu_init.$(OBJEXT):grub_emu_init.h
grub_emu_init.h: genemuinitheader.sh $(MODULE_FILES)
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinitheader.sh $(TARGET_NM) > $@
CLEANFILES += grub_emu_init.h
grub_emu_init.c: grub_emu_init.h genemuinit.sh $(MODULE_FILES)
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinit.sh $(TARGET_NM) > $@
CLEANFILES += grub_emu_init.c
endif
# List files
fs.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'FS_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += fs.lst
CLEANFILES += fs.lst
command.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += command.lst
CLEANFILES += command.lst
partmap.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'PARTMAP_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += partmap.lst
CLEANFILES += partmap.lst
terminal.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/INPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
-e "/OUTPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += terminal.lst
CLEANFILES += terminal.lst
fdt.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += fdt.lst
CLEANFILES += fdt.lst
parttool.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/PARTTOOL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += parttool.lst
CLEANFILES += parttool.lst
video.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'VIDEO_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += video.lst
CLEANFILES += video.lst
# but, crypto.lst is simply copied
crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst
cp $^ $@
platform_DATA += crypto.lst
CLEANFILES += crypto.lst
syminfo.lst: gensyminfo.sh kernel_syms.lst $(MODULE_FILES)
cat kernel_syms.lst > $@.new
for m in $(MODULE_FILES); do \
sh $< $$m >> $@.new || exit 1; \
done
mv $@.new $@
# generate global module dependencies list
moddep.lst: syminfo.lst genmoddep.awk video.lst
cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1)
platform_DATA += moddep.lst
CLEANFILES += config.log syminfo.lst moddep.lst
$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT)
TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
platform_DATA += $(MOD_FILES)
platform_DATA += modinfo.sh
CLEANFILES += $(MOD_FILES)
if COND_ENABLE_EFIEMU
efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF)
-rm -f $@
-rm -f $@.bin
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m32 -Wall -Werror -nostdlib -static -O2 -c -o $@.bin $<
if test "x$(TARGET_APPLE_LINKER)" = x1; then \
$(TARGET_OBJCONV) -felf32 -nu -nd $@.bin $@ || exit 1; \
rm -f $@.bin ; \
elif test ! -z "$(TARGET_OBJ2ELF)"; then \
$(TARGET_OBJ2ELF) $@.bin || (rm -f $@.bin; exit 1); \
mv $@.bin $@ ; \
else \
mv $@.bin $@ ; \
fi
# Link format -arch,x86_64 means Apple linker
efiemu64_c.o: efiemu/runtime/efiemu.c
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -nostdlib -Wall -Werror -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
efiemu64_s.o: efiemu/runtime/efiemu.S
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -Wall -Werror -nostdlib -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELEF)
-rm -f $@
-rm -f $@.bin
$(TARGET_CC) -m64 $(EFIEMU64_LINK_FORMAT) -nostdlib -static -Wl,-r -o $@.bin $^
if test "x$(EFIEMU64_LINK_FORMAT)" = x-arch,x86_64; then \
$(TARGET_OBJCONV) -felf64 -nu -nd $@.bin $@ || exit 1; \
rm -f $@.bin; \
else \
mv $@.bin $@ ; \
fi
platform_DATA += efiemu32.o efiemu64.o
CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
endif
windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows
windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA)
test -d $(windowsdir)/$(target_cpu)-$(platform) || mkdir $(windowsdir)/$(target_cpu)-$(platform)
for x in $(platform_DATA); do \
cp -fp $$x $(windowsdir)/$(target_cpu)-$(platform)/$$x; \
done

View File

@@ -100,6 +100,10 @@ kernel = {
emu_cppflags = '$(CPPFLAGS_GNULIB)';
arm_uboot_ldflags = '-Wl,-r,-d';
arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
mips64_efi_ldflags = '-Wl,-r,-d';
mips64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame -R .MIPS.abiflags';
arm_coreboot_ldflags = '-Wl,-r,-d';
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
@@ -114,6 +118,7 @@ kernel = {
i386_coreboot_startup = kern/i386/coreboot/startup.S;
i386_multiboot_startup = kern/i386/coreboot/startup.S;
mips_startup = kern/mips/startup.S;
mips64_efi_startup = kern/mips64/efi/startup.S;
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
arm_uboot_startup = kern/arm/startup.S;
@@ -310,6 +315,15 @@ kernel = {
extra_dist = video/sis315_init.c;
mips_loongson = commands/keylayouts.c;
mips64 = kern/mips64/init.c;
mips64 = kern/mips64/dl.c;
mips64 = kern/mips64/cache.S;
mips64 = kern/generic/rtc_get_time_ms.c;
mips64_efi = kern/mips64/efi/init.c;
mips64_efi = kern/mips64/efi/loongson.c;
mips64_efi = lib/mips64/efi/loongson.c;
mips64_efi = lib/mips64/efi/loongson_asm.S;
powerpc_ieee1275 = kern/powerpc/cache.S;
powerpc_ieee1275 = kern/powerpc/dl.c;
powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
@@ -828,6 +842,7 @@ module = {
enable = sparc64_ieee1275;
enable = powerpc_ieee1275;
enable = mips_arc;
enable = mips64_efi;
enable = ia64_efi;
enable = arm_efi;
enable = arm64_efi;
@@ -1588,6 +1603,7 @@ module = {
module = {
name = ventoy;
common = ventoy/ventoy.c;
common = ventoy/ventoy_cmd.c;
common = ventoy/ventoy_linux.c;
common = ventoy/ventoy_unix.c;
common = ventoy/ventoy_windows.c;
@@ -1597,6 +1613,12 @@ module = {
common = ventoy/lzx.c;
common = ventoy/xpress.c;
common = ventoy/huffman.c;
common = ventoy/miniz.c;
};
module = {
name = setkey;
common = term/setkey.c;
};
module = {
@@ -1661,6 +1683,8 @@ module = {
efi = lib/efi/relocator.c;
mips = lib/mips/relocator_asm.S;
mips = lib/mips/relocator.c;
mips64 = lib/mips64/relocator_asm.S;
mips64 = lib/mips64/relocator.c;
powerpc = lib/powerpc/relocator_asm.S;
powerpc = lib/powerpc/relocator.c;
xen = lib/xen/relocator.c;
@@ -1673,6 +1697,7 @@ module = {
extra_dist = kern/powerpc/cache_flush.S;
enable = mips;
enable = mips64;
enable = powerpc;
enable = x86;
enable = i386_xen_pvh;
@@ -1803,6 +1828,7 @@ module = {
i386_pc = lib/i386/pc/vesa_modes_table.c;
i386_xen_pvh = lib/i386/pc/vesa_modes_table.c;
mips = loader/mips/linux.c;
mips64 = loader/mips64/linux.c;
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
ia64_efi = loader/ia64/efi/linux.c;
@@ -1909,6 +1935,7 @@ module = {
enable = riscv32_efi;
enable = riscv64_efi;
enable = mips;
enable = mips64_efi;
};
module = {

View File

@@ -479,7 +479,7 @@ LOCAL(stop):
jmp LOCAL(stop)
ventoy_uuid: .ascii "XXXXXXXXXXXXXXXX"
notification_string: .asciz "GR"
notification_string: .asciz "VT"
geometry_error_string: .asciz "Ge"
hd_probe_error_string: .asciz "HD"
read_error_string: .asciz "Rd"

View File

@@ -0,0 +1,343 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/extcmd.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/crypto.h>
#include <grub/normal.h>
#include <grub/i18n.h>
GRUB_MOD_LICENSE ("GPLv3+");
static const struct grub_arg_option options[] = {
{"hash", 'h', 0, N_("Specify hash to use."), N_("HASH"), ARG_TYPE_STRING},
{"check", 'c', 0, N_("Check hashes of files with hash list FILE."),
N_("FILE"), ARG_TYPE_STRING},
{"prefix", 'p', 0, N_("Base directory for hash list."), N_("DIR"),
ARG_TYPE_STRING},
{"keep-going", 'k', 0, N_("Don't stop after first error."), 0, 0},
{"uncompress", 'u', 0, N_("Uncompress file before checksumming."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
static struct { const char *name; const char *hashname; } aliases[] =
{
{"sha256sum", "sha256"},
{"sha512sum", "sha512"},
{"sha1sum", "sha1"},
{"md5sum", "md5"},
{"crc", "crc32"},
};
static inline int
hextoval (char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static grub_err_t
hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result)
{
int progress = 0;
grub_uint64_t ro = 0;
grub_uint64_t div = 0;
grub_uint64_t total = 0;
void *context;
grub_uint8_t *readbuf;
#define BUF_SIZE 1024 * 1024
readbuf = grub_malloc (BUF_SIZE);
if (!readbuf)
return grub_errno;
context = grub_zalloc (hash->contextsize);
if (!readbuf || !context)
goto fail;
if (file->size > 16 * 1024 * 1024)
progress = 1;
hash->init (context);
while (1)
{
grub_ssize_t r;
r = grub_file_read (file, readbuf, BUF_SIZE);
if (r < 0)
goto fail;
if (r == 0)
break;
hash->write (context, readbuf, r);
if (progress)
{
total += r;
div = grub_divmod64(total * 100, (grub_uint64_t)file->size, &ro);
grub_printf("\rCalculating %d%% ", (int)div);
grub_refresh();
}
}
hash->final (context);
grub_memcpy (result, hash->read (context), hash->mdlen);
grub_free (readbuf);
grub_free (context);
if (progress)
{
grub_printf("\rCalculating 100%% \n\r\n");
grub_refresh();
}
return GRUB_ERR_NONE;
fail:
grub_free (readbuf);
grub_free (context);
return grub_errno;
}
static grub_err_t
check_list (const gcry_md_spec_t *hash, const char *hashfilename,
const char *prefix, int keep, int uncompress)
{
grub_file_t hashlist, file;
char *buf = NULL;
grub_uint8_t expected[GRUB_CRYPTO_MAX_MDLEN];
grub_uint8_t actual[GRUB_CRYPTO_MAX_MDLEN];
grub_err_t err;
unsigned i;
unsigned unread = 0, mismatch = 0;
if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
return grub_error (GRUB_ERR_BUG, "mdlen is too long");
hashlist = grub_file_open (hashfilename, GRUB_FILE_TYPE_HASHLIST);
if (!hashlist)
return grub_errno;
while (grub_free (buf), (buf = grub_file_getline (hashlist)))
{
const char *p = buf;
while (grub_isspace (p[0]))
p++;
for (i = 0; i < hash->mdlen; i++)
{
int high, low;
high = hextoval (*p++);
low = hextoval (*p++);
if (high < 0 || low < 0)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
expected[i] = (high << 4) | low;
}
if ((p[0] != ' ' && p[0] != '\t') || (p[1] != ' ' && p[1] != '\t'))
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
p += 2;
if (prefix)
{
char *filename;
filename = grub_xasprintf ("%s/%s", prefix, p);
if (!filename)
return grub_errno;
file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
: GRUB_FILE_TYPE_NONE));
grub_free (filename);
}
else
file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
: GRUB_FILE_TYPE_NONE));
if (!file)
{
grub_file_close (hashlist);
grub_free (buf);
return grub_errno;
}
err = hash_file (file, hash, actual);
grub_file_close (file);
if (err)
{
grub_printf_ (N_("%s: READ ERROR\n"), p);
if (!keep)
{
grub_file_close (hashlist);
grub_free (buf);
return err;
}
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
if (grub_crypto_memcmp (expected, actual, hash->mdlen) != 0)
{
grub_printf_ (N_("%s: HASH MISMATCH\n"), p);
if (!keep)
{
grub_file_close (hashlist);
grub_free (buf);
return grub_error (GRUB_ERR_TEST_FAILURE,
"hash of '%s' mismatches", p);
}
mismatch++;
continue;
}
grub_printf_ (N_("%s: OK\n"), p);
}
if (mismatch || unread)
return grub_error (GRUB_ERR_TEST_FAILURE,
"%d files couldn't be read and hash "
"of %d files mismatches", unread, mismatch);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
const char *hashname = NULL;
const char *prefix = NULL;
const gcry_md_spec_t *hash;
unsigned i;
int keep = state[3].set;
int uncompress = state[4].set;
unsigned unread = 0;
for (i = 0; i < ARRAY_SIZE (aliases); i++)
if (grub_strcmp (ctxt->extcmd->cmd->name, aliases[i].name) == 0)
hashname = aliases[i].hashname;
if (state[0].set)
hashname = state[0].arg;
if (!hashname)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no hash specified");
hash = grub_crypto_lookup_md_by_name (hashname);
if (!hash)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown hash");
if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
return grub_error (GRUB_ERR_BUG, "mdlen is too long");
if (state[2].set)
prefix = state[2].arg;
if (state[1].set)
{
if (argc != 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"--check is incompatible with file list");
return check_list (hash, state[1].arg, prefix, keep, uncompress);
}
for (i = 0; i < (unsigned) argc; i++)
{
GRUB_PROPERLY_ALIGNED_ARRAY (result, GRUB_CRYPTO_MAX_MDLEN);
grub_file_t file;
grub_err_t err;
unsigned j;
file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
: GRUB_FILE_TYPE_NONE));
if (!file)
{
if (!keep)
return grub_errno;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
err = hash_file (file, hash, result);
grub_file_close (file);
if (err)
{
if (!keep)
return err;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
for (j = 0; j < hash->mdlen; j++)
grub_printf ("%02x", ((grub_uint8_t *) result)[j]);
grub_printf (" %s\n", args[i]);
}
if (unread)
return grub_error (GRUB_ERR_TEST_FAILURE, "%d files couldn't be read",
unread);
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd, cmd_md5, cmd_sha1, cmd_sha256, cmd_sha512, cmd_crc;
GRUB_MOD_INIT(hashsum)
{
cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum, 0,
N_("-h HASH [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
/* TRANSLATORS: "hash checksum" is just to
be a bit more precise, you can treat it as
just "hash". */
N_("Compute or check hash checksum."),
options);
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
cmd_sha1 = grub_register_extcmd ("sha1sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
cmd_crc = grub_register_extcmd ("crc", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
}
GRUB_MOD_FINI(hashsum)
{
grub_unregister_extcmd (cmd);
grub_unregister_extcmd (cmd_md5);
grub_unregister_extcmd (cmd_sha1);
grub_unregister_extcmd (cmd_sha256);
grub_unregister_extcmd (cmd_sha512);
grub_unregister_extcmd (cmd_crc);
}

View File

@@ -0,0 +1,353 @@
/* search.c - search devices based on a file or a filesystem label */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
#include <grub/file.h>
#include <grub/env.h>
#include <grub/command.h>
#include <grub/search.h>
#include <grub/i18n.h>
#include <grub/disk.h>
#include <grub/partition.h>
GRUB_MOD_LICENSE ("GPLv3+");
static int g_no_vtoyefi_part = 0;
static char g_vtoyefi_dosname[64];
static char g_vtoyefi_gptname[64];
struct cache_entry
{
struct cache_entry *next;
char *key;
char *value;
};
static struct cache_entry *cache;
/* Context for FUNC_NAME. */
struct search_ctx
{
const char *key;
const char *var;
int no_floppy;
char **hints;
unsigned nhints;
int count;
int is_cache;
};
/* Helper for FUNC_NAME. */
static int
iterate_device (const char *name, void *data)
{
struct search_ctx *ctx = data;
int found = 0;
/* Skip floppy drives when requested. */
if (ctx->no_floppy &&
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
return 1;
if (g_no_vtoyefi_part && (grub_strcmp(name, g_vtoyefi_dosname) == 0 || grub_strcmp(name, g_vtoyefi_gptname) == 0)) {
return 0;
}
#ifdef DO_SEARCH_FS_UUID
#define compare_fn grub_strcasecmp
#else
#define compare_fn grub_strcmp
#endif
#ifdef DO_SEARCH_FILE
{
char *buf;
grub_file_t file;
buf = grub_xasprintf ("(%s)%s", name, ctx->key);
if (! buf)
return 1;
file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (file)
{
found = 1;
grub_file_close (file);
}
grub_free (buf);
}
#else
{
/* SEARCH_FS_UUID or SEARCH_LABEL */
grub_device_t dev;
grub_fs_t fs;
char *quid;
dev = grub_device_open (name);
if (dev)
{
fs = grub_fs_probe (dev);
#ifdef DO_SEARCH_FS_UUID
#define read_fn fs_uuid
#else
#define read_fn fs_label
#endif
if (fs && fs->read_fn)
{
fs->read_fn (dev, &quid);
if (grub_errno == GRUB_ERR_NONE && quid)
{
if (compare_fn (quid, ctx->key) == 0)
found = 1;
grub_free (quid);
}
}
grub_device_close (dev);
}
}
#endif
if (!ctx->is_cache && found && ctx->count == 0)
{
struct cache_entry *cache_ent;
cache_ent = grub_malloc (sizeof (*cache_ent));
if (cache_ent)
{
cache_ent->key = grub_strdup (ctx->key);
cache_ent->value = grub_strdup (name);
if (cache_ent->value && cache_ent->key)
{
cache_ent->next = cache;
cache = cache_ent;
}
else
{
grub_free (cache_ent->value);
grub_free (cache_ent->key);
grub_free (cache_ent);
grub_errno = GRUB_ERR_NONE;
}
}
else
grub_errno = GRUB_ERR_NONE;
}
if (found)
{
ctx->count++;
if (ctx->var)
grub_env_set (ctx->var, name);
else
grub_printf (" %s", name);
}
grub_errno = GRUB_ERR_NONE;
return (found && ctx->var);
}
/* Helper for FUNC_NAME. */
static int
part_hook (grub_disk_t disk, const grub_partition_t partition, void *data)
{
struct search_ctx *ctx = data;
char *partition_name, *devname;
int ret;
partition_name = grub_partition_get_name (partition);
if (! partition_name)
return 1;
devname = grub_xasprintf ("%s,%s", disk->name, partition_name);
grub_free (partition_name);
if (!devname)
return 1;
ret = iterate_device (devname, ctx);
grub_free (devname);
return ret;
}
/* Helper for FUNC_NAME. */
static void
try (struct search_ctx *ctx)
{
unsigned i;
struct cache_entry **prev;
struct cache_entry *cache_ent;
for (prev = &cache, cache_ent = *prev; cache_ent;
prev = &cache_ent->next, cache_ent = *prev)
if (compare_fn (cache_ent->key, ctx->key) == 0)
break;
if (cache_ent)
{
ctx->is_cache = 1;
if (iterate_device (cache_ent->value, ctx))
{
ctx->is_cache = 0;
return;
}
ctx->is_cache = 0;
/* Cache entry was outdated. Remove it. */
if (!ctx->count)
{
*prev = cache_ent->next;
grub_free (cache_ent->key);
grub_free (cache_ent->value);
grub_free (cache_ent);
}
}
for (i = 0; i < ctx->nhints; i++)
{
char *end;
if (!ctx->hints[i][0])
continue;
end = ctx->hints[i] + grub_strlen (ctx->hints[i]) - 1;
if (*end == ',')
*end = 0;
if (iterate_device (ctx->hints[i], ctx))
{
if (!*end)
*end = ',';
return;
}
if (!*end)
{
grub_device_t dev;
int ret;
dev = grub_device_open (ctx->hints[i]);
if (!dev)
{
if (!*end)
*end = ',';
continue;
}
if (!dev->disk)
{
grub_device_close (dev);
if (!*end)
*end = ',';
continue;
}
ret = grub_partition_iterate (dev->disk, part_hook, ctx);
if (!*end)
*end = ',';
grub_device_close (dev);
if (ret)
return;
}
}
grub_device_iterate (iterate_device, ctx);
}
void
FUNC_NAME (const char *key, const char *var, int no_floppy,
char **hints, unsigned nhints)
{
struct search_ctx ctx = {
.key = key,
.var = var,
.no_floppy = no_floppy,
.hints = hints,
.nhints = nhints,
.count = 0,
.is_cache = 0
};
grub_fs_autoload_hook_t saved_autoload;
g_no_vtoyefi_part = 0;
if (grub_env_get("VTOY_SEARCH_NO_VTOYEFI"))
{
grub_snprintf(g_vtoyefi_dosname, sizeof(g_vtoyefi_dosname), "%s,msdos2", grub_env_get("vtoydev"));
grub_snprintf(g_vtoyefi_gptname, sizeof(g_vtoyefi_gptname), "%s,gpt2", grub_env_get("vtoydev"));
g_no_vtoyefi_part = 1;
}
/* First try without autoloading if we're setting variable. */
if (var)
{
saved_autoload = grub_fs_autoload_hook;
grub_fs_autoload_hook = 0;
try (&ctx);
/* Restore autoload hook. */
grub_fs_autoload_hook = saved_autoload;
/* Retry with autoload if nothing found. */
if (grub_errno == GRUB_ERR_NONE && ctx.count == 0)
try (&ctx);
}
else
try (&ctx);
if (grub_errno == GRUB_ERR_NONE && ctx.count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
}
static grub_err_t
grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
char **args)
{
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (args + 2),
argc > 2 ? argc - 2 : 0);
return grub_errno;
}
static grub_command_t cmd;
#ifdef DO_SEARCH_FILE
GRUB_MOD_INIT(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_INIT(search_fs_uuid)
#else
GRUB_MOD_INIT(search_label)
#endif
{
cmd =
grub_register_command (COMMAND_NAME, grub_cmd_do_search,
N_("NAME [VARIABLE] [HINTS]"),
HELP_MESSAGE);
}
#ifdef DO_SEARCH_FILE
GRUB_MOD_FINI(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_FINI(search_fs_uuid)
#else
GRUB_MOD_FINI(search_label)
#endif
{
grub_unregister_command (cmd);
}

View File

@@ -0,0 +1,257 @@
/* loopback.c - command to add loopback devices. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/mm.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
GRUB_MOD_LICENSE ("GPLv3+");
struct grub_loopback
{
char *devname;
grub_file_t file;
struct grub_loopback *next;
unsigned long id;
grub_off_t skip;
};
static struct grub_loopback *loopback_list;
static unsigned long last_id = 0;
static const struct grub_arg_option options[] =
{
/* TRANSLATORS: The disk is simply removed from the list of available ones,
not wiped, avoid to scare user. */
{"delete", 'd', 0, N_("Delete the specified loopback drive."), 0, 0},
{"skip", 's', 0, "skip sectors of the file.", "SECTORS", ARG_TYPE_INT },
{0, 0, 0, 0, 0, 0}
};
/* Delete the loopback device NAME. */
static grub_err_t
delete_loopback (const char *name)
{
struct grub_loopback *dev;
struct grub_loopback **prev;
/* Search for the device. */
for (dev = loopback_list, prev = &loopback_list;
dev;
prev = &dev->next, dev = dev->next)
if (grub_strcmp (dev->devname, name) == 0)
break;
if (! dev)
return grub_error (GRUB_ERR_BAD_DEVICE, "device not found");
/* Remove the device from the list. */
*prev = dev->next;
grub_free (dev->devname);
grub_file_close (dev->file);
grub_free (dev);
return 0;
}
/* The command to add and remove loopback devices. */
static grub_err_t
grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
grub_file_t file;
struct grub_loopback *newdev;
grub_err_t ret;
grub_off_t skip = 0;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
/* Check if `-d' was used. */
if (state[0].set)
return delete_loopback (args[0]);
if (state[1].set)
skip = (grub_off_t)grub_strtoull(state[1].arg, NULL, 10);
if (argc < 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (! file)
return grub_errno;
/* First try to replace the old device. */
for (newdev = loopback_list; newdev; newdev = newdev->next)
if (grub_strcmp (newdev->devname, args[0]) == 0)
break;
if (newdev)
{
grub_file_close (newdev->file);
newdev->file = file;
newdev->skip = skip;
return 0;
}
/* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev)
goto fail;
newdev->devname = grub_strdup (args[0]);
if (! newdev->devname)
{
grub_free (newdev);
goto fail;
}
newdev->file = file;
newdev->skip = skip;
newdev->id = last_id++;
/* Add the new entry to the list. */
newdev->next = loopback_list;
loopback_list = newdev;
return 0;
fail:
ret = grub_errno;
grub_file_close (file);
return ret;
}
static int
grub_loopback_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
grub_disk_pull_t pull)
{
struct grub_loopback *d;
if (pull != GRUB_DISK_PULL_NONE)
return 0;
for (d = loopback_list; d; d = d->next)
{
if (hook (d->devname, hook_data))
return 1;
}
return 0;
}
static grub_err_t
grub_loopback_open (const char *name, grub_disk_t disk)
{
struct grub_loopback *dev;
for (dev = loopback_list; dev; dev = dev->next)
if (grub_strcmp (dev->devname, name) == 0)
break;
if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
/* Use the filesize for the disk size, round up to a complete sector. */
if (dev->file->size != GRUB_FILE_SIZE_UNKNOWN)
disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1)
/ GRUB_DISK_SECTOR_SIZE);
else
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
/* Avoid reading more than 512M. */
disk->max_agglomerate = 1 << (29 - GRUB_DISK_SECTOR_BITS
- GRUB_DISK_CACHE_BITS);
disk->id = dev->id;
disk->data = dev;
return 0;
}
static grub_err_t
grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf)
{
grub_file_t file = ((struct grub_loopback *) disk->data)->file;
grub_off_t skip = ((struct grub_loopback *) disk->data)->skip;
grub_off_t pos;
grub_file_seek (file, (sector + skip) << GRUB_DISK_SECTOR_BITS);
grub_file_read (file, buf, size << GRUB_DISK_SECTOR_BITS);
if (grub_errno)
return grub_errno;
/* In case there is more data read than there is available, in case
of files that are not a multiple of GRUB_DISK_SECTOR_SIZE, fill
the rest with zeros. */
pos = (sector + skip + size) << GRUB_DISK_SECTOR_BITS;
if (pos > file->size)
{
grub_size_t amount = pos - file->size;
grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
}
return 0;
}
static grub_err_t
grub_loopback_write (grub_disk_t disk __attribute ((unused)),
grub_disk_addr_t sector __attribute ((unused)),
grub_size_t size __attribute ((unused)),
const char *buf __attribute ((unused)))
{
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"loopback write is not supported");
}
static struct grub_disk_dev grub_loopback_dev =
{
.name = "loopback",
.id = GRUB_DISK_DEVICE_LOOPBACK_ID,
.disk_iterate = grub_loopback_iterate,
.disk_open = grub_loopback_open,
.disk_read = grub_loopback_read,
.disk_write = grub_loopback_write,
.next = 0
};
static grub_extcmd_t cmd;
GRUB_MOD_INIT(loopback)
{
cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, 0,
N_("[-d] DEVICENAME FILE."),
/* TRANSLATORS: The file itself is not destroyed
or transformed into drive. */
N_("Make a virtual drive from a file."), options);
grub_disk_dev_register (&grub_loopback_dev);
}
GRUB_MOD_FINI(loopback)
{
grub_unregister_extcmd (cmd);
grub_disk_dev_unregister (&grub_loopback_dev);
}

View File

@@ -735,6 +735,8 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
{
if ((dirent.flags & FLAG_TYPE) == FLAG_TYPE_DIR)
ctx.type = GRUB_FSHELP_DIR;
else if ((dirent.flags & FLAG_TYPE) == 3)
ctx.type = GRUB_FSHELP_DIR;
else
ctx.type = GRUB_FSHELP_REG;
}

View File

@@ -28,6 +28,8 @@
extern int g_ventoy_memdisk_mode;
extern int g_ventoy_iso_raw;
extern int g_ventoy_grub2_mode;
extern int g_ventoy_wimboot_mode;
extern int g_ventoy_iso_uefi_drv;
static const char *align_options[] =
@@ -205,6 +207,12 @@ label_set_property (void *vself, const char *name, const char *value)
else if (grub_strcmp (value, "@VTOY_ISO_RAW@") == 0) {
value = g_ventoy_iso_raw ? grub_env_get("VTOY_ISO_RAW_STR") : " ";
}
else if (grub_strcmp (value, "@VTOY_GRUB2_MODE@") == 0) {
value = g_ventoy_grub2_mode ? grub_env_get("VTOY_GRUB2_MODE_STR") : " ";
}
else if (grub_strcmp (value, "@VTOY_WIMBOOT_MODE@") == 0) {
value = g_ventoy_wimboot_mode ? grub_env_get("VTOY_WIMBOOT_MODE_STR") : " ";
}
else if (grub_strcmp (value, "@VTOY_ISO_UEFI_DRV@") == 0) {
value = g_ventoy_iso_uefi_drv ? grub_env_get("VTOY_ISO_UEFI_DRV_STR") : " ";
}

View File

@@ -964,3 +964,20 @@ void * grub_efi_allocate_iso_buf(grub_uint64_t size)
return (void *)(unsigned long)address;
}
void * grub_efi_allocate_chain_buf(grub_uint64_t size)
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;
grub_efi_physical_address_t address = 0;
grub_efi_uintn_t pages = GRUB_EFI_BYTES_TO_PAGES(size);
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_DATA, pages, &address);
if (status != GRUB_EFI_SUCCESS)
{
return NULL;
}
return (void *)(unsigned long)address;
}

View File

@@ -0,0 +1,672 @@
/* mm.c - generic EFI memory management */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/cpu/efi/memory.h>
#if defined (__i386__) || defined (__x86_64__)
#include <grub/pci.h>
#endif
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
#define BYTES_TO_PAGES_DOWN(bytes) ((bytes) >> 12)
#define PAGES_TO_BYTES(pages) ((pages) << 12)
/* The size of a memory map obtained from the firmware. This must be
a multiplier of 4KB. */
#define MEMORY_MAP_SIZE 0x3000
/* The minimum and maximum heap size for GRUB itself. */
#define MIN_HEAP_SIZE 0x100000
#define MAX_HEAP_SIZE (1600 * 0x100000)
static void *finish_mmap_buf = 0;
static grub_efi_uintn_t finish_mmap_size = 0;
static grub_efi_uintn_t finish_key = 0;
static grub_efi_uintn_t finish_desc_size;
static grub_efi_uint32_t finish_desc_version;
int grub_efi_is_finished = 0;
/*
* We need to roll back EFI allocations on exit. Remember allocations that
* we'll free on exit.
*/
struct efi_allocation;
struct efi_allocation {
grub_efi_physical_address_t address;
grub_efi_uint64_t pages;
struct efi_allocation *next;
};
static struct efi_allocation *efi_allocated_memory;
static void
grub_efi_store_alloc (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
struct efi_allocation *alloc;
grub_efi_status_t status;
b = grub_efi_system_table->boot_services;
status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
sizeof(*alloc), (void**)&alloc);
if (status == GRUB_EFI_SUCCESS)
{
alloc->next = efi_allocated_memory;
alloc->address = address;
alloc->pages = pages;
efi_allocated_memory = alloc;
}
else
grub_printf ("Could not malloc memory to remember EFI allocation. "
"Exiting GRUB won't free all memory.\n");
}
static void
grub_efi_drop_alloc (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
struct efi_allocation *ea, *eap;
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
for (eap = NULL, ea = efi_allocated_memory; ea; eap = ea, ea = ea->next)
{
if (ea->address != address || ea->pages != pages)
continue;
/* Remove the current entry from the list. */
if (eap)
eap->next = ea->next;
else
efi_allocated_memory = ea->next;
/* Then free the memory backing it. */
efi_call_1 (b->free_pool, ea);
/* And leave, we're done. */
break;
}
}
/* Allocate pages. Return the pointer to the first of allocated pages. */
void *
grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
grub_efi_uintn_t pages,
grub_efi_allocate_type_t alloctype,
grub_efi_memory_type_t memtype)
{
grub_efi_status_t status;
grub_efi_boot_services_t *b;
/* Limit the memory access to less than 4GB for 32-bit platforms. */
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
return 0;
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
if (status != GRUB_EFI_SUCCESS)
return 0;
if (address == 0)
{
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
address = GRUB_EFI_MAX_USABLE_ADDRESS;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
return 0;
}
grub_efi_store_alloc (address, pages);
return (void *) ((grub_addr_t) address);
}
void *
grub_efi_allocate_any_pages (grub_efi_uintn_t pages)
{
return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS,
pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS,
GRUB_EFI_LOADER_DATA);
}
void *
grub_efi_allocate_fixed (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
return grub_efi_allocate_pages_real (address, pages,
GRUB_EFI_ALLOCATE_ADDRESS,
GRUB_EFI_LOADER_DATA);
}
/* Free pages starting from ADDRESS. */
void
grub_efi_free_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
efi_call_2 (b->free_pages, address, pages);
grub_efi_drop_alloc (address, pages);
}
#if defined (__i386__) || defined (__x86_64__)
/* Helper for stop_broadcom. */
static int
find_card (grub_pci_device_t dev, grub_pci_id_t pciid,
void *data __attribute__ ((unused)))
{
grub_pci_address_t addr;
grub_uint8_t cap;
grub_uint16_t pm_state;
if ((pciid & 0xffff) != GRUB_PCI_VENDOR_BROADCOM)
return 0;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
if (grub_pci_read (addr) >> 24 != GRUB_PCI_CLASS_NETWORK)
return 0;
cap = grub_pci_find_capability (dev, GRUB_PCI_CAP_POWER_MANAGEMENT);
if (!cap)
return 0;
addr = grub_pci_make_address (dev, cap + 4);
pm_state = grub_pci_read_word (addr);
pm_state = pm_state | 0x03;
grub_pci_write_word (addr, pm_state);
grub_pci_read_word (addr);
return 0;
}
static void
stop_broadcom (void)
{
grub_pci_iterate (find_card, NULL);
}
#endif
grub_err_t
grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
grub_efi_uintn_t *map_key,
grub_efi_uintn_t *efi_desc_size,
grub_efi_uint32_t *efi_desc_version)
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;
#if defined (__i386__) || defined (__x86_64__)
const grub_uint16_t apple[] = { 'A', 'p', 'p', 'l', 'e' };
int is_apple;
is_apple = (grub_memcmp (grub_efi_system_table->firmware_vendor,
apple, sizeof (apple)) == 0);
#endif
while (1)
{
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
&finish_desc_size, &finish_desc_version) < 0)
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
if (outbuf && *outbuf_size < finish_mmap_size)
return grub_error (GRUB_ERR_IO, "memory map buffer is too small");
finish_mmap_buf = grub_malloc (finish_mmap_size);
if (!finish_mmap_buf)
return grub_errno;
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
&finish_desc_size, &finish_desc_version) <= 0)
{
grub_free (finish_mmap_buf);
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
}
b = grub_efi_system_table->boot_services;
status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
finish_key);
if (status == GRUB_EFI_SUCCESS)
break;
if (status != GRUB_EFI_INVALID_PARAMETER)
{
grub_free (finish_mmap_buf);
return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
}
grub_free (finish_mmap_buf);
grub_printf ("Trying to terminate EFI services again\n");
}
grub_efi_is_finished = 1;
if (outbuf_size)
*outbuf_size = finish_mmap_size;
if (outbuf)
grub_memcpy (outbuf, finish_mmap_buf, finish_mmap_size);
if (map_key)
*map_key = finish_key;
if (efi_desc_size)
*efi_desc_size = finish_desc_size;
if (efi_desc_version)
*efi_desc_version = finish_desc_version;
#if defined (__i386__) || defined (__x86_64__)
if (is_apple)
stop_broadcom ();
#endif
return GRUB_ERR_NONE;
}
/*
* To obtain the UEFI memory map, we must pass a buffer of sufficient size
* to hold the entire map. This function returns a sane start value for
* buffer size.
*/
grub_efi_uintn_t
grub_efi_find_mmap_size (void)
{
grub_efi_uintn_t mmap_size = 0;
grub_efi_uintn_t desc_size;
if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0)
{
grub_error (GRUB_ERR_IO, "cannot get EFI memory map size");
return 0;
}
/*
* Add an extra page, since UEFI can alter the memory map itself on
* callbacks or explicit calls, including console output.
*/
return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_SIZE);
}
/* Get the memory map as defined in the EFI spec. Return 1 if successful,
return 0 if partial, or return -1 if an error occurs. */
int
grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size,
grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t *map_key,
grub_efi_uintn_t *descriptor_size,
grub_efi_uint32_t *descriptor_version)
{
grub_efi_status_t status;
grub_efi_boot_services_t *b;
grub_efi_uintn_t key;
grub_efi_uint32_t version;
grub_efi_uintn_t size;
if (grub_efi_is_finished)
{
int ret = 1;
if (*memory_map_size < finish_mmap_size)
{
grub_memcpy (memory_map, finish_mmap_buf, *memory_map_size);
ret = 0;
}
else
{
grub_memcpy (memory_map, finish_mmap_buf, finish_mmap_size);
ret = 1;
}
*memory_map_size = finish_mmap_size;
if (map_key)
*map_key = finish_key;
if (descriptor_size)
*descriptor_size = finish_desc_size;
if (descriptor_version)
*descriptor_version = finish_desc_version;
return ret;
}
/* Allow some parameters to be missing. */
if (! map_key)
map_key = &key;
if (! descriptor_version)
descriptor_version = &version;
if (! descriptor_size)
descriptor_size = &size;
b = grub_efi_system_table->boot_services;
status = efi_call_5 (b->get_memory_map, memory_map_size, memory_map, map_key,
descriptor_size, descriptor_version);
if (*descriptor_size == 0)
*descriptor_size = sizeof (grub_efi_memory_descriptor_t);
if (status == GRUB_EFI_SUCCESS)
return 1;
else if (status == GRUB_EFI_BUFFER_TOO_SMALL)
return 0;
else
return -1;
}
/* Sort the memory map in place. */
static void
sort_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *d1;
grub_efi_memory_descriptor_t *d2;
for (d1 = memory_map;
d1 < memory_map_end;
d1 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size))
{
grub_efi_memory_descriptor_t *max_desc = d1;
for (d2 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size);
d2 < memory_map_end;
d2 = NEXT_MEMORY_DESCRIPTOR (d2, desc_size))
{
if (max_desc->num_pages < d2->num_pages)
max_desc = d2;
}
if (max_desc != d1)
{
grub_efi_memory_descriptor_t tmp;
tmp = *d1;
*d1 = *max_desc;
*max_desc = tmp;
}
}
}
/* Filter the descriptors. GRUB needs only available memory. */
static grub_efi_memory_descriptor_t *
filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_memory_descriptor_t *filtered_memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
grub_efi_memory_descriptor_t *filtered_desc;
for (desc = memory_map, filtered_desc = filtered_memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
{
if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY
#if 1
&& desc->physical_start <= GRUB_EFI_MAX_USABLE_ADDRESS
#endif
&& desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
&& desc->num_pages != 0)
{
grub_memcpy (filtered_desc, desc, desc_size);
/* Avoid less than 1MB, because some loaders seem to be confused. */
if (desc->physical_start < 0x100000)
{
desc->num_pages -= BYTES_TO_PAGES (0x100000
- desc->physical_start);
desc->physical_start = 0x100000;
}
#if 1
if (BYTES_TO_PAGES (filtered_desc->physical_start)
+ filtered_desc->num_pages
> BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS))
filtered_desc->num_pages
= (BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS)
- BYTES_TO_PAGES (filtered_desc->physical_start));
#endif
if (filtered_desc->num_pages == 0)
continue;
filtered_desc = NEXT_MEMORY_DESCRIPTOR (filtered_desc, desc_size);
}
}
return filtered_desc;
}
/* Return the total number of pages. */
static grub_efi_uint64_t
get_total_pages (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
grub_efi_uint64_t total = 0;
for (desc = memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
total += desc->num_pages;
return total;
}
/* Add memory regions. */
static void
add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end,
grub_efi_uint64_t required_pages)
{
grub_efi_memory_descriptor_t *desc;
for (desc = memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_uint64_t pages;
grub_efi_physical_address_t start;
void *addr;
start = desc->physical_start;
pages = desc->num_pages;
if (pages > required_pages)
{
start += PAGES_TO_BYTES (pages - required_pages);
pages = required_pages;
}
addr = grub_efi_allocate_pages_real (start, pages,
GRUB_EFI_ALLOCATE_ADDRESS,
GRUB_EFI_LOADER_CODE);
if (! addr)
grub_fatal ("cannot allocate conventional memory %p with %u pages",
(void *) ((grub_addr_t) start),
(unsigned) pages);
grub_mm_init_region (addr, PAGES_TO_BYTES (pages));
required_pages -= pages;
if (required_pages == 0)
break;
}
if (required_pages > 0)
grub_fatal ("too little memory");
}
void
grub_efi_memory_fini (void)
{
/*
* Free all stale allocations. grub_efi_free_pages() will remove
* the found entry from the list and it will always find the first
* list entry (efi_allocated_memory is the list start). Hence we
* remove all entries from the list until none is left altogether.
*/
while (efi_allocated_memory)
grub_efi_free_pages (efi_allocated_memory->address,
efi_allocated_memory->pages);
}
#if 0
/* Print the memory map. */
static void
print_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
int i;
for (desc = memory_map, i = 0;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size), i++)
{
grub_printf ("MD: t=%x, p=%llx, v=%llx, n=%llx, a=%llx\n",
desc->type, desc->physical_start, desc->virtual_start,
desc->num_pages, desc->attribute);
}
}
#endif
void
grub_efi_mm_init (void)
{
grub_efi_memory_descriptor_t *memory_map;
grub_efi_memory_descriptor_t *memory_map_end;
grub_efi_memory_descriptor_t *filtered_memory_map;
grub_efi_memory_descriptor_t *filtered_memory_map_end;
grub_efi_uintn_t map_size;
grub_efi_uintn_t desc_size;
grub_efi_uint64_t total_pages;
grub_efi_uint64_t required_pages;
int mm_status;
/* Prepare a memory region to store two memory maps. */
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
if (! memory_map)
grub_fatal ("cannot allocate memory");
/* Obtain descriptors for available memory. */
map_size = MEMORY_MAP_SIZE;
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0);
if (mm_status == 0)
{
grub_efi_free_pages
((grub_efi_physical_address_t) ((grub_addr_t) memory_map),
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
/* Freeing/allocating operations may increase memory map size. */
map_size += desc_size * 32;
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size));
if (! memory_map)
grub_fatal ("cannot allocate memory");
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0,
&desc_size, 0);
}
if (mm_status < 0)
grub_fatal ("cannot get memory map");
memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size);
filtered_memory_map = memory_map_end;
filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
desc_size, memory_map_end);
/* By default, request a quarter of the available memory. */
total_pages = get_total_pages (filtered_memory_map, desc_size,
filtered_memory_map_end);
#if defined (__mips__) && (_MIPS_SIM == _ABI64)
required_pages = (total_pages > 4096) ? (total_pages - 4096) : (total_pages >> 1);
#else
required_pages = (total_pages >> 2);
#endif
if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
/* Sort the filtered descriptors, so that GRUB can allocate pages
from smaller regions. */
sort_memory_map (filtered_memory_map, desc_size, filtered_memory_map_end);
/* Allocate memory regions for GRUB's memory management. */
add_memory_regions (filtered_memory_map, desc_size,
filtered_memory_map_end, required_pages);
#if 0
/* For debug. */
map_size = MEMORY_MAP_SIZE;
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0)
grub_fatal ("cannot get memory map");
grub_printf ("printing memory map\n");
print_memory_map (memory_map, desc_size,
NEXT_MEMORY_DESCRIPTOR (memory_map, map_size));
grub_fatal ("Debug. ");
#endif
/* Release the memory maps. */
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
}
#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
grub_err_t
grub_efi_get_ram_base(grub_addr_t *base_addr)
{
grub_efi_memory_descriptor_t *memory_map, *desc;
grub_efi_uintn_t memory_map_size, desc_size;
int ret;
memory_map_size = grub_efi_find_mmap_size();
memory_map = grub_malloc (memory_map_size);
if (! memory_map)
return GRUB_ERR_OUT_OF_MEMORY;
ret = grub_efi_get_memory_map (&memory_map_size, memory_map, NULL,
&desc_size, NULL);
if (ret < 1)
return GRUB_ERR_BUG;
for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS;
(grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size);
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
if (desc->attribute & GRUB_EFI_MEMORY_WB)
*base_addr = grub_min (*base_addr, desc->physical_start);
grub_free(memory_map);
return GRUB_ERR_NONE;
}
#endif

View File

@@ -0,0 +1,23 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009,2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
FUNCTION (grub_arch_sync_caches)
jr.hb $ra

View File

@@ -0,0 +1,150 @@
/* dl-mips64.c - arch-dependent part of loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2007,2009,2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/elf.h>
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/cpu/types.h>
#include <grub/mm.h>
#include <grub/i18n.h>
/* Check if EHDR is a valid ELF header. */
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
#ifdef GRUB_CPU_WORDS_BIGENDIAN
if (e->e_ident[EI_CLASS] != ELFCLASS64
|| e->e_ident[EI_DATA] != ELFDATA2MSB
|| e->e_machine != EM_MIPS)
#else
if (e->e_ident[EI_CLASS] != ELFCLASS64
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|| e->e_machine != EM_MIPS)
#endif
return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
return GRUB_ERR_NONE;
}
#pragma GCC diagnostic ignored "-Wcast-align"
grub_err_t
grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
grub_size_t *tramp, grub_size_t *got)
{
*tramp = 0;
*got = 0;
return GRUB_ERR_NONE;
}
/* Relocate symbols. */
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
Elf_Shdr *s, grub_dl_segment_t seg)
{
Elf_Ehdr *e = ehdr;
Elf_Rel *rel, *max;
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = (Elf_Rel *) ((char *) rel + s->sh_size);
rel < max;
rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
{
grub_uint8_t *addr;
Elf_Sym *sym;
Elf_Addr r_info;
grub_uint64_t sym_value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
r_info = ((grub_uint64_t) rel->r_info << 32) |
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
addr = (grub_uint8_t *) ((char *) seg->addr + rel->r_offset);
sym = (Elf_Sym *) ((char *) mod->symtab
+ mod->symsize * ELF_R_SYM (r_info));
sym_value = sym->st_value;
if (s->sh_type == SHT_RELA)
{
sym_value += ((Elf_Rela *) rel)->r_addend;
}
switch (ELF_R_TYPE (r_info))
{
case R_MIPS_64:
*(grub_uint64_t *) addr += sym_value;
break;
case R_MIPS_32:
*(grub_uint32_t *) addr += sym_value;
break;
case R_MIPS_26:
{
grub_uint32_t value;
grub_uint32_t raw;
raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
value = raw << 2;
value += sym_value;
raw = (value >> 2) & 0x3ffffff;
*(grub_uint32_t *) addr =
raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
}
break;
case R_MIPS_LO16:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) sym_value;
break;
case R_MIPS_HI16:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x8000UL) >> 16);
break;
case R_MIPS_HIGHER:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x80008000UL) >> 32);
break;
case R_MIPS_HIGHEST:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_uint16_t) ((sym_value + 0x800080008000UL) >> 48);
break;
default:
{
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%x is not implemented yet"),
ELF_R_TYPE (r_info));
}
break;
}
}
return GRUB_ERR_NONE;
}

View File

@@ -0,0 +1,85 @@
/* init.c - initialize an arm-based EFI system */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/env.h>
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/cpu/time.h>
#include <grub/efi/efi.h>
#include <grub/loader.h>
#include <grub/time.h>
#include <grub/machine/loongson.h>
static grub_uint64_t tmr;
static grub_efi_event_t tmr_evt;
static grub_uint64_t
grub_efi_get_time_ms (void)
{
return tmr;
}
static void
grub_loongson_increment_timer (grub_efi_event_t event __attribute__ ((unused)),
void *context __attribute__ ((unused)))
{
tmr += 10;
}
void
grub_machine_init (void)
{
grub_efi_boot_services_t *b;
grub_efi_init ();
b = grub_efi_system_table->boot_services;
efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
grub_install_get_time_ms (grub_efi_get_time_ms);
if (grub_efi_is_loongson ())
grub_efi_loongson_init ();
else
/* FIXME: Get cpuclock from EFI. */
grub_timer_init (1000000000U);
}
void
grub_machine_fini (int flags)
{
grub_efi_boot_services_t *b;
if (!(flags & GRUB_LOADER_FLAG_NORETURN))
return;
b = grub_efi_system_table->boot_services;
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
efi_call_1 (b->close_event, tmr_evt);
if (grub_efi_is_loongson ())
grub_efi_loongson_fini ();
grub_efi_fini ();
}

View File

@@ -0,0 +1,33 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/efi/efi.h>
#include <grub/cpu/time.h>
#include <grub/loader.h>
#include <grub/machine/loongson.h>
void
grub_efi_loongson_init (void)
{
}
void
grub_efi_loongson_fini (void)
{
}

View File

@@ -0,0 +1,47 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
.file "startup.S"
.text
.set push
.align 4
FUNCTION(_start)
/*
* EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0.
*/
daddiu $sp, -16
sd $ra, ($sp)
dla $a2, grub_efi_image_handle
sd $a0, ($a2)
dla $a2, grub_efi_system_table
sd $a1, ($a2)
jal grub_main
1:
ld $ra, ($sp)
daddiu $sp, 16
jr $ra
.set pop

View File

@@ -0,0 +1,47 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009,2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/kernel.h>
#include <grub/env.h>
#include <grub/time.h>
#include <grub/cpu/mips.h>
grub_uint32_t grub_arch_cpuclock;
/* FIXME: use interrupt to count high. */
grub_uint64_t
grub_get_rtc (void)
{
static grub_uint32_t high = 0;
static grub_uint32_t last = 0;
grub_uint32_t low;
asm volatile ("mfc0 %0, " GRUB_CPU_MIPS_COP0_TIMER_COUNT : "=r" (low));
if (low < last)
high++;
last = low;
return (((grub_uint64_t) high) << 32) | low;
}
void
grub_timer_init (grub_uint32_t cpuclock)
{
grub_arch_cpuclock = cpuclock;
grub_install_get_time_ms (grub_rtc_get_time_ms);
}

View File

@@ -0,0 +1,133 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/term.h>
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/time.h>
struct grub_term_output *grub_term_outputs_disabled;
struct grub_term_input *grub_term_inputs_disabled;
struct grub_term_output *grub_term_outputs;
struct grub_term_input *grub_term_inputs;
/* Current color state. */
grub_uint8_t grub_term_normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR;
grub_uint8_t grub_term_highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR;
void (*grub_term_poll_usb) (int wait_for_completion) = NULL;
void (*grub_net_poll_cards_idle) (void) = NULL;
/* Put a Unicode character. */
static void
grub_putcode_dumb (grub_uint32_t code,
struct grub_term_output *term)
{
struct grub_unicode_glyph c =
{
.base = code,
.variant = 0,
.attributes = 0,
.ncomb = 0,
.estimated_width = 1
};
if (code == '\t' && term->getxy)
{
int n;
n = GRUB_TERM_TAB_WIDTH - ((term->getxy (term).x)
% GRUB_TERM_TAB_WIDTH);
while (n--)
grub_putcode_dumb (' ', term);
return;
}
(term->putchar) (term, &c);
if (code == '\n')
grub_putcode_dumb ('\r', term);
}
static void
grub_xputs_dumb (const char *str)
{
for (; *str; str++)
{
grub_term_output_t term;
grub_uint32_t code = *str;
if (code > 0x7f)
code = '?';
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_putcode_dumb (code, term);
}
}
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
int (*grub_key_remap)(int key) = NULL;
int
grub_getkey_noblock (void)
{
grub_term_input_t term;
if (grub_term_poll_usb)
grub_term_poll_usb (0);
if (grub_net_poll_cards_idle)
grub_net_poll_cards_idle ();
FOR_ACTIVE_TERM_INPUTS(term)
{
int key = term->getkey (term);
if (grub_key_remap)
key = grub_key_remap(key);
if (key != GRUB_TERM_NO_KEY)
return key;
}
return GRUB_TERM_NO_KEY;
}
int
grub_getkey (void)
{
int ret;
grub_refresh ();
while (1)
{
ret = grub_getkey_noblock ();
if (ret != GRUB_TERM_NO_KEY)
return ret;
grub_cpu_idle ();
}
}
void
grub_refresh (void)
{
struct grub_term_output *term;
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_term_refresh (term);
}

View File

@@ -0,0 +1,40 @@
/* efi.c - generic EFI support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/kernel.h>
#include <grub/acpi.h>
#include <grub/loader.h>
void
grub_halt (void)
{
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__mips__) &&\
!defined(__riscv)
grub_acpi_halt ();
#endif
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
while (1);
}

View File

@@ -0,0 +1,495 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/mm.h>
#include <grub/cache.h>
#include <grub/efi/efi.h>
#include <grub/cpu/efi/memory.h>
#include <grub/cpu/memory.h>
#include <grub/machine/loongson.h>
#pragma GCC diagnostic ignored "-Wunused-function"
#define loongson_params (&loongson_boot_params->boot_params.efi.smbios.lp)
#define loongson_boot_params_size ALIGN_UP (sizeof (*loongson_boot_params), 8)
#define loongson_reset_code_size (&grub_efi_loongson_reset_end - &grub_efi_loongson_reset_start)
extern grub_uint8_t grub_efi_loongson_reset_start;
extern grub_uint8_t grub_efi_loongson_reset_end;
static struct
{
grub_efi_loongson_boot_params boot_params;
grub_efi_loongson_memory_map memory_map;
grub_efi_loongson_cpu_info cpu_info;
grub_efi_loongson_system_info system_info;
grub_efi_loongson_irq_src_routing_table irq_src_routing_table;
grub_efi_loongson_interface_info interface_info;
grub_efi_loongson_special_attribute special_attribute;
grub_efi_loongson_board_devices board_devices;
} GRUB_PACKED
* loongson_boot_params;
static void
grub_efi_loongson_init_reset_system (void)
{
grub_efi_loongson_boot_params *boot_params;
grub_uint8_t *reset_code_addr = (grub_uint8_t *) loongson_boot_params +
loongson_boot_params_size;
boot_params = &loongson_boot_params->boot_params;
grub_efi_loongson_reset_system_addr =
(grub_uint64_t) grub_efi_system_table->runtime_services->reset_system;
grub_memcpy (reset_code_addr, &grub_efi_loongson_reset_start, loongson_reset_code_size);
grub_arch_sync_caches (reset_code_addr, loongson_reset_code_size);
boot_params->reset_system.reset_cold = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_cold -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.reset_warm = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_warm -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.shutdown = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_shutdown -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.do_suspend = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_suspend -
(grub_uint64_t) &grub_efi_loongson_reset_start);
}
static void
grub_efi_loongson_init_smbios (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_smbios_table *dst = &loongson_boot_params->boot_params.efi.smbios;
dst->vers = smbios_table->vers;
dst->vga_bios = smbios_table->vga_bios;
}
static void
grub_efi_loongson_init_cpu_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_cpu_info *src = (void *) smbios_table->lp.cpu_offset;
grub_efi_loongson_cpu_info *dst = &loongson_boot_params->cpu_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_cpu_info));
loongson_params->cpu_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_system_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_system_info *src = (void *) smbios_table->lp.system_offset;
grub_efi_loongson_system_info *dst = &loongson_boot_params->system_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_system_info));
loongson_params->system_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_irq_src_routing_table (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_irq_src_routing_table *src = (void *) smbios_table->lp.irq_offset;
grub_efi_loongson_irq_src_routing_table *dst = &loongson_boot_params->irq_src_routing_table;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_irq_src_routing_table));
loongson_params->irq_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_interface_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_interface_info *src = (void *) smbios_table->lp.interface_offset;
grub_efi_loongson_interface_info *dst = &loongson_boot_params->interface_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_interface_info));
loongson_params->interface_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_special_attribute (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_special_attribute *src = (void *) smbios_table->lp.special_offset;
grub_efi_loongson_special_attribute *dst = &loongson_boot_params->special_attribute;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_special_attribute));
loongson_params->special_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_board_devices (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_board_devices *src = (void *) smbios_table->lp.boarddev_table_offset;
grub_efi_loongson_board_devices *dst = &loongson_boot_params->board_devices;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_board_devices));
loongson_params->boarddev_table_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
static void
grub_efi_loongson_init_memory_map (grub_efi_loongson_smbios_table *smbios_table,
grub_efi_memory_descriptor_t *mmap_buf,
grub_efi_uintn_t mmap_size,
grub_efi_uintn_t desc_size)
{
grub_efi_loongson_memory_map *src = (void *) smbios_table->lp.memory_offset;
grub_efi_loongson_memory_map *dst = &loongson_boot_params->memory_map;
grub_efi_memory_descriptor_t *mmap_end;
grub_efi_memory_descriptor_t *desc;
grub_efi_memory_descriptor_t *desc_next;
grub_efi_uint32_t mem_types_reserved[] =
{
1, // GRUB_EFI_RESERVED_MEMORY_TYPE
0, // GRUB_EFI_LOADER_CODE
0, // GRUB_EFI_LOADER_DATA
0, // GRUB_EFI_BOOT_SERVICES_CODE
0, // GRUB_EFI_BOOT_SERVICES_DATA
1, // GRUB_EFI_RUNTIME_SERVICES_CODE
1, // GRUB_EFI_RUNTIME_SERVICES_DATA
0, // GRUB_EFI_CONVENTIONAL_MEMORY
1, // GRUB_EFI_UNUSABLE_MEMORY
0, // GRUB_EFI_ACPI_RECLAIM_MEMORY
0, // GRUB_EFI_ACPI_MEMORY_NVS
1, // GRUB_EFI_MEMORY_MAPPED_IO
1, // GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE
1, // GRUB_EFI_PAL_CODE
1, // GRUB_EFI_PERSISTENT_MEMORY
};
grub_uint32_t need_sort = 1;
if (!src)
return;
dst->vers = src->vers;
dst->nr_map = 0;
dst->mem_freq = src->mem_freq;
loongson_params->memory_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
if (!mmap_buf || !mmap_size || !desc_size)
return;
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
/* drop reserved */
for (desc = mmap_buf,
desc_next = desc;
desc < mmap_end;
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
desc->type = mem_types_reserved[desc->type];
if (desc->type)
continue;
if (desc != desc_next)
*desc_next = *desc;
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size);
}
mmap_end = desc_next;
/* sort: low->high */
while (need_sort)
{
need_sort = 0;
for (desc = mmap_buf,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
(desc < mmap_end) && (desc_next < mmap_end);
desc = desc_next,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_memory_descriptor_t tmp;
if (desc->physical_start <= desc_next->physical_start)
continue;
tmp = *desc;
*desc = *desc_next;
*desc_next = tmp;
need_sort = 1;
}
}
/* combine continuous memory map */
for (desc = mmap_buf,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
desc_next < mmap_end;
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size))
{
grub_efi_physical_address_t prev_end = desc->physical_start + (desc->num_pages << 12);
if (prev_end == desc_next->physical_start)
{
desc->num_pages += desc_next->num_pages;
continue;
}
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
grub_memcpy (desc, desc_next, desc_size);
}
mmap_end = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
/* write to loongson memory map */
for (desc = mmap_buf;
desc < mmap_end;
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_physical_address_t physical_start = grub_vtop ((void *) desc->physical_start);
grub_efi_physical_address_t physical_end = physical_start + (desc->num_pages << 12);
physical_start = ALIGN_UP (physical_start, 0x100000);
physical_end = ALIGN_DOWN (physical_end, 0x100000);
if (physical_start >= physical_end || (physical_end - physical_start) < 0x100000)
continue;
dst->map[dst->nr_map].node_id = (desc->physical_start >> 44) & 0xf;
dst->map[dst->nr_map].mem_type = (physical_end <= 0x10000000) ?
GRUB_EFI_LOONGSON_SYSTEM_RAM_LOW :
GRUB_EFI_LOONGSON_SYSTEM_RAM_HIGH;
dst->map[dst->nr_map].mem_start = physical_start;
dst->map[dst->nr_map].mem_size = (physical_end - physical_start) >> 20;
grub_dprintf ("loongson", "memory map %03u: 0x%016lx 0x%016lx @ %u\n",
dst->nr_map, physical_start, physical_end - physical_start,
dst->map[dst->nr_map].node_id);
dst->nr_map ++;
}
}
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
#define SUB_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) - (size)))
void
grub_efi_loongson_alloc_boot_params (void)
{
grub_efi_memory_descriptor_t *mmap_buf;
grub_efi_memory_descriptor_t *mmap_end;
grub_efi_memory_descriptor_t *desc;
grub_efi_uintn_t mmap_size;
grub_efi_uintn_t desc_size;
grub_efi_physical_address_t address;
grub_efi_allocate_type_t type;
grub_efi_uintn_t pages;
grub_efi_status_t status;
grub_efi_boot_services_t *b;
int mm_status;
type = GRUB_EFI_ALLOCATE_ADDRESS;
pages = BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size);
mmap_size = (1 << 12);
mmap_buf = grub_malloc (mmap_size);
if (!mmap_buf)
grub_fatal ("out of memory!");
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
if (mm_status == 0)
{
grub_free (mmap_buf);
mmap_size += desc_size * 32;
mmap_buf = grub_malloc (mmap_size);
if (!mmap_buf)
grub_fatal ("out of memory!");
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
}
if (mm_status < 0)
grub_fatal ("cannot get memory map!");
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
for (desc = SUB_MEMORY_DESCRIPTOR (mmap_end, desc_size);
desc >= mmap_buf;
desc = SUB_MEMORY_DESCRIPTOR (desc, desc_size))
{
if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY)
continue;
if (desc->physical_start >= GRUB_EFI_MAX_USABLE_ADDRESS)
continue;
if (desc->num_pages < pages)
continue;
address = desc->physical_start;
break;
}
grub_free (mmap_buf);
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_RUNTIME_SERVICES_DATA, pages, &address);
if (status != GRUB_EFI_SUCCESS)
grub_fatal ("cannot allocate Loongson boot parameters!");
loongson_boot_params = (void *) ((grub_addr_t) address);
}
void
grub_efi_loongson_free_boot_params (void)
{
grub_efi_free_pages ((grub_addr_t) loongson_boot_params,
BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size));
}
void *
grub_efi_loongson_get_smbios_table (void)
{
static grub_efi_loongson_smbios_table *smbios_table;
grub_efi_loongson_boot_params *old_boot_params;
struct bootparamsinterface* boot_params;
void * tmp_boot_params = NULL;
char * p = NULL;
if(smbios_table)
return smbios_table;
tmp_boot_params = grub_efi_loongson_get_boot_params();
if(tmp_boot_params == NULL)
{
grub_dprintf("loongson", "tmp_boot_params is NULL\n");
return tmp_boot_params;
}
boot_params = (struct bootparamsinterface *)tmp_boot_params;
p = (char *)&(boot_params->signature);
if(grub_strncmp(p, "BPI", 3) == 0)
{
grub_dprintf("loongson", "find new bpi\n");
return boot_params ? boot_params : 0;
}
else
{
old_boot_params = (grub_efi_loongson_boot_params *)tmp_boot_params;
return old_boot_params ? &old_boot_params->efi.smbios : 0;
}
}
int
grub_efi_is_loongson (void)
{
return grub_efi_loongson_get_smbios_table () ? 1 : 0;
}
void *
grub_efi_loongson_get_boot_params (void)
{
static void * boot_params = NULL;
grub_efi_configuration_table_t *tables;
grub_efi_guid_t smbios_guid = GRUB_EFI_LOONGSON_SMBIOS_TABLE_GUID;
unsigned int i;
if (boot_params)
return boot_params;
/* Look for Loongson SMBIOS in UEFI config tables. */
tables = grub_efi_system_table->configuration_table;
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
if (grub_memcmp (&tables[i].vendor_guid, &smbios_guid, sizeof (smbios_guid)) == 0)
{
boot_params= tables[i].vendor_table;
grub_dprintf ("loongson", "found registered SMBIOS @ %p\n", boot_params);
break;
}
return boot_params;
}
grub_uint8_t
grub_efi_loongson_calculatesum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
{
grub_uint8_t sum;
grub_efi_uintn_t count;
for (sum = 0, count = 0; count < length; count++)
{
sum = (grub_uint8_t) (sum + *(buffer + count));
}
return sum;
}
grub_uint8_t
grub_efi_loongson_grub_calculatechecksum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
{
grub_uint8_t checksum;
checksum = grub_efi_loongson_calculatesum8(buffer, length);
return (grub_uint8_t) (0x100 - checksum);
}
grub_uint32_t
grub_efi_loongson_memmap_sort(struct memmap array[], grub_uint32_t length, mem_map * bpmem, grub_uint32_t index, grub_uint32_t memtype)
{
grub_uint64_t tempmemsize = 0;
grub_uint32_t j = 0;
grub_uint32_t t = 0;
for(j = 0; j < length;)
{
tempmemsize = array[j].memsize;
for(t = j + 1; t < length; t++)
{
if(array[j].memstart + tempmemsize == array[t].memstart)
{
tempmemsize += array[t].memsize;
}
else
{
break;
}
}
bpmem->map[index].memtype = memtype;
bpmem->map[index].memstart = array[j].memstart;
bpmem->map[index].memsize = tempmemsize;
grub_dprintf("loongson", "map[%d]:type %x, start 0x%llx, end 0x%llx\n",
index,
bpmem->map[index].memtype,
(unsigned long long)bpmem->map[index].memstart,
(unsigned long long)bpmem->map[index].memstart+ bpmem->map[index].memsize
);
j = t;
index++;
}
return index;
}

View File

@@ -0,0 +1,61 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
.file "loongson.S"
.text
.set push
.set noreorder
.align 4
VARIABLE (grub_efi_loongson_reset_start)
VARIABLE (grub_efi_loongson_reset_system_addr)
.dword 0
reset_system:
bal 1f
move $a1, $zero
1:
ld $t9, -16($ra)
move $a2, $zero
jalr $t9
move $a3, $zero
FUNCTION(grub_efi_loongson_reset_cold)
b reset_system
li $a0, 0
FUNCTION(grub_efi_loongson_reset_warm)
b reset_system
li $a0, 1
FUNCTION(grub_efi_loongson_reset_shutdown)
b reset_system
li $a0, 2
FUNCTION(grub_efi_loongson_reset_suspend)
b reset_system
li $a0, 3
VARIABLE (grub_efi_loongson_reset_end)
.set pop

View File

@@ -0,0 +1,169 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/cache.h>
#include <grub/mips64/relocator.h>
#include <grub/relocator_private.h>
extern grub_uint8_t grub_relocator_forward_start;
extern grub_uint8_t grub_relocator_forward_end;
extern grub_uint8_t grub_relocator_backward_start;
extern grub_uint8_t grub_relocator_backward_end;
#define REGW_SIZEOF (6 * sizeof (grub_uint32_t))
#define JUMP_SIZEOF (2 * sizeof (grub_uint32_t))
#define RELOCATOR_SRC_SIZEOF(x) (&grub_relocator_##x##_end \
- &grub_relocator_##x##_start)
#define RELOCATOR_SIZEOF(x) (RELOCATOR_SRC_SIZEOF(x) \
+ REGW_SIZEOF * 3)
grub_size_t grub_relocator_align = sizeof (grub_uint64_t);
grub_size_t grub_relocator_forward_size;
grub_size_t grub_relocator_backward_size;
grub_size_t grub_relocator_jumper_size = JUMP_SIZEOF + REGW_SIZEOF;
void
grub_cpu_relocator_init (void)
{
grub_relocator_forward_size = RELOCATOR_SIZEOF(forward);
grub_relocator_backward_size = RELOCATOR_SIZEOF(backward);
}
static void
write_reg (int regn, grub_uint64_t val, void **target)
{
grub_uint32_t lui;
grub_uint32_t ori;
grub_uint32_t dsll;
/* lui $r, 0 */
lui = (0x3c00 | regn) << 16;
/* ori $r, $r, 0 */
ori = (0x3400 | (regn << 5) | regn) << 16;
/* dsll $r, $r, 16 */
dsll = (regn << 16) | (regn << 11) | (16 << 6) | 56;
/* lui $r, val[63:48]. */
*(grub_uint32_t *) *target = lui | (grub_uint16_t) (val >> 48);
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[47:32]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 32);
*target = ((grub_uint32_t *) *target) + 1;
/* dsll $r, $r, 16 */
*(grub_uint32_t *) *target = dsll;
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[31:16]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 16);
*target = ((grub_uint32_t *) *target) + 1;
/* dsll $r, $r, 16 */
*(grub_uint32_t *) *target = dsll;
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[15:0]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) val;
*target = ((grub_uint32_t *) *target) + 1;
}
static void
write_jump (int regn, void **target)
{
/* j $r. */
*(grub_uint32_t *) *target = (regn << 21) | 0x8;
*target = ((grub_uint32_t *) *target) + 1;
/* nop. */
*(grub_uint32_t *) *target = 0;
*target = ((grub_uint32_t *) *target) + 1;
}
void
grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
{
write_reg (1, addr, &rels);
write_jump (1, &rels);
}
void
grub_cpu_relocator_backward (void *ptr0, void *src, void *dest,
grub_size_t size)
{
void *ptr = ptr0;
write_reg (8, (grub_uint64_t) src, &ptr);
write_reg (9, (grub_uint64_t) dest, &ptr);
write_reg (10, (grub_uint64_t) size, &ptr);
grub_memcpy (ptr, &grub_relocator_backward_start,
RELOCATOR_SRC_SIZEOF (backward));
}
void
grub_cpu_relocator_forward (void *ptr0, void *src, void *dest,
grub_size_t size)
{
void *ptr = ptr0;
write_reg (8, (grub_uint64_t) src, &ptr);
write_reg (9, (grub_uint64_t) dest, &ptr);
write_reg (10, (grub_uint64_t) size, &ptr);
grub_memcpy (ptr, &grub_relocator_forward_start,
RELOCATOR_SRC_SIZEOF (forward));
}
grub_err_t
grub_relocator64_boot (struct grub_relocator *rel,
struct grub_relocator64_state state)
{
grub_relocator_chunk_t ch;
void *ptr;
grub_err_t err;
void *relst;
grub_size_t relsize;
grub_size_t stateset_size = 31 * REGW_SIZEOF + JUMP_SIZEOF;
unsigned i;
grub_addr_t vtarget;
err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
(0xffffffff - stateset_size)
+ 1, stateset_size,
grub_relocator_align,
GRUB_RELOCATOR_PREFERENCE_NONE, 0);
if (err)
return err;
ptr = get_virtual_current_address (ch);
for (i = 1; i < 32; i++)
write_reg (i, state.gpr[i], &ptr);
write_jump (state.jumpreg, &ptr);
vtarget = (grub_addr_t) grub_map_memory (get_physical_target_address (ch),
stateset_size);
err = grub_relocator_prepare_relocs (rel, vtarget, &relst, &relsize);
if (err)
return err;
grub_arch_sync_caches ((void *) relst, relsize);
((void (*) (void)) relst) ();
/* Not reached. */
return GRUB_ERR_NONE;
}

View File

@@ -0,0 +1,56 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
.p2align 4 /* force 16-byte alignment */
.set push
.set noreorder
.set nomacro
VARIABLE (grub_relocator_forward_start)
copycont1:
ld $11,0($8)
sd $11,0($9)
daddiu $8, $8, 8
daddiu $10, $10, -8
bne $10, $0, copycont1
daddiu $9, $9, 8
VARIABLE (grub_relocator_forward_end)
VARIABLE (grub_relocator_backward_start)
daddu $9, $9, $10
daddu $8, $8, $10
/* Backward movsl is implicitly off-by-one. compensate that. */
daddiu $9, $9, -8
daddiu $8, $8, -8
copycont2:
ld $11,0($8)
sd $11,0($9)
daddiu $8, $8, -8
daddiu $10, $10, -8
bne $10, $0, copycont2
daddiu $9, $9, -8
VARIABLE (grub_relocator_backward_end)
.set pop

View File

@@ -0,0 +1,69 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <grub/dl.h>
#include <grub/mips64/asm.h>
.file "setjmp.S"
GRUB_MOD_LICENSE "GPLv3+"
.text
/*
* int grub_setjmp (grub_jmp_buf env)
*/
FUNCTION(grub_setjmp)
GRUB_ASM_REG_S $s0, 0($a0)
GRUB_ASM_REG_S $s1, 8($a0)
GRUB_ASM_REG_S $s2, 16($a0)
GRUB_ASM_REG_S $s3, 24($a0)
GRUB_ASM_REG_S $s4, 32($a0)
GRUB_ASM_REG_S $s5, 40($a0)
GRUB_ASM_REG_S $s6, 48($a0)
GRUB_ASM_REG_S $s7, 56($a0)
GRUB_ASM_REG_S $s8, 64($a0)
GRUB_ASM_REG_S $gp, 72($a0)
GRUB_ASM_REG_S $sp, 80($a0)
GRUB_ASM_REG_S $ra, 88($a0)
move $v0, $zero
move $v1, $zero
jr $ra
nop
/*
* int grub_longjmp (grub_jmp_buf env, int val)
*/
FUNCTION(grub_longjmp)
GRUB_ASM_REG_L $s0, 0($a0)
GRUB_ASM_REG_L $s1, 8($a0)
GRUB_ASM_REG_L $s2, 16($a0)
GRUB_ASM_REG_L $s3, 24($a0)
GRUB_ASM_REG_L $s4, 32($a0)
GRUB_ASM_REG_L $s5, 40($a0)
GRUB_ASM_REG_L $s6, 48($a0)
GRUB_ASM_REG_L $s7, 56($a0)
GRUB_ASM_REG_L $s8, 64($a0)
GRUB_ASM_REG_L $gp, 72($a0)
GRUB_ASM_REG_L $sp, 80($a0)
GRUB_ASM_REG_L $ra, 88($a0)
addiu $v0, $zero, 1
movn $v0, $a1, $a1
move $v1, $zero
jr $ra
nop

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
#if defined(__i386__)
#include "./i386/setjmp.S"
#elif defined(__x86_64__)
#include "./x86_64/setjmp.S"
#elif defined(__sparc__)
#include "./sparc64/setjmp.S"
#elif defined(__mips__)
#if _MIPS_SIM == _ABI64
#include "./mips64/setjmp.S"
#else
#include "./mips/setjmp.S"
#endif
#elif defined(__powerpc__) || defined(__PPC__)
#include "./powerpc/setjmp.S"
#elif defined(__ia64__)
#include "./ia64/setjmp.S"
#include "./ia64/longjmp.S"
#elif defined(__arm__)
#include "./arm/setjmp.S"
#elif defined(__aarch64__)
#include "./arm64/setjmp.S"
#elif defined(__riscv)
#include "./riscv/setjmp.S"
#else
#error "Unknown target cpu type"
#endif

View File

@@ -0,0 +1,852 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/charset.h>
#include <grub/command.h>
#include <grub/err.h>
#include <grub/file.h>
#include <grub/fdt.h>
#include <grub/linux.h>
#include <grub/loader.h>
#include <grub/mm.h>
#include <grub/types.h>
#include <grub/cpu/linux.h>
#include <grub/efi/efi.h>
#include <grub/efi/fdtload.h>
#include <grub/efi/memory.h>
#include <grub/efi/pe32.h>
#include <grub/i18n.h>
#include <grub/lib/cmdline.h>
#include <grub/verify.h>
#include <grub/term.h>
#include <grub/env.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_dl_t my_mod;
static int loaded;
static void *kernel_addr;
static grub_uint64_t kernel_size;
static char *linux_args;
static grub_uint32_t cmdline_size;
static grub_addr_t initrd_start;
static grub_addr_t initrd_end;
#define LINUX_MAX_ARGC 1024
static int ventoy_debug = 0;
static int ventoy_initrd_called = 0;
static int ventoy_linux_argc = 0;
static char **ventoy_linux_args = NULL;
static int ventoy_extra_initrd_num = 0;
static char *ventoy_extra_initrd_list[256];
static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[]);
grub_err_t
grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
{
if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
grub_dprintf ("linux", "UEFI stub kernel:\n");
grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
return GRUB_ERR_NONE;
}
static grub_err_t
finalize_params_linux (void)
{
int node, retval;
void *fdt;
fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
if (!fdt)
goto failure;
node = grub_fdt_find_subnode (fdt, 0, "chosen");
if (node < 0)
node = grub_fdt_add_subnode (fdt, 0, "chosen");
if (node < 1)
goto failure;
/* Set initrd info */
if (initrd_start && initrd_end > initrd_start)
{
grub_dprintf ("linux", "Initrd @ %p-%p\n",
(void *) initrd_start, (void *) initrd_end);
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
initrd_start);
if (retval)
goto failure;
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end",
initrd_end);
if (retval)
goto failure;
}
if (grub_fdt_install() != GRUB_ERR_NONE)
goto failure;
return GRUB_ERR_NONE;
failure:
grub_fdt_unload();
return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
}
grub_err_t
grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
{
grub_efi_memory_mapped_device_path_t *mempath;
grub_efi_handle_t image_handle;
grub_efi_boot_services_t *b;
grub_efi_status_t status;
grub_efi_loaded_image_t *loaded_image;
int len;
mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
if (!mempath)
return grub_errno;
mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
mempath[0].start_address = addr;
mempath[0].end_address = addr + size;
mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
mempath[1].header.length = sizeof (grub_efi_device_path_t);
b = grub_efi_system_table->boot_services;
status = b->load_image (0, grub_efi_image_handle,
(grub_efi_device_path_t *) mempath,
(void *) addr, size, &image_handle);
if (status != GRUB_EFI_SUCCESS)
return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
grub_dprintf ("linux", "linux command line: '%s'\n", args);
/* Convert command line to UCS-2 */
loaded_image = grub_efi_get_loaded_image (image_handle);
loaded_image->load_options_size = len =
(grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
loaded_image->load_options =
grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
if (!loaded_image->load_options)
return grub_errno;
loaded_image->load_options_size =
2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
(grub_uint8_t *) args, len, NULL);
grub_dprintf ("linux", "starting image %p\n", image_handle);
status = b->start_image (image_handle, 0, NULL);
/* When successful, not reached */
b->unload_image (image_handle);
grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
return grub_errno;
}
static void ventoy_debug_pause(void)
{
char key;
if (0 == ventoy_debug)
{
return;
}
grub_printf("press Enter to continue ......\n");
while (1)
{
key = grub_getkey();
if (key == '\n' || key == '\r')
{
break;
}
}
}
static int ventoy_preboot(void)
{
int i;
const char *file;
char buf[128];
if (ventoy_debug)
{
grub_printf("ventoy_preboot %d %d\n", ventoy_linux_argc, ventoy_initrd_called);
ventoy_debug_pause();
}
if (ventoy_linux_argc == 0)
{
return 0;
}
if (ventoy_initrd_called)
{
ventoy_initrd_called = 0;
return 0;
}
grub_snprintf(buf, sizeof(buf), "mem:%s:size:%s", grub_env_get("ventoy_cpio_addr"), grub_env_get("ventoy_cpio_size"));
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);
file = grub_env_get("vtoy_img_part_file");
if (file)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(file);
}
if (ventoy_debug)
{
grub_printf("========== initrd list ==========\n");
for (i = 0; i < ventoy_extra_initrd_num; i++)
{
grub_printf("%s\n", ventoy_extra_initrd_list[i]);
}
grub_printf("=================================\n");
ventoy_debug_pause();
}
grub_cmd_initrd(NULL, ventoy_extra_initrd_num, ventoy_extra_initrd_list);
return 0;
}
static int ventoy_boot_opt_filter(char *opt)
{
if (grub_strcmp(opt, "noinitrd") == 0)
{
return 1;
}
if (grub_strcmp(opt, "vga=current") == 0)
{
return 1;
}
if (grub_strncmp(opt, "rdinit=", 7) == 0)
{
if (grub_strcmp(opt, "rdinit=/vtoy/vtoy") != 0)
{
opt[0] = 'v';
opt[1] = 't';
}
return 0;
}
if (grub_strncmp(opt, "init=", 5) == 0)
{
opt[0] = 'v';
opt[1] = 't';
return 0;
}
if (ventoy_debug)
{
if (grub_strcmp(opt, "quiet") == 0)
{
return 1;
}
if (grub_strncmp(opt, "loglevel=", 9) == 0)
{
return 1;
}
if (grub_strcmp(opt, "splash") == 0)
{
return 1;
}
}
return 0;
}
static int ventoy_bootopt_hook(int argc, char *argv[])
{
int i;
int TmpIdx;
int count = 0;
const char *env;
char c;
char *newenv;
char *last, *pos;
//grub_printf("ventoy_bootopt_hook: %d %d\n", argc, ventoy_linux_argc);
if (ventoy_linux_argc == 0)
{
return 0;
}
/* To avoid --- parameter, we split two parts */
for (TmpIdx = 0; TmpIdx < argc; TmpIdx++)
{
if (ventoy_boot_opt_filter(argv[TmpIdx]))
{
continue;
}
if (grub_strncmp(argv[TmpIdx], "--", 2) == 0)
{
break;
}
ventoy_linux_args[count++] = grub_strdup(argv[TmpIdx]);
}
for (i = 0; i < ventoy_linux_argc; i++)
{
ventoy_linux_args[count] = ventoy_linux_args[i + (LINUX_MAX_ARGC / 2)];
ventoy_linux_args[i + (LINUX_MAX_ARGC / 2)] = NULL;
if (ventoy_linux_args[count][0] == '@')
{
env = grub_env_get(ventoy_linux_args[count] + 1);
if (env)
{
grub_free(ventoy_linux_args[count]);
newenv = grub_strdup(env);
last = newenv;
while (*last)
{
while (*last)
{
if (*last != ' ' && *last != '\t')
{
break;
}
last++;
}
if (*last == 0)
{
break;
}
for (pos = last; *pos; pos++)
{
if (*pos == ' ' || *pos == '\t')
{
c = *pos;
*pos = 0;
if (0 == ventoy_boot_opt_filter(last))
{
ventoy_linux_args[count++] = grub_strdup(last);
}
*pos = c;
break;
}
}
if (*pos == 0)
{
if (0 == ventoy_boot_opt_filter(last))
{
ventoy_linux_args[count++] = grub_strdup(last);
}
break;
}
last = pos + 1;
}
}
else
{
count++;
}
}
else
{
count++;
}
}
while (TmpIdx < argc)
{
if (ventoy_boot_opt_filter(argv[TmpIdx]))
{
continue;
}
ventoy_linux_args[count++] = grub_strdup(argv[TmpIdx]);
TmpIdx++;
}
if (ventoy_debug)
{
ventoy_linux_args[count++] = grub_strdup("loglevel=7");
}
ventoy_linux_argc = count;
if (ventoy_debug)
{
grub_printf("========== bootoption ==========\n");
for (i = 0; i < count; i++)
{
grub_printf("%s ", ventoy_linux_args[i]);
}
grub_printf("\n================================\n");
}
return 0;
}
static grub_err_t
grub_cmd_set_boot_opt (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;
const char *vtdebug;
for (i = 0; i < argc; i++)
{
ventoy_linux_args[ventoy_linux_argc + (LINUX_MAX_ARGC / 2) ] = grub_strdup(argv[i]);
ventoy_linux_argc++;
}
vtdebug = grub_env_get("vtdebug_flag");
if (vtdebug && vtdebug[0])
{
ventoy_debug = 1;
}
if (ventoy_debug) grub_printf("ventoy set boot opt %d\n", ventoy_linux_argc);
return 0;
}
static grub_err_t
grub_cmd_unset_boot_opt (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;
(void)argc;
(void)argv;
for (i = 0; i < LINUX_MAX_ARGC; i++)
{
if (ventoy_linux_args[i])
{
grub_free(ventoy_linux_args[i]);
}
}
ventoy_debug = 0;
ventoy_linux_argc = 0;
ventoy_initrd_called = 0;
grub_memset(ventoy_linux_args, 0, sizeof(char *) * LINUX_MAX_ARGC);
return 0;
}
static grub_err_t
grub_cmd_extra_initrd_append (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int newclen = 0;
char *pos = NULL;
char *end = NULL;
char buf[256] = {0};
if (argc != 1)
{
return 1;
}
for (pos = argv[0]; *pos; pos++)
{
if (*pos == '/')
{
end = pos;
}
}
if (end)
{
/* grub2 newc bug workaround */
newclen = (int)grub_strlen(end + 1);
if ((110 + newclen) % 4 == 0)
{
grub_snprintf(buf, sizeof(buf), "newc:.%s:%s", end + 1, argv[0]);
}
else
{
grub_snprintf(buf, sizeof(buf), "newc:%s:%s", end + 1, argv[0]);
}
if (ventoy_extra_initrd_num < 256)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);
}
}
return 0;
}
static grub_err_t
grub_cmd_extra_initrd_reset (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;
(void)argc;
(void)argv;
for (i = 0; i < ventoy_extra_initrd_num; i++)
{
if (ventoy_extra_initrd_list[i])
{
grub_free(ventoy_extra_initrd_list[i]);
}
}
grub_memset(ventoy_extra_initrd_list, 0, sizeof(ventoy_extra_initrd_list));
return 0;
}
static grub_err_t
grub_linux_boot (void)
{
ventoy_preboot();
if (finalize_params_linux () != GRUB_ERR_NONE)
return grub_errno;
return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
kernel_size, linux_args));
}
static grub_err_t
grub_linux_unload (void)
{
grub_dl_unref (my_mod);
loaded = 0;
if (initrd_start)
grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start,
GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start));
initrd_start = initrd_end = 0;
grub_free (linux_args);
if (kernel_addr)
grub_efi_free_pages ((grub_addr_t) kernel_addr,
GRUB_EFI_BYTES_TO_PAGES (kernel_size));
grub_fdt_unload ();
return GRUB_ERR_NONE;
}
/*
* As per linux/Documentation/arm/Booting
* ARM initrd needs to be covered by kernel linear mapping,
* so place it in the first 512MB of DRAM.
*
* As per linux/Documentation/arm64/booting.txt
* ARM64 initrd needs to be contained entirely within a 1GB aligned window
* of up to 32GB of size that covers the kernel image as well.
* Since the EFI stub loader will attempt to load the kernel near start of
* RAM, place the buffer in the first 32GB of RAM.
*/
#ifdef __arm__
#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024)
#else /* __aarch64__ */
#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024)
#endif
/*
* This function returns a pointer to a legally allocated initrd buffer,
* or NULL if unsuccessful
*/
static void *
allocate_initrd_mem (int initrd_pages)
{
grub_addr_t max_addr;
if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
return NULL;
max_addr += INITRD_MAX_ADDRESS_OFFSET - 1;
return grub_efi_allocate_pages_real (max_addr, initrd_pages,
GRUB_EFI_ALLOCATE_MAX_ADDRESS,
GRUB_EFI_LOADER_DATA);
}
static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
int initrd_size, initrd_pages;
void *initrd_mem = NULL;
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
goto fail;
}
if (!loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("you need to load the kernel first"));
goto fail;
}
if (grub_initrd_init (argc, argv, &initrd_ctx))
goto fail;
initrd_size = grub_get_initrd_size (&initrd_ctx);
grub_dprintf ("linux", "Loading initrd\n");
initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size));
initrd_mem = allocate_initrd_mem (initrd_pages);
if (!initrd_mem)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
goto fail;
}
if (grub_initrd_load (&initrd_ctx, argv, initrd_mem))
goto fail;
initrd_start = (grub_addr_t) initrd_mem;
initrd_end = initrd_start + initrd_size;
grub_dprintf ("linux", "[addr=%p, size=0x%x]\n",
(void *) initrd_start, initrd_size);
fail:
grub_initrd_close (&initrd_ctx);
if (initrd_mem && !initrd_start)
grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages);
return grub_errno;
}
static grub_err_t
grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_file_t file = 0;
struct linux_arch_kernel_header lh;
grub_err_t err;
grub_dl_ref (my_mod);
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
goto fail;
}
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (!file)
goto fail;
kernel_size = grub_file_size (file);
if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
return grub_errno;
if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
goto fail;
grub_loader_unset();
grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
grub_dprintf ("linux", "kernel numpages: %lld\n",
(long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
if (!kernel_addr)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
goto fail;
}
grub_file_seek (file, 0);
if (grub_file_read (file, kernel_addr, kernel_size)
< (grub_int64_t) kernel_size)
{
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
goto fail;
}
grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
linux_args = grub_malloc (cmdline_size);
if (!linux_args)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
goto fail;
}
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
if (ventoy_linux_argc)
{
ventoy_bootopt_hook(argc, argv);
err = grub_create_loader_cmdline (ventoy_linux_argc, ventoy_linux_args,
linux_args + sizeof (LINUX_IMAGE) - 1,
cmdline_size,
GRUB_VERIFY_KERNEL_CMDLINE); }
else
{
err = grub_create_loader_cmdline (argc, argv,
linux_args + sizeof (LINUX_IMAGE) - 1,
cmdline_size,
GRUB_VERIFY_KERNEL_CMDLINE);
}
if (err)
goto fail;
if (grub_errno == GRUB_ERR_NONE)
{
grub_loader_set (grub_linux_boot, grub_linux_unload, 0);
loaded = 1;
}
fail:
if (file)
grub_file_close (file);
if (grub_errno != GRUB_ERR_NONE)
{
grub_dl_unref (my_mod);
loaded = 0;
}
if (linux_args && !loaded)
grub_free (linux_args);
if (kernel_addr && !loaded)
grub_efi_free_pages ((grub_addr_t) kernel_addr,
GRUB_EFI_BYTES_TO_PAGES (kernel_size));
return grub_errno;
}
static grub_err_t
ventoy_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;
const char *file;
char buf[64];
if (ventoy_debug) grub_printf("ventoy_cmd_initrd %d\n", ventoy_linux_argc);
if (ventoy_linux_argc == 0)
{
return grub_cmd_initrd(cmd, argc, argv);
}
grub_snprintf(buf, sizeof(buf), "mem:%s:size:%s", grub_env_get("ventoy_cpio_addr"), grub_env_get("ventoy_cpio_size"));
if (ventoy_debug) grub_printf("membuf=%s\n", buf);
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);
file = grub_env_get("vtoy_img_part_file");
if (file)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(file);
}
for (i = 0; i < argc; i++)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(argv[i]);
}
ventoy_initrd_called = 1;
if (ventoy_debug)
{
grub_printf("========== initrd list ==========\n");
for (i = 0; i < ventoy_extra_initrd_num; i++)
{
grub_printf("%s\n", ventoy_extra_initrd_list[i]);
}
grub_printf("=================================\n");
}
return grub_cmd_initrd(cmd, ventoy_extra_initrd_num, ventoy_extra_initrd_list);
}
static grub_command_t cmd_linux, cmd_initrd, cmd_linuxefi, cmd_initrdefi;
static grub_command_t cmd_set_bootopt, cmd_unset_bootopt, cmd_extra_initrd_append, cmd_extra_initrd_reset;
GRUB_MOD_INIT (linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0,
N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", ventoy_cmd_initrd, 0,
N_("Load initrd."));
cmd_linuxefi = grub_register_command ("linuxefi", grub_cmd_linux,
0, N_("Load Linux."));
cmd_initrdefi = grub_register_command ("initrdefi", ventoy_cmd_initrd,
0, N_("Load initrd."));
cmd_set_bootopt = grub_register_command ("vt_set_boot_opt", grub_cmd_set_boot_opt, 0, N_("set ext boot opt"));
cmd_unset_bootopt = grub_register_command ("vt_unset_boot_opt", grub_cmd_unset_boot_opt, 0, N_("unset ext boot opt"));
cmd_extra_initrd_append = grub_register_command ("vt_img_extra_initrd_append", grub_cmd_extra_initrd_append, 0, N_(""));
cmd_extra_initrd_reset = grub_register_command ("vt_img_extra_initrd_reset", grub_cmd_extra_initrd_reset, 0, N_(""));
ventoy_linux_args = grub_zalloc(sizeof(char *) * LINUX_MAX_ARGC);
my_mod = mod;
}
GRUB_MOD_FINI (linux)
{
grub_unregister_command (cmd_linux);
grub_unregister_command (cmd_initrd);
}

View File

@@ -88,7 +88,6 @@ static int ventoy_linux_argc = 0;
static char **ventoy_linux_args = NULL;
static int ventoy_extra_initrd_num = 0;
static char *ventoy_extra_initrd_list[256];
static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]);
@@ -531,6 +530,7 @@ static int ventoy_boot_opt_filter(char *opt)
static int ventoy_bootopt_hook(int argc, char *argv[])
{
int i;
int TmpIdx;
int count = 0;
const char *env;
char c;
@@ -544,14 +544,20 @@ static int ventoy_bootopt_hook(int argc, char *argv[])
return 0;
}
for (i = 0; i < argc; i++)
/* To avoid --- parameter, we split two parts */
for (TmpIdx = 0; TmpIdx < argc; TmpIdx++)
{
if (ventoy_boot_opt_filter(argv[i]))
if (ventoy_boot_opt_filter(argv[TmpIdx]))
{
continue;
}
ventoy_linux_args[count++] = grub_strdup(argv[i]);
if (grub_strncmp(argv[TmpIdx], "--", 2) == 0)
{
break;
}
ventoy_linux_args[count++] = grub_strdup(argv[TmpIdx]);
}
for (i = 0; i < ventoy_linux_argc; i++)
@@ -623,6 +629,17 @@ static int ventoy_bootopt_hook(int argc, char *argv[])
}
}
while (TmpIdx < argc)
{
if (ventoy_boot_opt_filter(argv[TmpIdx]))
{
continue;
}
ventoy_linux_args[count++] = grub_strdup(argv[TmpIdx]);
TmpIdx++;
}
if (ventoy_debug)
{
ventoy_linux_args[count++] = grub_strdup("loglevel=7");

View File

@@ -0,0 +1,316 @@
#include <grub/types.h>
#include <grub/err.h>
#include <grub/linux.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/env.h>
#include <grub/term.h>
struct newc_head
{
char magic[6];
char ino[8];
char mode[8];
char uid[8];
char gid[8];
char nlink[8];
char mtime[8];
char filesize[8];
char devmajor[8];
char devminor[8];
char rdevmajor[8];
char rdevminor[8];
char namesize[8];
char check[8];
} GRUB_PACKED;
struct grub_linux_initrd_component
{
grub_file_t file;
char *newc_name;
grub_off_t size;
};
struct dir
{
char *name;
struct dir *next;
struct dir *child;
};
static char
hex (grub_uint8_t val)
{
if (val < 10)
return '0' + val;
return 'a' + val - 10;
}
static void
set_field (char *var, grub_uint32_t val)
{
int i;
char *ptr = var;
for (i = 28; i >= 0; i -= 4)
*ptr++ = hex((val >> i) & 0xf);
}
static grub_uint8_t *
make_header (grub_uint8_t *ptr,
const char *name, grub_size_t len,
grub_uint32_t mode,
grub_off_t fsize)
{
struct newc_head *head = (struct newc_head *) ptr;
grub_uint8_t *optr;
grub_size_t oh = 0;
grub_memcpy (head->magic, "070701", 6);
set_field (head->ino, 0);
set_field (head->mode, mode);
set_field (head->uid, 0);
set_field (head->gid, 0);
set_field (head->nlink, 1);
set_field (head->mtime, 0);
set_field (head->filesize, fsize);
set_field (head->devmajor, 0);
set_field (head->devminor, 0);
set_field (head->rdevmajor, 0);
set_field (head->rdevminor, 0);
set_field (head->namesize, len);
set_field (head->check, 0);
optr = ptr;
ptr += sizeof (struct newc_head);
grub_memcpy (ptr, name, len);
ptr += len;
oh = ALIGN_UP_OVERHEAD (ptr - optr, 4);
grub_memset (ptr, 0, oh);
ptr += oh;
return ptr;
}
static void
free_dir (struct dir *root)
{
if (!root)
return;
free_dir (root->next);
free_dir (root->child);
grub_free (root->name);
grub_free (root);
}
static grub_size_t
insert_dir (const char *name, struct dir **root,
grub_uint8_t *ptr)
{
struct dir *cur, **head = root;
const char *cb, *ce = name;
grub_size_t size = 0;
while (1)
{
for (cb = ce; *cb == '/'; cb++);
for (ce = cb; *ce && *ce != '/'; ce++);
if (!*ce)
break;
for (cur = *root; cur; cur = cur->next)
if (grub_memcmp (cur->name, cb, ce - cb)
&& cur->name[ce - cb] == 0)
break;
if (!cur)
{
struct dir *n;
n = grub_zalloc (sizeof (*n));
if (!n)
return 0;
n->next = *head;
n->name = grub_strndup (cb, ce - cb);
if (ptr)
{
grub_dprintf ("linux", "Creating directory %s, %s\n", name, ce);
ptr = make_header (ptr, name, ce - name,
040777, 0);
}
size += ALIGN_UP ((ce - (char *) name)
+ sizeof (struct newc_head), 4);
*head = n;
cur = n;
}
root = &cur->next;
}
return size;
}
grub_err_t
grub_initrd_init (int argc, char *argv[],
struct grub_linux_initrd_context *initrd_ctx)
{
int i;
int newc = 0;
struct dir *root = 0;
initrd_ctx->nfiles = 0;
initrd_ctx->components = 0;
initrd_ctx->components = grub_zalloc (argc
* sizeof (initrd_ctx->components[0]));
if (!initrd_ctx->components)
return grub_errno;
initrd_ctx->size = 0;
for (i = 0; i < argc; i++)
{
const char *fname = argv[i];
initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
if (grub_memcmp (argv[i], "newc:", 5) == 0)
{
const char *ptr, *eptr;
ptr = argv[i] + 5;
while (*ptr == '/')
ptr++;
eptr = grub_strchr (ptr, ':');
if (eptr)
{
initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr);
if (!initrd_ctx->components[i].newc_name)
{
grub_initrd_close (initrd_ctx);
return grub_errno;
}
initrd_ctx->size
+= ALIGN_UP (sizeof (struct newc_head)
+ grub_strlen (initrd_ctx->components[i].newc_name),
4);
initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name,
&root, 0);
newc = 1;
fname = eptr + 1;
}
}
else if (newc)
{
initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head)
+ sizeof ("TRAILER!!!") - 1, 4);
free_dir (root);
root = 0;
newc = 0;
}
initrd_ctx->components[i].file = grub_file_open (fname,
GRUB_FILE_TYPE_LINUX_INITRD
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (!initrd_ctx->components[i].file)
{
grub_initrd_close (initrd_ctx);
return grub_errno;
}
initrd_ctx->nfiles++;
initrd_ctx->components[i].size
= grub_file_size (initrd_ctx->components[i].file);
initrd_ctx->size += initrd_ctx->components[i].size;
}
if (newc)
{
initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head)
+ sizeof ("TRAILER!!!") - 1, 4);
free_dir (root);
root = 0;
}
return GRUB_ERR_NONE;
}
grub_size_t
grub_get_initrd_size (struct grub_linux_initrd_context *initrd_ctx)
{
return initrd_ctx->size;
}
void
grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx)
{
int i;
if (!initrd_ctx->components)
return;
for (i = 0; i < initrd_ctx->nfiles; i++)
{
grub_free (initrd_ctx->components[i].newc_name);
grub_file_close (initrd_ctx->components[i].file);
}
grub_free (initrd_ctx->components);
initrd_ctx->components = 0;
}
extern int ventoy_need_prompt_load_file(void);
extern grub_ssize_t ventoy_load_file_with_prompt(grub_file_t file, void *buf, grub_ssize_t size);
grub_err_t
grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
char *argv[], void *target)
{
grub_uint8_t *ptr = target;
int i;
int newc = 0;
struct dir *root = 0;
grub_ssize_t cursize = 0;
grub_ssize_t readsize = 0;
for (i = 0; i < initrd_ctx->nfiles; i++)
{
grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
ptr += ALIGN_UP_OVERHEAD (cursize, 4);
if (initrd_ctx->components[i].newc_name)
{
ptr += insert_dir (initrd_ctx->components[i].newc_name,
&root, ptr);
ptr = make_header (ptr, initrd_ctx->components[i].newc_name,
grub_strlen (initrd_ctx->components[i].newc_name),
0100777,
initrd_ctx->components[i].size);
newc = 1;
}
else if (newc)
{
ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1,
0, 0);
free_dir (root);
root = 0;
newc = 0;
}
cursize = initrd_ctx->components[i].size;
if (ventoy_need_prompt_load_file() && initrd_ctx->components[i].newc_name &&
grub_strcmp(initrd_ctx->components[i].newc_name, "boot.wim") == 0)
{
readsize = ventoy_load_file_with_prompt(initrd_ctx->components[i].file, ptr, cursize);
}
else
{
readsize = grub_file_read (initrd_ctx->components[i].file, ptr, cursize);
}
if (readsize != cursize)
{
if (!grub_errno)
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
argv[i]);
grub_initrd_close (initrd_ctx);
return grub_errno;
}
ptr += cursize;
}
if (newc)
{
grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
ptr += ALIGN_UP_OVERHEAD (cursize, 4);
ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);
}
free_dir (root);
root = 0;
return GRUB_ERR_NONE;
}

File diff suppressed because it is too large Load Diff

View File

@@ -37,11 +37,14 @@
int g_ventoy_menu_refresh = 0;
int g_ventoy_memdisk_mode = 0;
int g_ventoy_iso_raw = 0;
int g_ventoy_grub2_mode = 0;
int g_ventoy_wimboot_mode = 0;
int g_ventoy_iso_uefi_drv = 0;
int g_ventoy_last_entry = -1;
int g_ventoy_suppress_esc = 0;
int g_ventoy_menu_esc = 0;
int g_ventoy_fn_mutex = 0;
int g_ventoy_terminal_output = 0;
/* Time to delay after displaying an error message about a default/fallback
entry failing to boot. */
@@ -871,15 +874,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
}
break;
case GRUB_TERM_KEY_F7:
case '7':
cmdstr = grub_env_get("VTOY_F7_CMD");
if (cmdstr)
menu_fini ();
if (g_ventoy_terminal_output == 0)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
grub_script_execute_sourcecode("terminal_output console");
g_ventoy_terminal_output = 1;
}
break;
else
{
grub_script_execute_sourcecode("terminal_output gfxterm");
g_ventoy_terminal_output = 0;
}
goto refresh;
case GRUB_TERM_KEY_F1:
case '1':
menu_fini ();
@@ -893,6 +899,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
g_ventoy_menu_refresh = 1;
goto refresh;
case (GRUB_TERM_CTRL | 'r'):
menu_fini ();
g_ventoy_grub2_mode = 1 - g_ventoy_grub2_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
case (GRUB_TERM_CTRL | 'w'):
menu_fini ();
g_ventoy_wimboot_mode = 1 - g_ventoy_wimboot_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
case (GRUB_TERM_CTRL | 'u'):
menu_fini ();
g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;

View File

@@ -0,0 +1,795 @@
#define ventoy_keyboard_set_layout(name) if (grub_strcmp(layout, #name) == 0) return ventoy_keyboard_layout_##name()
static void ventoy_keyboard_layout_QWERTY_USA(void) {
grub_keymap_reset();
grub_keymap_disable();
}
static void ventoy_keyboard_layout_AZERTY(void) {
grub_keymap_reset();
grub_keymap_add_by_string("a", "q");
grub_keymap_add_by_string("A", "Q");
grub_keymap_add_by_string("z", "w");
grub_keymap_add_by_string("Z", "W");
grub_keymap_add_by_string("q", "a");
grub_keymap_add_by_string("Q", "A");
grub_keymap_add_by_string("m", "semicolon");
grub_keymap_add_by_string("M", "colon");
grub_keymap_add_by_string("w", "z");
grub_keymap_add_by_string("W", "Z");
grub_keymap_add_by_string("comma", "m");
grub_keymap_add_by_string("question", "M");
grub_keymap_add_by_string("semicolon", "comma");
grub_keymap_add_by_string("period", "less");
grub_keymap_add_by_string("colon", "period");
grub_keymap_add_by_string("slash", "greater");
grub_keymap_add_by_string("exclam", "slash");
grub_keymap_add_by_string("dollar", "bracketright");
grub_keymap_add_by_string("asterisk", "backslash");
grub_keymap_add_by_string("percent", "doublequote");
grub_keymap_add_by_string("ampersand", "1");
grub_keymap_add_by_string("1", "exclam");
grub_keymap_add_by_string("tilde", "2");
grub_keymap_add_by_string("2", "at");
grub_keymap_add_by_string("doublequote", "3");
grub_keymap_add_by_string("3", "numbersign");
grub_keymap_add_by_string("quote", "4");
grub_keymap_add_by_string("4", "dollar");
grub_keymap_add_by_string("parenleft", "5");
grub_keymap_add_by_string("5", "percent");
grub_keymap_add_by_string("minus", "6");
grub_keymap_add_by_string("6", "caret");
grub_keymap_add_by_string("backquote", "7");
grub_keymap_add_by_string("7", "ampersand");
grub_keymap_add_by_string("underscore", "8");
grub_keymap_add_by_string("8", "asterisk");
grub_keymap_add_by_string("caret", "9");
grub_keymap_add_by_string("9", "parenleft");
grub_keymap_add_by_string("at", "0");
grub_keymap_add_by_string("0", "parenright");
grub_keymap_add_by_string("parenright", "minus");
grub_keymap_add_by_string("less", "backquote");
grub_keymap_add_by_string("greater", "tilde");
grub_keymap_add_by_string("numbersign", "braceright");
grub_keymap_add_by_string("backslash", "question");
grub_keymap_add_by_string("bracketright", "braceleft");
grub_keymap_add_by_string("braceleft", "quote");
grub_keymap_add_by_string("braceright", "underscore");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_CZECH_QWERTY(void) {
grub_keymap_reset();
grub_keymap_add_by_string("semicolon", "backquote");
grub_keymap_add_by_string("plus", "1");
grub_keymap_add_by_string("equal", "minus");
grub_keymap_add_by_string("quote", "equal");
grub_keymap_add_by_string("parenright", "bracketright");
grub_keymap_add_by_string("doublequote", "backslash");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("1", "exclam");
grub_keymap_add_by_string("2", "at");
grub_keymap_add_by_string("3", "numbersign");
grub_keymap_add_by_string("4", "dollar");
grub_keymap_add_by_string("5", "percent");
grub_keymap_add_by_string("6", "caret");
grub_keymap_add_by_string("7", "ampersand");
grub_keymap_add_by_string("8", "asterisk");
grub_keymap_add_by_string("9", "parenleft");
grub_keymap_add_by_string("0", "parenright");
grub_keymap_add_by_string("percent", "underscore");
grub_keymap_add_by_string("slash", "braceleft");
grub_keymap_add_by_string("parenleft", "braceright");
grub_keymap_add_by_string("doublequote", "colon");
grub_keymap_add_by_string("exclam", "doublequote");
grub_keymap_add_by_string("quote", "bar");
grub_keymap_add_by_string("question", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("backquote", "Abackquote");
grub_keymap_add_by_string("exclam", "A1");
grub_keymap_add_by_string("at", "A2");
grub_keymap_add_by_string("numbersign", "A3");
grub_keymap_add_by_string("dollar", "A4");
grub_keymap_add_by_string("percent", "A5");
grub_keymap_add_by_string("caret", "A6");
grub_keymap_add_by_string("ampersand", "A7");
grub_keymap_add_by_string("asterisk", "A8");
grub_keymap_add_by_string("parenleft", "A9");
grub_keymap_add_by_string("parenright", "A0");
grub_keymap_add_by_string("minus", "Aminus");
grub_keymap_add_by_string("equal", "Aequal");
grub_keymap_add_by_string("bracketleft", "Abracketleft");
grub_keymap_add_by_string("bracketright", "Abracketright");
grub_keymap_add_by_string("semicolon", "Asemicolon");
grub_keymap_add_by_string("backslash", "Abackslash");
grub_keymap_add_by_string("less", "Acomma");
grub_keymap_add_by_string("greater", "Aperiod");
grub_keymap_add_by_string("slash", "Aslash");
grub_keymap_add_by_string("tilde", "Atilde");
grub_keymap_add_by_string("underscore", "Aunderscore");
grub_keymap_add_by_string("plus", "Aplus");
grub_keymap_add_by_string("braceleft", "Abraceleft");
grub_keymap_add_by_string("braceright", "Abraceright");
grub_keymap_add_by_string("caret", "Adoublequote");
grub_keymap_add_by_string("colon", "Acolon");
grub_keymap_add_by_string("question", "Aquestion");
grub_keymap_add_by_string("bar", "Abar");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_CZECH_QWERTZ(void) {
grub_keymap_reset();
grub_keymap_add_by_string("y", "z");
grub_keymap_add_by_string("z", "y");
grub_keymap_add_by_string("Y", "Z");
grub_keymap_add_by_string("Z", "Y");
grub_keymap_add_by_string("semicolon", "backquote");
grub_keymap_add_by_string("plus", "1");
grub_keymap_add_by_string("equal", "minus");
grub_keymap_add_by_string("quote", "equal");
grub_keymap_add_by_string("parenright", "bracketright");
grub_keymap_add_by_string("doublequote", "backslash");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("1", "exclam");
grub_keymap_add_by_string("2", "at");
grub_keymap_add_by_string("3", "numbersign");
grub_keymap_add_by_string("4", "dollar");
grub_keymap_add_by_string("5", "percent");
grub_keymap_add_by_string("6", "caret");
grub_keymap_add_by_string("7", "ampersand");
grub_keymap_add_by_string("8", "asterisk");
grub_keymap_add_by_string("9", "parenleft");
grub_keymap_add_by_string("0", "parenright");
grub_keymap_add_by_string("percent", "underscore");
grub_keymap_add_by_string("slash", "braceleft");
grub_keymap_add_by_string("parenleft", "braceright");
grub_keymap_add_by_string("doublequote", "colon");
grub_keymap_add_by_string("exclam", "doublequote");
grub_keymap_add_by_string("quote", "bar");
grub_keymap_add_by_string("question", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("tilde", "A1");
grub_keymap_add_by_string("caret", "A3");
grub_keymap_add_by_string("backslash", "Aq");
grub_keymap_add_by_string("bar", "Aw");
grub_keymap_add_by_string("bracketleft", "Af");
grub_keymap_add_by_string("bracketright", "Ag");
grub_keymap_add_by_string("dollar", "Asemicolon");
grub_keymap_add_by_string("numbersign", "Ax");
grub_keymap_add_by_string("ampersand", "Ac");
grub_keymap_add_by_string("at", "Av");
grub_keymap_add_by_string("braceleft", "Ab");
grub_keymap_add_by_string("braceright", "An");
grub_keymap_add_by_string("less", "Acomma");
grub_keymap_add_by_string("greater", "Aperiod");
grub_keymap_add_by_string("asterisk", "Aslash");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_DANISH(void) {
grub_keymap_reset();
grub_keymap_add_by_string("plus", "minus");
grub_keymap_add_by_string("quote", "equal");
grub_keymap_add_by_string("doublequote", "bracketright");
grub_keymap_add_by_string("quote", "backslash");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("caret", "braceright");
grub_keymap_add_by_string("asterisk", "bar");
grub_keymap_add_by_string("backquote", "plus");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("bar", "Atilde");
grub_keymap_add_by_string("backslash", "Abackquote");
grub_keymap_add_by_string("greater", "tilde");
grub_keymap_add_by_string("at", "A2");
grub_keymap_add_by_string("dollar", "A4");
grub_keymap_add_by_string("braceleft", "A7");
grub_keymap_add_by_string("bracketleft", "A8");
grub_keymap_add_by_string("bracketright", "A9");
grub_keymap_add_by_string("braceright", "A0");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("less", "quote");
grub_keymap_add_by_string("greater", "doublequote");
grub_keymap_add_by_string("tilde", "Abracketright");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_DVORAK_USA(void) {
grub_keymap_reset();
grub_keymap_add_by_string("[", "minus");
grub_keymap_add_by_string("braceleft", "underscore");
grub_keymap_add_by_string("quote", "q");
grub_keymap_add_by_string("doublequote", "Q");
grub_keymap_add_by_string("comma", "w");
grub_keymap_add_by_string("less", "W");
grub_keymap_add_by_string("s", "semicolon");
grub_keymap_add_by_string("S", "colon");
grub_keymap_add_by_string("semicolon", "z");
grub_keymap_add_by_string("colon", "Z");
grub_keymap_add_by_string("w", "comma");
grub_keymap_add_by_string("W", "less");
grub_keymap_add_by_string("v", "period");
grub_keymap_add_by_string("z", "greater");
grub_keymap_add_by_string("z", "slash");
grub_keymap_add_by_string("equal", "bracketright");
grub_keymap_add_by_string("backslash", "backslash");
grub_keymap_add_by_string("underscore", "doublequote");
grub_keymap_add_by_string("quote", "q");
grub_keymap_add_by_string("doublequote", "Q");
grub_keymap_add_by_string("comma", "w");
grub_keymap_add_by_string("less", "W");
grub_keymap_add_by_string("period", "e");
grub_keymap_add_by_string("greater", "E");
grub_keymap_add_by_string("p", "r");
grub_keymap_add_by_string("P", "R");
grub_keymap_add_by_string("y", "t");
grub_keymap_add_by_string("Y", "T");
grub_keymap_add_by_string("f", "y");
grub_keymap_add_by_string("F", "Y");
grub_keymap_add_by_string("g", "u");
grub_keymap_add_by_string("G", "U");
grub_keymap_add_by_string("c", "c");
grub_keymap_add_by_string("C", "I");
grub_keymap_add_by_string("r", "o");
grub_keymap_add_by_string("R", "O");
grub_keymap_add_by_string("l", "p");
grub_keymap_add_by_string("L", "P");
grub_keymap_add_by_string("bracketright", "equal");
grub_keymap_add_by_string("braceright", "plus");
grub_keymap_add_by_string("a", "a");
grub_keymap_add_by_string("A", "A");
grub_keymap_add_by_string("o", "s");
grub_keymap_add_by_string("O", "S");
grub_keymap_add_by_string("e", "d");
grub_keymap_add_by_string("E", "D");
grub_keymap_add_by_string("u", "f");
grub_keymap_add_by_string("U", "F");
grub_keymap_add_by_string("i", "g");
grub_keymap_add_by_string("I", "G");
grub_keymap_add_by_string("d", "h");
grub_keymap_add_by_string("D", "H");
grub_keymap_add_by_string("h", "j");
grub_keymap_add_by_string("H", "J");
grub_keymap_add_by_string("t", "k");
grub_keymap_add_by_string("T", "K");
grub_keymap_add_by_string("n", "l");
grub_keymap_add_by_string("N", "L");
grub_keymap_add_by_string("s", "semicolon");
grub_keymap_add_by_string("S", "colon");
grub_keymap_add_by_string("minus", "quote");
grub_keymap_add_by_string("underscore", "doublequote");
grub_keymap_add_by_string("semicolon", "z");
grub_keymap_add_by_string("colon", "Z");
grub_keymap_add_by_string("q", "x");
grub_keymap_add_by_string("Q", "X");
grub_keymap_add_by_string("j", "c");
grub_keymap_add_by_string("J", "C");
grub_keymap_add_by_string("k", "v");
grub_keymap_add_by_string("K", "V");
grub_keymap_add_by_string("x", "b");
grub_keymap_add_by_string("X", "B");
grub_keymap_add_by_string("b", "n");
grub_keymap_add_by_string("B", "N");
grub_keymap_add_by_string("w", "comma");
grub_keymap_add_by_string("W", "less");
grub_keymap_add_by_string("v", "period");
grub_keymap_add_by_string("V", "greater");
grub_keymap_add_by_string("z", "slash");
grub_keymap_add_by_string("Z", "question");
grub_keymap_add_by_string("slash", "bracketleft");
grub_keymap_add_by_string("question", "braceleft");
grub_keymap_add_by_string("equal", "bracketright");
grub_keymap_add_by_string("plus", "braceright");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_FRENCH(void) {
grub_keymap_reset();
grub_keymap_add_by_string("less", "backquote");
grub_keymap_add_by_string("greater", "tilde");
grub_keymap_add_by_string("ampersand", "1");
grub_keymap_add_by_string("1", "exclam");
grub_keymap_add_by_string("tilde", "2");
grub_keymap_add_by_string("2", "at");
grub_keymap_add_by_string("doublequote", "3");
grub_keymap_add_by_string("3", "numbersign");
grub_keymap_add_by_string("quote", "4");
grub_keymap_add_by_string("4", "dollar");
grub_keymap_add_by_string("parenleft", "5");
grub_keymap_add_by_string("5", "percent");
grub_keymap_add_by_string("minus", "6");
grub_keymap_add_by_string("6", "caret");
grub_keymap_add_by_string("backquote", "7");
grub_keymap_add_by_string("7", "ampersand");
grub_keymap_add_by_string("underscore", "8");
grub_keymap_add_by_string("8", "asterisk");
grub_keymap_add_by_string("backslash", "9");
grub_keymap_add_by_string("9", "parenleft");
grub_keymap_add_by_string("at", "0");
grub_keymap_add_by_string("0", "parenright");
grub_keymap_add_by_string("parenright", "minus");
grub_keymap_add_by_string("numbersign", "underscore");
grub_keymap_add_by_string("a", "q");
grub_keymap_add_by_string("A", "Q");
grub_keymap_add_by_string("z", "w");
grub_keymap_add_by_string("Z", "W");
grub_keymap_add_by_string("caret", "bracketleft");
grub_keymap_add_by_string("dollar", "bracketright");
grub_keymap_add_by_string("q", "a");
grub_keymap_add_by_string("Q", "A");
grub_keymap_add_by_string("m", "semicolon");
grub_keymap_add_by_string("M", "colon");
grub_keymap_add_by_string("bracketleft", "quote");
grub_keymap_add_by_string("percent", "doublequote");
grub_keymap_add_by_string("asterisk", "backslash");
grub_keymap_add_by_string("bracketright", "bar");
grub_keymap_add_by_string("w", "z");
grub_keymap_add_by_string("W", "Z");
grub_keymap_add_by_string("comma", "m");
grub_keymap_add_by_string("question", "M");
grub_keymap_add_by_string("semicolon", "comma");
grub_keymap_add_by_string("period", "less");
grub_keymap_add_by_string("colon", "period");
grub_keymap_add_by_string("slash", "greater");
grub_keymap_add_by_string("exclam", "slash");
grub_keymap_add_by_string("bar", "question");
grub_keymap_add_by_string("tilde", "A2");
grub_keymap_add_by_string("numbersign", "A3");
grub_keymap_add_by_string("braceleft", "A4");
grub_keymap_add_by_string("bracketleft", "A5");
grub_keymap_add_by_string("bar", "A6");
grub_keymap_add_by_string("quote", "A7");
grub_keymap_add_by_string("backslash", "A8");
grub_keymap_add_by_string("caret", "A9");
grub_keymap_add_by_string("at", "A0");
grub_keymap_add_by_string("bracketright", "Aminus");
grub_keymap_add_by_string("braceright", "Aequal");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_GERMAN(void) {
grub_keymap_reset();
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("backslash", "minus");
grub_keymap_add_by_string("z", "y");
grub_keymap_add_by_string("Z", "Y");
grub_keymap_add_by_string("y", "z");
grub_keymap_add_by_string("Y", "Z");
grub_keymap_add_by_string("plus", "bracketright");
grub_keymap_add_by_string("asterisk", "braceright");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("caret", "backquote");
grub_keymap_add_by_string("quote", "equal");
grub_keymap_add_by_string("backquote", "plus");
grub_keymap_add_by_string("braceright", "doublequote");
grub_keymap_add_by_string("bar", "bracketleft");
grub_keymap_add_by_string("at", "braceleft");
grub_keymap_add_by_string("numbersign", "backslash");
grub_keymap_add_by_string("at", "Aq");
grub_keymap_add_by_string("less", "backquote");
grub_keymap_add_by_string("greater", "tilde");
grub_keymap_add_by_string("braceleft", "A7");
grub_keymap_add_by_string("bracketleft", "A8");
grub_keymap_add_by_string("bracketright", "A9");
grub_keymap_add_by_string("braceright", "A0");
grub_keymap_add_by_string("tilde", "Abracketright");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("quote", "bar");
grub_keymap_add_by_string("greater", "semicolon");
grub_keymap_add_by_string("less", "colon");
grub_keymap_add_by_string("bar", "quote");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_ITALIANO(void) {
grub_keymap_reset();
grub_keymap_add_by_string("backslash", "backquote");
grub_keymap_add_by_string("bar", "tilde");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("tilde", "numbersign");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("quote", "minus");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("caret", "plus");
grub_keymap_add_by_string("bracketleft", "bracketleft");
grub_keymap_add_by_string("bracketright", "braceleft");
grub_keymap_add_by_string("plus", "bracketright");
grub_keymap_add_by_string("asterisk", "braceright");
grub_keymap_add_by_string("at", "semicolon");
grub_keymap_add_by_string("braceleft", "colon");
grub_keymap_add_by_string("numbersign", "quote");
grub_keymap_add_by_string("braceright", "doublequote");
grub_keymap_add_by_string("less", "backslash");
grub_keymap_add_by_string("greater", "bar");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("bracketleft", "Abracketleft");
grub_keymap_add_by_string("bracketright", "Abracketright");
grub_keymap_add_by_string("at", "Asemicolon");
grub_keymap_add_by_string("numbersign", "Aquote");
grub_keymap_add_by_string("braceright", "Abraceright");
grub_keymap_add_by_string("braceleft", "Abraceleft");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_JAPAN_106(void) {
grub_keymap_reset();
grub_keymap_add_by_string("at", "bracketleft");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("quote", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("underscore", "parenright");
grub_keymap_add_by_string("equal", "underscore");
grub_keymap_add_by_string("plus", "colon");
grub_keymap_add_by_string("colon", "quote");
grub_keymap_add_by_string("asterisk", "doublequote");
grub_keymap_add_by_string("bracketleft", "bracketright");
grub_keymap_add_by_string("braceleft", "braceright");
grub_keymap_add_by_string("bracketright", "backslash");
grub_keymap_add_by_string("braceright", "bar");
grub_keymap_add_by_string("backslash", "backquote");
grub_keymap_add_by_string("tilde", "plus");
grub_keymap_add_by_string("caret", "equal");
grub_keymap_add_by_string("backquote", "braceleft");
grub_keymap_add_by_string("bar", "tilde");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_LATIN_USA(void) {
grub_keymap_reset();
grub_keymap_add_by_string("bar", "backquote");
grub_keymap_add_by_string("quote", "minus");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("backquote", "bracketleft");
grub_keymap_add_by_string("plus", "bracketright");
grub_keymap_add_by_string("braceleft", "quote");
grub_keymap_add_by_string("braceright", "backslash");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("asterisk", "braceright");
grub_keymap_add_by_string("bracketleft", "doublequote");
grub_keymap_add_by_string("bracketright", "bar");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("caret", "Aquote");
grub_keymap_add_by_string("doublequote", "braceleft");
grub_keymap_add_by_string("at", "Aq");
grub_keymap_add_by_string("backquote", "Abackslash");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("greater", "plus");
grub_keymap_add_by_string("less", "equal");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("backquote", "Abackslash");
grub_keymap_add_by_string("tilde", "Abracketright");
grub_keymap_add_by_string("caret", "Aquote");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_PORTU_BRAZIL(void) {
grub_keymap_reset();
grub_keymap_add_by_string("quote", "backquote");
grub_keymap_add_by_string("quote", "bracketleft");
grub_keymap_add_by_string("bracketleft", "bracketright");
grub_keymap_add_by_string("tilde", "quote");
grub_keymap_add_by_string("bracketright", "backslash");
grub_keymap_add_by_string("semicolon", "slash");
grub_keymap_add_by_string("bar", "colon");
grub_keymap_add_by_string("doublequote", "tilde");
grub_keymap_add_by_string("backquote", "braceleft");
grub_keymap_add_by_string("braceleft", "braceright");
grub_keymap_add_by_string("caret", "doublequote");
grub_keymap_add_by_string("braceright", "bar");
grub_keymap_add_by_string("colon", "question");
grub_keymap_add_by_string("backslash", "semicolon");
grub_keymap_add_by_string("bar", "Atilde");
grub_keymap_add_by_string("backslash", "Abackquote");
grub_keymap_add_by_string("slash", "Aq");
grub_keymap_add_by_string("question", "Aw");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_QWERTY_UK(void) {
grub_keymap_reset();
grub_keymap_add_by_string("at", "doublequote");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("tilde", "bar");
grub_keymap_add_by_string("numbersign", "backslash");
grub_keymap_add_by_string("backslash", "numbersign");
grub_keymap_add_by_string("bar", "tilde");
grub_keymap_add_by_string("backslash", "Atilde");
grub_keymap_add_by_string("backslash", "Abackquote");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_QWERTZ(void) {
grub_keymap_reset();
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "percent");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("backslash", "minus");
grub_keymap_add_by_string("z", "y");
grub_keymap_add_by_string("Z", "Y");
grub_keymap_add_by_string("y", "z");
grub_keymap_add_by_string("Y", "Z");
grub_keymap_add_by_string("plus", "bracketright");
grub_keymap_add_by_string("asterisk", "braceright");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("caret", "backquote");
grub_keymap_add_by_string("backquote", "equal");
grub_keymap_add_by_string("numbersign", "backslash");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("percent", "caret");
grub_keymap_add_by_string("less", "numbersign");
grub_keymap_add_by_string("greater", "bar");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_QWERTZ_HUN(void) {
grub_keymap_reset();
grub_keymap_add_by_string("y", "z");
grub_keymap_add_by_string("z", "y");
grub_keymap_add_by_string("Y", "Z");
grub_keymap_add_by_string("Z", "Y");
grub_keymap_add_by_string("0", "backquote");
grub_keymap_add_by_string("quote", "exclam");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("plus", "numbersign");
grub_keymap_add_by_string("exclam", "dollar");
grub_keymap_add_by_string("slash", "caret");
grub_keymap_add_by_string("equal", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("backslash", "Aq");
grub_keymap_add_by_string("bar", "Aw");
grub_keymap_add_by_string("bracketleft", "Af");
grub_keymap_add_by_string("bracketright", "Ag");
grub_keymap_add_by_string("greater", "Az");
grub_keymap_add_by_string("numbersign", "Ax");
grub_keymap_add_by_string("ampersand", "Ac");
grub_keymap_add_by_string("at", "Av");
grub_keymap_add_by_string("braceleft", "Ab");
grub_keymap_add_by_string("braceright", "An");
grub_keymap_add_by_string("less", "Am");
grub_keymap_add_by_string("dollar", "colon");
grub_keymap_add_by_string("question", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("at", "doublequote");
grub_keymap_add_by_string("tilde", "A1");
grub_keymap_add_by_string("caret", "A3");
grub_keymap_add_by_string("backquote", "A7");
grub_keymap_add_by_string("asterisk", "0");
grub_keymap_add_by_string("dollar", "Asemicolon");
grub_keymap_add_by_string("semicolon", "Acomma");
grub_keymap_add_by_string("greater", "Aperiod");
grub_keymap_add_by_string("asterisk", "Aslash");
grub_keymap_add_by_string("backquote", "A9");
grub_keymap_add_by_string("doublequote", "A0");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_QWERTZ_SLOV_CROAT(void) {
grub_keymap_reset();
grub_keymap_add_by_string("quote", "minus");
grub_keymap_add_by_string("plus", "equal");
grub_keymap_add_by_string("y", "z");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("doublequote", "tilde");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("asterisk", "plus");
grub_keymap_add_by_string("Y", "Z");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("tilde", "A1");
grub_keymap_add_by_string("caret", "A3");
grub_keymap_add_by_string("backquote", "A7");
grub_keymap_add_by_string("backslash", "Aq");
grub_keymap_add_by_string("bar", "Aw");
grub_keymap_add_by_string("bracketleft", "Af");
grub_keymap_add_by_string("bracketright", "Ag");
grub_keymap_add_by_string("at", "Av");
grub_keymap_add_by_string("braceleft", "Ab");
grub_keymap_add_by_string("braceright", "An");
grub_keymap_add_by_string("less", "Acomma");
grub_keymap_add_by_string("greater", "Aperiod");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_SPANISH(void) {
grub_keymap_reset();
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("caret", "braceleft");
grub_keymap_add_by_string("asterisk", "braceright");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("quote", "minus");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("greater", "bar");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("backslash", "backquote");
grub_keymap_add_by_string("less", "backslash");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("backquote", "bracketleft");
grub_keymap_add_by_string("plus", "bracketright");
grub_keymap_add_by_string("plus", "colon");
grub_keymap_add_by_string("at", "semicolon");
grub_keymap_add_by_string("bar", "A1");
grub_keymap_add_by_string("at", "A2");
grub_keymap_add_by_string("numbersign", "A3");
grub_keymap_add_by_string("tilde", "A4");
grub_keymap_add_by_string("bracketleft", "Abracketleft");
grub_keymap_add_by_string("bracketright", "Abracketright");
grub_keymap_add_by_string("braceleft", "Aquote");
grub_keymap_add_by_string("braceright", "Abackslash");
grub_keymap_add_by_string("greater", "bar");
grub_keymap_add_by_string("less", "backslash");
grub_keymap_add_by_string("backslash", "Abackquote");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_SWEDISH(void) {
grub_keymap_reset();
grub_keymap_add_by_string("plus", "minus");
grub_keymap_add_by_string("quote", "equal");
grub_keymap_add_by_string("doublequote", "bracketright");
grub_keymap_add_by_string("quote", "backslash");
grub_keymap_add_by_string("minus", "slash");
grub_keymap_add_by_string("doublequote", "at");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("caret", "braceright");
grub_keymap_add_by_string("asterisk", "bar");
grub_keymap_add_by_string("backquote", "plus");
grub_keymap_add_by_string("semicolon", "less");
grub_keymap_add_by_string("colon", "greater");
grub_keymap_add_by_string("underscore", "question");
grub_keymap_add_by_string("bar", "Atilde");
grub_keymap_add_by_string("backslash", "Abackquote");
grub_keymap_add_by_string("greater", "tilde");
grub_keymap_add_by_string("at", "A2");
grub_keymap_add_by_string("dollar", "A4");
grub_keymap_add_by_string("braceleft", "A7");
grub_keymap_add_by_string("bracketleft", "A8");
grub_keymap_add_by_string("bracketright", "A9");
grub_keymap_add_by_string("braceright", "A0");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("less", "quote");
grub_keymap_add_by_string("greater", "doublequote");
grub_keymap_add_by_string("tilde", "Abracketright");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_TURKISH_Q(void) {
grub_keymap_reset();
grub_keymap_add_by_string("doublequote", "backquote");
grub_keymap_add_by_string("asterisk", "minus");
grub_keymap_add_by_string("minus", "equal");
grub_keymap_add_by_string("comma", "backslash");
grub_keymap_add_by_string("period", "slash");
grub_keymap_add_by_string("quote", "at");
grub_keymap_add_by_string("caret", "numbersign");
grub_keymap_add_by_string("plus", "dollar");
grub_keymap_add_by_string("ampersand", "caret");
grub_keymap_add_by_string("slash", "ampersand");
grub_keymap_add_by_string("parenleft", "asterisk");
grub_keymap_add_by_string("parenright", "parenleft");
grub_keymap_add_by_string("equal", "parenright");
grub_keymap_add_by_string("question", "underscore");
grub_keymap_add_by_string("underscore", "plus");
grub_keymap_add_by_string("semicolon", "bar");
grub_keymap_add_by_string("colon", "question");
grub_keymap_add_by_string("less", "Abackquote");
grub_keymap_add_by_string("greater", "A1");
grub_keymap_add_by_string("numbersign", "A3");
grub_keymap_add_by_string("dollar", "A4");
grub_keymap_add_by_string("braceleft", "A7");
grub_keymap_add_by_string("bracketleft", "A8");
grub_keymap_add_by_string("bracketright", "A9");
grub_keymap_add_by_string("braceright", "A0");
grub_keymap_add_by_string("backslash", "Aminus");
grub_keymap_add_by_string("bar", "Aequal");
grub_keymap_add_by_string("at", "Aq");
grub_keymap_add_by_string("doublequote", "Abracketleft");
grub_keymap_add_by_string("tilde", "Abracketright");
grub_keymap_enable();
}
static void ventoy_keyboard_layout_VIETNAMESE(void) {
grub_keymap_reset();
grub_keymap_add_by_string("exclam", "A1");
grub_keymap_add_by_string("at", "A2");
grub_keymap_add_by_string("numbersign", "A3");
grub_keymap_add_by_string("dollar", "A4");
grub_keymap_add_by_string("percent", "A5");
grub_keymap_add_by_string("caret", "A6");
grub_keymap_add_by_string("ampersand", "A7");
grub_keymap_add_by_string("asterisk", "A8");
grub_keymap_add_by_string("parenleft", "A9");
grub_keymap_add_by_string("parenright", "A0");
grub_keymap_add_by_string("plus", "Aplus");
grub_keymap_add_by_string("equal", "Aequal");
grub_keymap_add_by_string("braceleft", "Abraceleft");
grub_keymap_add_by_string("braceright", "Abraceright");
grub_keymap_add_by_string("colon", "Acolon");
grub_keymap_add_by_string("semicolon", "Asemicolon");
grub_keymap_add_by_string("quote", "Aquote");
grub_keymap_add_by_string("backslash", "Abackslash");
grub_keymap_add_by_string("less", "Aless");
grub_keymap_add_by_string("greater", "Agreater");
grub_keymap_add_by_string("comma", "Acomma");
grub_keymap_add_by_string("period", "Aperiod");
grub_keymap_add_by_string("question", "Aquestion");
grub_keymap_add_by_string("slash", "Aslash");
grub_keymap_add_by_string("tilde", "Atilde");
grub_keymap_add_by_string("backquote", "Abackquote");
grub_keymap_add_by_string("bracketright", "Abracketright");
grub_keymap_add_by_string("bracketleft", "Abracketleft");
grub_keymap_add_by_string("bar", "Abar");
grub_keymap_add_by_string("doublequote", "Adoublequote");
grub_keymap_add_by_string("colon", "Acolon");
grub_keymap_add_by_string("minus", "Aminus");
grub_keymap_add_by_string("underscore", "Aunderscore");
grub_keymap_enable();
}
void ventoy_set_keyboard_layout(const char *layout);
void ventoy_set_keyboard_layout(const char *layout) {
ventoy_keyboard_set_layout(QWERTY_USA);
ventoy_keyboard_set_layout(AZERTY);
ventoy_keyboard_set_layout(CZECH_QWERTY);
ventoy_keyboard_set_layout(CZECH_QWERTZ);
ventoy_keyboard_set_layout(DANISH);
ventoy_keyboard_set_layout(DVORAK_USA);
ventoy_keyboard_set_layout(FRENCH);
ventoy_keyboard_set_layout(GERMAN);
ventoy_keyboard_set_layout(ITALIANO);
ventoy_keyboard_set_layout(JAPAN_106);
ventoy_keyboard_set_layout(LATIN_USA);
ventoy_keyboard_set_layout(PORTU_BRAZIL);
ventoy_keyboard_set_layout(QWERTY_UK);
ventoy_keyboard_set_layout(QWERTZ);
ventoy_keyboard_set_layout(QWERTZ_HUN);
ventoy_keyboard_set_layout(QWERTZ_SLOV_CROAT);
ventoy_keyboard_set_layout(SPANISH);
ventoy_keyboard_set_layout(SWEDISH);
ventoy_keyboard_set_layout(TURKISH_Q);
ventoy_keyboard_set_layout(VIETNAMESE);
}

View File

@@ -0,0 +1,463 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/serial.h>
#include <grub/term.h>
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/terminfo.h>
#if !defined (GRUB_MACHINE_EMU) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
#include <grub/cpu/io.h>
#endif
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/list.h>
#ifdef GRUB_MACHINE_MIPS_LOONGSON
#include <grub/machine/kernel.h>
#endif
#ifdef GRUB_MACHINE_IEEE1275
#include <grub/ieee1275/console.h>
#endif
GRUB_MOD_LICENSE ("GPLv3+");
#define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports))
enum
{
OPTION_UNIT,
OPTION_PORT,
OPTION_SPEED,
OPTION_WORD,
OPTION_PARITY,
OPTION_STOP,
OPTION_BASE_CLOCK,
OPTION_RTSCTS
};
/* Argument options. */
static const struct grub_arg_option options[] =
{
{"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT},
{"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING},
{"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT},
{"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT},
{"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING},
{"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT},
{"base-clock", 'b', 0, N_("Set the base frequency."), 0, ARG_TYPE_STRING},
{"rtscts", 'f', 0, N_("Enable/disable RTS/CTS."), "on|off", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static struct grub_serial_port *grub_serial_ports;
struct grub_serial_output_state
{
struct grub_terminfo_output_state tinfo;
struct grub_serial_port *port;
};
struct grub_serial_input_state
{
struct grub_terminfo_input_state tinfo;
struct grub_serial_port *port;
};
static void
serial_put (grub_term_output_t term, const int c)
{
struct grub_serial_output_state *data = term->data;
data->port->driver->put (data->port, c);
}
static int
serial_fetch (grub_term_input_t term)
{
struct grub_serial_input_state *data = term->data;
return data->port->driver->fetch (data->port);
}
static const struct grub_serial_input_state grub_serial_terminfo_input_template =
{
.tinfo =
{
.readkey = serial_fetch
}
};
static const struct grub_serial_output_state grub_serial_terminfo_output_template =
{
.tinfo =
{
.put = serial_put,
.size = { 80, 24 }
}
};
static struct grub_serial_input_state grub_serial_terminfo_input;
static struct grub_serial_output_state grub_serial_terminfo_output;
static int registered = 0;
static struct grub_term_input grub_serial_term_input =
{
.name = "serial",
.init = grub_terminfo_input_init,
.getkey = grub_terminfo_getkey,
.data = &grub_serial_terminfo_input
};
static struct grub_term_output grub_serial_term_output =
{
.name = "serial",
.init = grub_terminfo_output_init,
.putchar = grub_terminfo_putchar,
.getwh = grub_terminfo_getwh,
.getxy = grub_terminfo_getxy,
.gotoxy = grub_terminfo_gotoxy,
.cls = grub_terminfo_cls,
.setcolorstate = grub_terminfo_setcolorstate,
.setcursor = grub_terminfo_setcursor,
.flags = GRUB_TERM_CODE_TYPE_ASCII,
.data = &grub_serial_terminfo_output,
.progress_update_divisor = GRUB_PROGRESS_SLOW
};
struct grub_serial_port *
grub_serial_find (const char *name)
{
struct grub_serial_port *port;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
#if ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)) && !defined(GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC)
if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) == 0
&& grub_isxdigit (name [sizeof ("port") - 1]))
{
name = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1],
0, 16));
if (!name)
return NULL;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
}
#endif
#ifdef GRUB_MACHINE_IEEE1275
if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
{
name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
if (!name)
return NULL;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
}
#endif
return port;
}
static grub_err_t
grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
char pname[40];
const char *name = NULL;
struct grub_serial_port *port;
struct grub_serial_config config;
grub_err_t err;
if (state[OPTION_UNIT].set)
{
grub_snprintf (pname, sizeof (pname), "com%ld",
grub_strtoul (state[0].arg, 0, 0));
name = pname;
}
if (state[OPTION_PORT].set)
{
grub_snprintf (pname, sizeof (pname), "port%lx",
grub_strtoul (state[1].arg, 0, 0));
name = pname;
}
if (argc >= 1)
name = args[0];
if (!name)
name = "com0";
port = grub_serial_find (name);
if (!port)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("serial port `%s' isn't found"),
name);
config = port->config;
if (state[OPTION_SPEED].set) {
config.speed = grub_strtoul (state[OPTION_SPEED].arg, 0, 0);
if (config.speed == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port parity"));
}
if (state[OPTION_WORD].set)
config.word_len = grub_strtoul (state[OPTION_WORD].arg, 0, 0);
if (state[OPTION_PARITY].set)
{
if (! grub_strcmp (state[OPTION_PARITY].arg, "no"))
config.parity = GRUB_SERIAL_PARITY_NONE;
else if (! grub_strcmp (state[OPTION_PARITY].arg, "odd"))
config.parity = GRUB_SERIAL_PARITY_ODD;
else if (! grub_strcmp (state[OPTION_PARITY].arg, "even"))
config.parity = GRUB_SERIAL_PARITY_EVEN;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port parity"));
}
if (state[OPTION_RTSCTS].set)
{
if (grub_strcmp (state[OPTION_RTSCTS].arg, "on") == 0)
config.rtscts = 1;
else if (grub_strcmp (state[OPTION_RTSCTS].arg, "off") == 0)
config.rtscts = 0;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port flow control"));
}
if (state[OPTION_STOP].set)
{
if (! grub_strcmp (state[OPTION_STOP].arg, "1"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_1;
else if (! grub_strcmp (state[OPTION_STOP].arg, "2"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_2;
else if (! grub_strcmp (state[OPTION_STOP].arg, "1.5"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_1_5;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port stop bits number"));
}
if (state[OPTION_BASE_CLOCK].set)
{
char *ptr;
config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0);
if (grub_errno)
return grub_errno;
if (ptr && *ptr == 'M')
config.base_clock *= 1000000;
if (ptr && (*ptr == 'k' || *ptr == 'K'))
config.base_clock *= 1000;
}
if (config.speed == 0)
config.speed = 9600;
/* Initialize with new settings. */
err = port->driver->configure (port, &config);
if (err)
return err;
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
/* Compatibility kludge. */
if (port->driver == &grub_ns8250_driver)
{
if (!registered)
{
grub_terminfo_output_register (&grub_serial_term_output, "vt100");
grub_term_register_input ("serial", &grub_serial_term_input);
grub_term_register_output ("serial", &grub_serial_term_output);
}
grub_serial_terminfo_output.port = port;
grub_serial_terminfo_input.port = port;
registered = 1;
}
#endif
return GRUB_ERR_NONE;
}
#ifdef GRUB_MACHINE_MIPS_LOONGSON
const char loongson_defserial[][6] =
{
[GRUB_ARCH_MACHINE_YEELOONG] = "com0",
[GRUB_ARCH_MACHINE_FULOONG2F] = "com2",
[GRUB_ARCH_MACHINE_FULOONG2E] = "com1"
};
#endif
grub_err_t
grub_serial_register (struct grub_serial_port *port)
{
struct grub_term_input *in;
struct grub_term_output *out;
struct grub_serial_input_state *indata;
struct grub_serial_output_state *outdata;
in = grub_malloc (sizeof (*in));
if (!in)
return grub_errno;
indata = grub_malloc (sizeof (*indata));
if (!indata)
{
grub_free (in);
return grub_errno;
}
grub_memcpy (in, &grub_serial_term_input, sizeof (*in));
in->data = indata;
in->name = grub_xasprintf ("serial_%s", port->name);
grub_memcpy (indata, &grub_serial_terminfo_input, sizeof (*indata));
if (!in->name)
{
grub_free (in);
grub_free (indata);
return grub_errno;
}
out = grub_zalloc (sizeof (*out));
if (!out)
{
grub_free (indata);
grub_free ((char *) in->name);
grub_free (in);
return grub_errno;
}
outdata = grub_malloc (sizeof (*outdata));
if (!outdata)
{
grub_free (indata);
grub_free ((char *) in->name);
grub_free (out);
grub_free (in);
return grub_errno;
}
grub_memcpy (out, &grub_serial_term_output, sizeof (*out));
out->data = outdata;
out->name = in->name;
grub_memcpy (outdata, &grub_serial_terminfo_output, sizeof (*outdata));
grub_list_push (GRUB_AS_LIST_P (&grub_serial_ports), GRUB_AS_LIST (port));
((struct grub_serial_input_state *) in->data)->port = port;
((struct grub_serial_output_state *) out->data)->port = port;
port->term_in = in;
port->term_out = out;
grub_terminfo_output_register (out, "vt100");
#ifdef GRUB_MACHINE_MIPS_LOONGSON
if (grub_strcmp (port->name, loongson_defserial[grub_arch_machine]) == 0)
{
grub_term_register_input_active ("serial_*", in);
grub_term_register_output_active ("serial_*", out);
}
else
{
grub_term_register_input_inactive ("serial_*", in);
grub_term_register_output_inactive ("serial_*", out);
}
#else
grub_term_register_input ("serial_*", in);
grub_term_register_output ("serial_*", out);
#endif
return GRUB_ERR_NONE;
}
void
grub_serial_unregister (struct grub_serial_port *port)
{
if (port->driver->fini)
port->driver->fini (port);
if (port->term_in)
grub_term_unregister_input (port->term_in);
if (port->term_out)
grub_term_unregister_output (port->term_out);
grub_list_remove (GRUB_AS_LIST (port));
}
void
grub_serial_unregister_driver (struct grub_serial_driver *driver)
{
struct grub_serial_port *port, *next;
for (port = grub_serial_ports; port; port = next)
{
next = port->next;
if (port->driver == driver)
grub_serial_unregister (port);
}
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(serial)
{
cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0,
N_("[OPTIONS...]"),
N_("Configure serial port."), options);
grub_memcpy (&grub_serial_terminfo_output,
&grub_serial_terminfo_output_template,
sizeof (grub_serial_terminfo_output));
grub_memcpy (&grub_serial_terminfo_input,
&grub_serial_terminfo_input_template,
sizeof (grub_serial_terminfo_input));
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
grub_ns8250_init ();
#endif
#ifdef GRUB_MACHINE_IEEE1275
grub_ofserial_init ();
#endif
#ifdef GRUB_MACHINE_EFI
grub_efiserial_init ();
#endif
#ifdef GRUB_MACHINE_ARC
grub_arcserial_init ();
#endif
}
GRUB_MOD_FINI(serial)
{
while (grub_serial_ports)
grub_serial_unregister (grub_serial_ports);
if (registered)
{
grub_term_unregister_input (&grub_serial_term_input);
grub_term_unregister_output (&grub_serial_term_output);
}
grub_unregister_extcmd (cmd);
}

View File

@@ -0,0 +1,388 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2020 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/env.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/term.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define MAX_KEYMAP 255
struct keymap
{
int cnt;
int in[MAX_KEYMAP];
int out[MAX_KEYMAP];
};
static struct keymap setkey_keymap;
struct keysym
{
const char *name; /* the name in unshifted state */
int code; /* scan code */
};
/* The table for key symbols. (from GRUB4DOS) */
static struct keysym keysym_table[] =
{
{"escape", GRUB_TERM_ESC}, // ESC
{"exclam", 0x21}, // '!'
{"at", 0x40}, // '@'
{"numbersign", 0x23}, // '#'
{"dollar", 0x24}, // '$'
{"percent", 0x25}, // '%'
{"caret", 0x5E}, // '^'
{"ampersand", 0x26}, // '&'
{"asterisk", 0x2A}, // '*'
{"parenleft", 0x28}, // '('
{"parenright", 0x29}, // ')'
{"minus", 0x2D}, // '-'
{"underscore", 0x5F}, // '_'
{"equal", 0x3D}, // '='
{"plus", 0x2B}, // '+'
{"backspace", GRUB_TERM_BACKSPACE}, // BS
{"ctrlbackspace", GRUB_TERM_CTRL | GRUB_TERM_BACKSPACE}, // (DEL)
{"tab", GRUB_TERM_TAB}, // Tab
{"bracketleft", 0x5B}, // '['
{"braceleft", 0x7B}, // '{'
{"bracketright", 0x5D}, // ']'
{"braceright", 0x7D}, // '}'
{"enter", 0x0D}, // Enter
{"semicolon", 0x3B}, // ';'
{"colon", 0x3A}, // ':'
{"quote", 0x27}, // '\''
{"doublequote", 0x22}, // '"'
{"backquote", 0x60}, // '`'
{"tilde", 0x7E}, // '~'
{"backslash", 0x5C}, // '\\'
{"bar", 0x7C}, // '|'
{"comma", 0x2C}, // ','
{"less", 0x3C}, // '<'
{"period", 0x2E}, // '.'
{"greater", 0x3E}, // '>'
{"slash", 0x2F}, // '/'
{"question", 0x3F}, // '?'
{"space", 0x20}, // Space
{"F1", GRUB_TERM_KEY_F1},
{"F2", GRUB_TERM_KEY_F2},
{"F3", GRUB_TERM_KEY_F3},
{"F4", GRUB_TERM_KEY_F4},
{"F5", GRUB_TERM_KEY_F5},
{"F6", GRUB_TERM_KEY_F6},
{"F7", GRUB_TERM_KEY_F7},
{"F8", GRUB_TERM_KEY_F8},
{"F9", GRUB_TERM_KEY_F9},
{"F10", GRUB_TERM_KEY_F10},
{"F11", GRUB_TERM_KEY_F11},
{"F12", GRUB_TERM_KEY_F12},
{"home", GRUB_TERM_KEY_HOME},
{"uparrow", GRUB_TERM_KEY_UP},
{"pageup", GRUB_TERM_KEY_NPAGE}, // PgUp
{"leftarrow", GRUB_TERM_KEY_LEFT},
{"center", GRUB_TERM_KEY_CENTER}, // keypad center key
{"rightarrow", GRUB_TERM_KEY_RIGHT},
{"end", GRUB_TERM_KEY_END},
{"downarrow", GRUB_TERM_KEY_DOWN},
{"pagedown", GRUB_TERM_KEY_PPAGE}, // PgDn
{"insert", GRUB_TERM_KEY_INSERT}, // Insert
{"delete", GRUB_TERM_KEY_DC}, // Delete
{"shiftF1", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F1},
{"shiftF2", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F2},
{"shiftF3", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F3},
{"shiftF4", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F4},
{"shiftF5", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F5},
{"shiftF6", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F6},
{"shiftF7", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F7},
{"shiftF8", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F8},
{"shiftF9", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F9},
{"shiftF10", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F10},
{"shiftF11", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F11},
{"shiftF12", GRUB_TERM_SHIFT | GRUB_TERM_KEY_F12},
{"ctrlF1", GRUB_TERM_CTRL | GRUB_TERM_KEY_F1},
{"ctrlF2", GRUB_TERM_CTRL | GRUB_TERM_KEY_F2},
{"ctrlF3", GRUB_TERM_CTRL | GRUB_TERM_KEY_F3},
{"ctrlF4", GRUB_TERM_CTRL | GRUB_TERM_KEY_F4},
{"ctrlF5", GRUB_TERM_CTRL | GRUB_TERM_KEY_F5},
{"ctrlF6", GRUB_TERM_CTRL | GRUB_TERM_KEY_F6},
{"ctrlF7", GRUB_TERM_CTRL | GRUB_TERM_KEY_F7},
{"ctrlF8", GRUB_TERM_CTRL | GRUB_TERM_KEY_F8},
{"ctrlF9", GRUB_TERM_CTRL | GRUB_TERM_KEY_F9},
{"ctrlF10", GRUB_TERM_CTRL | GRUB_TERM_KEY_F10},
{"ctrlF11", GRUB_TERM_CTRL | GRUB_TERM_KEY_F11},
{"ctrlF12", GRUB_TERM_CTRL | GRUB_TERM_KEY_F12},
// A=Alt or AltGr. Provided by steve.
{"Aq", GRUB_TERM_ALT | 0x71},
{"Aw", GRUB_TERM_ALT | 0x77},
{"Ae", GRUB_TERM_ALT | 0x65},
{"Ar", GRUB_TERM_ALT | 0x72},
{"At", GRUB_TERM_ALT | 0x74},
{"Ay", GRUB_TERM_ALT | 0x79},
{"Au", GRUB_TERM_ALT | 0x75},
{"Ai", GRUB_TERM_ALT | 0x69},
{"Ao", GRUB_TERM_ALT | 0x6F},
{"Ap", GRUB_TERM_ALT | 0x70},
{"Aa", GRUB_TERM_ALT | 0x61},
{"As", GRUB_TERM_ALT | 0x73},
{"Ad", GRUB_TERM_ALT | 0x64},
{"Af", GRUB_TERM_ALT | 0x66},
{"Ag", GRUB_TERM_ALT | 0x67},
{"Ah", GRUB_TERM_ALT | 0x68},
{"Aj", GRUB_TERM_ALT | 0x6A},
{"Ak", GRUB_TERM_ALT | 0x6B},
{"Al", GRUB_TERM_ALT | 0x6C},
{"Az", GRUB_TERM_ALT | 0x7A},
{"Ax", GRUB_TERM_ALT | 0x78},
{"Ac", GRUB_TERM_ALT | 0x63},
{"Av", GRUB_TERM_ALT | 0x76},
{"Ab", GRUB_TERM_ALT | 0x62},
{"An", GRUB_TERM_ALT | 0x6E},
{"Am", GRUB_TERM_ALT | 0x6D},
{"A1", GRUB_TERM_ALT | 0x31},
{"A2", GRUB_TERM_ALT | 0x32},
{"A3", GRUB_TERM_ALT | 0x33},
{"A4", GRUB_TERM_ALT | 0x34},
{"A5", GRUB_TERM_ALT | 0x35},
{"A6", GRUB_TERM_ALT | 0x36},
{"A7", GRUB_TERM_ALT | 0x37},
{"A8", GRUB_TERM_ALT | 0x38},
{"A9", GRUB_TERM_ALT | 0x39},
{"A0", GRUB_TERM_ALT | 0x30},
//{"oem102", 0x5c},
//{"shiftoem102", 0x7c},
{"Aminus", GRUB_TERM_ALT | 0x2D},
{"Aequal", GRUB_TERM_ALT | 0x3D},
{"Abracketleft", GRUB_TERM_ALT | 0x5B},
{"Abracketright", GRUB_TERM_ALT | 0x5D},
{"Asemicolon", GRUB_TERM_ALT | 0x3B},
{"Aquote", GRUB_TERM_ALT | 0x27},
{"Abackquote", GRUB_TERM_ALT | 0x60},
{"Abackslash", GRUB_TERM_ALT | 0x5C},
{"Acomma", GRUB_TERM_ALT | 0x2C},
{"Aperiod", GRUB_TERM_ALT | 0x2E},
{"Aslash", GRUB_TERM_ALT | 0x2F},
{"Acolon", GRUB_TERM_ALT | 0x3A},
{"Aplus", GRUB_TERM_ALT | 0x2B},
{"Aless", GRUB_TERM_ALT | 0x3C},
{"Aunderscore", GRUB_TERM_ALT | 0x5F},
{"Agreater", GRUB_TERM_ALT | 0x3E},
{"Aquestion", GRUB_TERM_ALT | 0x3F},
{"Atilde", GRUB_TERM_ALT | 0x7E},
{"Abraceleft", GRUB_TERM_ALT | 0x7B},
{"Abar", GRUB_TERM_ALT | 0x7C},
{"Abraceright", GRUB_TERM_ALT | 0x7D},
{"Adoublequote", GRUB_TERM_ALT | 0x22},
};
static int grub_keymap_getkey (int key)
{
int i;
if (key == GRUB_TERM_NO_KEY)
return key;
if (setkey_keymap.cnt > MAX_KEYMAP)
setkey_keymap.cnt = MAX_KEYMAP;
for (i = 0; i < setkey_keymap.cnt; i++)
{
if (key == setkey_keymap.in[i])
{
key = setkey_keymap.out[i];
break;
}
}
return key;
}
static void
grub_keymap_reset (void)
{
grub_memset (&setkey_keymap, 0, sizeof (struct keymap));
}
static grub_err_t
grub_keymap_add (int in, int out)
{
if (in == GRUB_TERM_NO_KEY || out == GRUB_TERM_NO_KEY)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid key: %d -> %d", in, out);
if (setkey_keymap.cnt >= MAX_KEYMAP)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"keymap FULL %d", setkey_keymap.cnt);
setkey_keymap.in[setkey_keymap.cnt] = in;
setkey_keymap.out[setkey_keymap.cnt] = out;
setkey_keymap.cnt++;
return GRUB_ERR_NONE;
}
static void
grub_keymap_enable (void)
{
grub_key_remap = grub_keymap_getkey;
}
static void
grub_keymap_disable (void)
{
grub_key_remap = NULL;
}
static void
grub_keymap_status (void)
{
int i;
if (setkey_keymap.cnt > MAX_KEYMAP)
setkey_keymap.cnt = MAX_KEYMAP;
for (i = 0; i < setkey_keymap.cnt; i++)
{
grub_printf ("0x%x -> 0x%x\n", setkey_keymap.in[i], setkey_keymap.out[i]);
}
}
static const struct grub_arg_option options[] =
{
{"reset", 'r', 0, N_("Reset keymap."), 0, 0},
{"enable", 'e', 0, N_("Enable keymap."), 0, 0},
{"disable", 'd', 0, N_("Disable keymap."), 0, 0},
{"status", 's', 0, N_("Display keymap."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
enum options
{
SETKEY_RESET,
SETKEY_ENABLE,
SETKEY_DISABLE,
SETKEY_STATUS,
};
static int
ishex (const char *str)
{
if (grub_strlen (str) < 3 || str[0] != '0')
return 0;
if (str[1] != 'x' && str[1] != 'X')
return 0;
return 1;
}
static int
parse_key (const char *str)
{
int i;
if (ishex (str))
return grub_strtol (str, NULL, 16);
if (grub_strlen (str) == 1)
return (int) str[0];
for (i = 0; i < (int) (sizeof (keysym_table) / sizeof (keysym_table[0])); i++)
{
if (grub_strcmp (str, keysym_table[i].name) == 0)
return keysym_table[i].code;
}
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid key %s", str);
return 0;
}
static grub_err_t
grub_cmd_setkey (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
int in, out;
if (state[SETKEY_ENABLE].set)
{
grub_keymap_enable ();
goto out;
}
if (state[SETKEY_DISABLE].set)
{
grub_keymap_disable ();
goto out;
}
if (state[SETKEY_RESET].set)
{
grub_keymap_reset ();
goto out;
}
if (state[SETKEY_STATUS].set)
{
grub_keymap_status ();
goto out;
}
if (argc != 2)
{
grub_printf
("Key names: 0-9, A-Z, a-z or escape, exclam, at, numbersign, dollar,"
"percent, caret, ampersand, asterisk, parenleft, parenright, minus,"
"underscore, equal, plus, backspace, tab, bracketleft, braceleft,"
"bracketright, braceright, enter, semicolon, colon, quote, doublequote,"
"backquote, tilde, backslash, bar, comma, less, period, greater,"
"slash, question, alt, space, delete, [ctrl|shift]F1-12."
"For Alt+ prefix with A, e.g. \'setkey at Aequal\'.");
goto out;
}
in = parse_key (args[1]);
out = parse_key (args[0]);
if (!in || !out)
goto out;
grub_keymap_add (in, out);
out:
return grub_errno;
}
static void grub_keymap_add_by_string(const char *src, const char *dst)
{
int in = 0;
int out = 0;
in = parse_key(dst);
out = parse_key(src);
if (in && out)
{
grub_keymap_add (in, out);
}
}
#include "keyboard_layout.c"
static grub_err_t grub_cmd_set_keylayout (grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
ventoy_set_keyboard_layout(args[0]);
return 0;
}
static grub_extcmd_t cmd, setcmd;
GRUB_MOD_INIT(setkey)
{
cmd = grub_register_extcmd ("setkey", grub_cmd_setkey, 0, N_("NEW_KEY USA_KEY"),
N_("Map default USA_KEY to NEW_KEY."), options);
setcmd = grub_register_extcmd ("set_keyboard_layout", grub_cmd_set_keylayout, 0, N_("layout"),
N_("Set keyboard layout."), NULL);
}
GRUB_MOD_FINI(setkey)
{
grub_unregister_extcmd (cmd);
}

View File

@@ -462,6 +462,8 @@ static int lzx_uncompressed ( struct lzx *lzx ) {
if ( len % 2 )
lzx->input.offset++;
lzx->output.offset += len;
return 0;
}
@@ -614,7 +616,7 @@ ssize_t lzx_decompress ( const void *data, size_t len, void *buf ) {
/* Sanity check */
if ( len % 2 ) {
DBG ( "LZX cannot handle odd-length input data\n" );
return -1;
//return -1;
}
/* Initialise global state, if required */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
#define MINIZ_HEADER_FILE_ONLY
#include "miniz.c"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,8 @@
#define VTOY_SIZE_1GB 1073741824
#define VTOY_SIZE_1MB (1024 * 1024)
#define VTOY_SIZE_2MB (2 * 1024 * 1024)
#define VTOY_SIZE_4MB (4 * 1024 * 1024)
#define VTOY_SIZE_512KB (512 * 1024)
#define VTOY_SIZE_1KB 1024
@@ -52,12 +54,44 @@
#define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
#ifdef GRUB_MACHINE_EFI
#define VTOY_DUAL_MODE_SUFFIX "uefi"
#define VTOY_PLAT_I386_UEFI 0x49413332
#define VTOY_PLAT_ARM64_UEFI 0x41413634
#define VTOY_PLAT_X86_64_UEFI 0x55454649
#define VTOY_PLAT_X86_LEGACY 0x42494f53
#define VTOY_PLAT_MIPS_UEFI 0x4D495053
#define VTOY_COMM_CPIO "ventoy.cpio"
#if defined(__arm__) || defined(__aarch64__)
#define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
#elif defined(__mips__)
#define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
#else
#define VTOY_DUAL_MODE_SUFFIX "legacy"
#define VTOY_ARCH_CPIO "ventoy_x86.cpio"
#endif
#define VTOY_PWD_CORRUPTED(err) \
{\
grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
grub_refresh(); \
grub_sleep(5); \
grub_exit(); \
return (err);\
}
typedef enum VTOY_FILE_FLT
{
VTOY_FILE_FLT_ISO = 0, /* .iso */
VTOY_FILE_FLT_WIM, /* .wim */
VTOY_FILE_FLT_EFI, /* .efi */
VTOY_FILE_FLT_IMG, /* .img */
VTOY_FILE_FLT_VHD, /* .vhd(x) */
VTOY_FILE_FLT_VTOY, /* .vtoy */
VTOY_FILE_FLT_BUTT
}VTOY_FILE_FLT;
#define FILE_FLT(type) (0 == g_vtoy_file_flt[VTOY_FILE_FLT_##type])
typedef struct ventoy_initrd_ctx
{
const char *path_prefix;
@@ -108,6 +142,7 @@ typedef struct cpio_newc_header
typedef int (*grub_char_check_func)(int c);
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
#define OFFSET_OF(TYPE, MEMBER) ((grub_size_t) &((TYPE *)0)->MEMBER)
#pragma pack(1)
typedef struct ventoy_patch_vhd
@@ -155,16 +190,20 @@ typedef struct ventoy_iso9660_vd
grub_uint8_t res;
char sys[32];
char vol[32];
grub_uint8_t res2[8];
grub_uint32_t space;
}ventoy_iso9660_vd;
#pragma pack()
#define img_type_iso 0
#define img_type_wim 1
#define img_type_efi 2
#define img_type_img 3
#define img_type_vhd 4
#define img_type_vtoy 5
#define img_type_start 0
#define img_type_iso 0
#define img_type_wim 1
#define img_type_efi 2
#define img_type_img 3
#define img_type_vhd 4
#define img_type_vtoy 5
#define img_type_max 6
typedef struct img_info
{
@@ -195,6 +234,7 @@ typedef struct img_iterator_node
img_info **tail;
char dir[400];
int dirlen;
int level;
int isocnt;
int done;
int select;
@@ -245,10 +285,12 @@ extern ventoy_guid g_ventoy_guid;
extern ventoy_img_chunk_list g_img_chunk_list;
extern ventoy_img_chunk_list g_wimiso_chunk_list;
extern char *g_wimiso_path;
extern char g_arch_mode_suffix[64];
extern const char *g_menu_prefix[img_type_max];
extern int g_ventoy_debug;
void ventoy_debug(const char *fmt, ...);
#define debug(fmt, ...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, __VA_ARGS__)
#define debug(fmt, args...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, ##args)
#define vtoy_ssprintf(buf, pos, fmt, ...) \
pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
@@ -354,6 +396,15 @@ typedef struct wim_security_header
grub_uint32_t count; /* Number of entries */
}wim_security_header;
typedef struct wim_stream_entry
{
grub_uint64_t len;
grub_uint64_t unused1;
wim_hash hash;
grub_uint16_t name_len;
/* name */
}wim_stream_entry;
/* Directory entry */
typedef struct wim_directory_entry
{
@@ -482,7 +533,19 @@ typedef struct plugin_entry
ventoy_plugin_check_pf checkfunc;
}plugin_entry;
typedef struct replace_fs_dir
{
grub_device_t dev;
grub_fs_t fs;
char fullpath[512];
char initrd[512];
int curpos;
int dircnt;
int filecnt;
}replace_fs_dir;
int ventoy_strcmp(const char *pattern, const char *str);
int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
grub_err_t ventoy_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args);
@@ -496,6 +559,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_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);
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
@@ -506,9 +570,16 @@ int ventoy_is_dir_exist(const char *fmt, ...);
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_set_wim_prompt(grub_extcmd_context_t ctxt, int argc, char **args);
grub_ssize_t ventoy_load_file_with_prompt(grub_file_t file, void *buf, grub_ssize_t size);
int ventoy_need_prompt_load_file(void);
VTOY_JSON *vtoy_json_find_item
(
@@ -718,8 +789,17 @@ typedef struct file_fullpath
char path[256];
}file_fullpath;
typedef struct theme_list
{
file_fullpath theme;
struct theme_list *next;
}theme_list;
#define auto_install_type_file 0
#define auto_install_type_parent 1
typedef struct install_template
{
int type;
int pathlen;
char isopath[256];
@@ -731,6 +811,24 @@ typedef struct install_template
struct install_template *next;
}install_template;
typedef struct dudfile
{
int size;
char *buf;
}dudfile;
typedef struct dud
{
int pathlen;
char isopath[256];
int dudnum;
file_fullpath *dudpath;
dudfile *files;
struct dud *next;
}dud;
typedef struct persistence_config
{
int pathlen;
@@ -764,12 +862,26 @@ typedef struct menu_class
{
int type;
int patlen;
int parent;
char pattern[256];
char class[64];
struct menu_class *next;
}menu_class;
#define vtoy_custom_boot_image_file 0
#define vtoy_custom_boot_directory 1
typedef struct custom_boot
{
int type;
int pathlen;
char path[256];
char cfg[256];
struct custom_boot *next;
}custom_boot;
#define vtoy_max_replace_file_size (2 * 1024 * 1024)
typedef struct conf_replace
{
@@ -781,8 +893,11 @@ typedef struct conf_replace
struct conf_replace *next;
}conf_replace;
#define injection_type_file 0
#define injection_type_parent 1
typedef struct injection_config
{
int type;
int pathlen;
char isopath[256];
char archive[256];
@@ -806,22 +921,59 @@ typedef struct image_list
struct image_list *next;
}image_list;
#define VTOY_PASSWORD_NONE 0
#define VTOY_PASSWORD_TXT 1
#define VTOY_PASSWORD_MD5 2
#define VTOY_PASSWORD_SALT_MD5 3
typedef struct vtoy_password
{
int type;
char text[128];
char salt[64];
grub_uint8_t md5[16];
}vtoy_password;
#define vtoy_menu_pwd_file 0
#define vtoy_menu_pwd_parent 1
typedef struct menu_password
{
int type;
int pathlen;
char isopath[256];
vtoy_password password;
struct menu_password *next;
}menu_password;
extern int g_ventoy_menu_esc;
extern int g_ventoy_suppress_esc;
extern int g_ventoy_last_entry;
extern int g_ventoy_memdisk_mode;
extern int g_ventoy_iso_raw;
extern int g_ventoy_grub2_mode;
extern int g_ventoy_wimboot_mode;
extern int g_ventoy_iso_uefi_drv;
extern int g_ventoy_case_insensitive;
extern grub_uint8_t g_ventoy_chain_type;
extern int g_vhdboot_enable;
#define VENTOY_IMG_WHITE_LIST 1
#define VENTOY_IMG_BLACK_LIST 2
extern int g_plugin_image_list;
extern ventoy_gpt_info *g_ventoy_part_info;
extern grub_uint64_t g_conf_replace_offset;
extern grub_uint64_t g_svd_replace_offset;
extern conf_replace *g_conf_replace_node;
extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align;
extern grub_uint64_t g_ventoy_disk_size;
extern grub_uint64_t g_ventoy_disk_part_size[2];
extern grub_uint32_t g_ventoy_plat_data;
#define ventoy_unix_fill_virt(new_data, new_len) \
{ \
@@ -839,26 +991,34 @@ extern int g_conf_replace_new_len_align;
chain->virt_img_size_in_bytes += data_secs * 2048; \
}
#define ventoy_syscall0(name) grub_##name()
#define ventoy_syscall1(name, a) grub_##name(a)
char * ventoy_get_line(char *start);
int ventoy_cmp_img(img_info *img1, img_info *img2);
void ventoy_swap_img(img_info *img1, img_info *img2);
char * ventoy_plugin_get_cur_install_template(const char *isopath);
install_template * ventoy_plugin_find_install_template(const char *isopath);
persistence_config * ventoy_plugin_find_persistent(const char *isopath);
grub_uint64_t ventoy_get_vtoy_partsize(int part);
void ventoy_plugin_dump_injection(void);
void ventoy_plugin_dump_auto_install(void);
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
const char * ventoy_plugin_get_injection(const char *isopath);
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name);
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path);
int ventoy_plugin_check_memdisk(const char *isopath);
int ventoy_plugin_get_image_list_index(int type, const char *name);
conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
dud * ventoy_plugin_find_dud(const char *iso);
int ventoy_plugin_load_dud(dud *node, const char *isopart);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void);
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args);
@@ -868,8 +1028,11 @@ int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args);
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);
@@ -877,6 +1040,29 @@ grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_check_password(const vtoy_password *pwd, int retry);
int ventoy_plugin_add_custom_boot(const char *vcfgpath);
const char * ventoy_plugin_get_custom_boot(const char *isopath);
grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len);
int ventoy_load_part_table(const char *diskname);
int ventoy_env_init(void);
int ventoy_register_all_cmd(void);
int ventoy_unregister_all_cmd(void);
int ventoy_chain_file_size(const char *path);
int ventoy_chain_file_read(const char *path, int offset, int len, void *buf);
#define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)
#define vtoy_theme_random_boot_second 0
#define vtoy_theme_random_boot_day 1
#define vtoy_theme_random_boot_month 2
#define ventoy_env_export(env, name) \
{\
grub_env_set((env), (name));\
grub_env_export(env);\
}
#endif /* __VENTOY_DEF_H__ */

View File

@@ -740,6 +740,11 @@ static grub_uint32_t ventoy_linux_get_override_chunk_count(void)
{
count++;
}
if (g_svd_replace_offset > 0)
{
count++;
}
return count;
}
@@ -753,6 +758,11 @@ static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
count++;
}
if (g_svd_replace_offset > 0)
{
count++;
}
return sizeof(ventoy_override_chunk) * count;
}
@@ -829,6 +839,14 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
cur++;
}
if (g_svd_replace_offset > 0)
{
cur->img_offset = g_svd_replace_offset;
cur->override_size = 1;
cur->override_data[0] = 0xFF;
cur++;
}
return;
}
@@ -995,12 +1013,15 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static int ventoy_cpio_busybox64(cpio_newc_header *head)
static int ventoy_cpio_busybox64(cpio_newc_header *head, const char *file)
{
char *name;
int namelen;
int offset;
int count = 0;
char filepath[128];
grub_snprintf(filepath, sizeof(filepath), "ventoy/busybox/%s", file);
name = (char *)(head + 1);
while (name[0] && count < 2)
@@ -1010,7 +1031,7 @@ static int ventoy_cpio_busybox64(cpio_newc_header *head)
grub_memcpy(name, "ventoy/busybox/32h", 18);
count++;
}
else if (grub_strcmp(name, "ventoy/busybox/64h") == 0)
else if (grub_strcmp(name, filepath) == 0)
{
grub_memcpy(name, "ventoy/busybox/ash", 18);
count++;
@@ -1037,18 +1058,60 @@ grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char
(void)args;
debug("ventoy_cmd_busybox_64 %d\n", argc);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, args[0]);
return 0;
}
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
grub_file_t file;
char buf[16];
(void)ctxt;
(void)argc;
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
}
for (i = 0; i < 10; i++)
{
buf[0] = 0;
grub_file_seek(file, (17 + i) * 2048);
grub_file_read(file, buf, 16);
if (buf[0] == 2 && grub_strncmp(buf + 1, "CD001", 5) == 0)
{
debug("Find SVD at VD %d\n", i);
g_svd_replace_offset = (17 + i) * 2048;
break;
}
}
if (i >= 10)
{
debug("SVD not found %d\n", (int)g_svd_replace_offset);
}
grub_file_close(file);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
int rc;
char *pos = NULL;
char *template_file = NULL;
char *template_buf = NULL;
char *persistent_buf = NULL;
char *injection_buf = NULL;
dud *dudnode = NULL;
char tmpname[128];
const char *injection_file = NULL;
grub_uint8_t *buf = NULL;
grub_uint32_t mod;
@@ -1059,7 +1122,9 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
grub_uint32_t template_size = 0;
grub_uint32_t persistent_size = 0;
grub_uint32_t injection_size = 0;
grub_uint32_t dud_size = 0;
grub_file_t file;
grub_file_t archfile;
grub_file_t tmpfile;
ventoy_img_chunk_list chunk_list;
@@ -1078,12 +1143,21 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_COMM_CPIO);
if (!file)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_COMM_CPIO);
}
archfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_ARCH_CPIO);
if (!archfile)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_ARCH_CPIO);
grub_file_close(file);
}
debug("load %s %s success\n", VTOY_COMM_CPIO, VTOY_ARCH_CPIO);
if (g_ventoy_cpio_buf)
{
grub_free(g_ventoy_cpio_buf);
@@ -1152,21 +1226,47 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
debug("injection not configed %s\n", args[1]);
}
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + persistent_size + injection_size + img_chunk_size);
dudnode = ventoy_plugin_find_dud(args[1]);
if (dudnode)
{
debug("dud file: <%d>\n", dudnode->dudnum);
ventoy_plugin_load_dud(dudnode, args[2]);
for (i = 0; i < dudnode->dudnum; i++)
{
if (dudnode->files[i].size > 0)
{
dud_size += dudnode->files[i].size + sizeof(cpio_newc_header);
}
}
}
else
{
debug("dud not configed %s\n", args[1]);
}
g_ventoy_cpio_buf = grub_malloc(file->size + archfile->size + 40960 + template_size +
persistent_size + injection_size + dud_size + img_chunk_size);
if (NULL == g_ventoy_cpio_buf)
{
grub_file_close(file);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size + 4096 + img_chunk_size);
grub_file_close(archfile);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size);
}
grub_file_read(file, g_ventoy_cpio_buf, file->size);
buf = (grub_uint8_t *)(g_ventoy_cpio_buf + file->size - 4);
while (*((grub_uint32_t *)buf) != 0x37303730)
{
buf -= 4;
}
grub_file_read(archfile, buf, archfile->size);
buf += (archfile->size - 4);
while (*((grub_uint32_t *)buf) != 0x37303730)
{
buf -= 4;
}
/* get initrd head len */
initrd_head_len = ventoy_cpio_newc_fill_head(buf, 0, NULL, "initrd000.xx");
@@ -1198,6 +1298,18 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
injection_buf = NULL;
}
if (dud_size > 0)
{
for (i = 0; i < dudnode->dudnum; i++)
{
pos = grub_strrchr(dudnode->dudpath[i].path, '.');
grub_snprintf(tmpname, sizeof(tmpname), "ventoy/ventoy_dud%d%s", i, (pos ? pos : ".iso"));
dud_size = dudnode->files[i].size;
headlen = ventoy_cpio_newc_fill_head(buf, dud_size, dudnode->files[i].buf, tmpname);
buf += headlen + ventoy_align(dud_size, 4);
}
}
/* step2: insert os param to cpio */
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
padlen = sizeof(ventoy_os_param);
@@ -1218,11 +1330,22 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
ventoy_cpio_newc_fill_head(g_ventoy_initrd_head, 0, NULL, "initrd000.xx");
grub_file_close(file);
grub_file_close(archfile);
if (grub_strcmp(args[3], "busybox=64") == 0)
{
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "64h");
}
else if (grub_strcmp(args[3], "busybox=a64") == 0)
{
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "a64");
}
else if (grub_strcmp(args[3], "busybox=m64") == 0)
{
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "m64");
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);

File diff suppressed because it is too large Load Diff

View 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"
@@ -235,6 +237,21 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
return pos;
}
static int ventoy_dragonfly_append_conf(char *buf, const char *isopath)
{
int pos = 0;
debug("ventoy_dragonfly_append_conf %s\n", isopath);
vtoy_ssprintf(buf, pos, "tmpfs_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "dm_target_linear_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "initrd.img_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "initrd.img_type=\"%s\"\n", "md_image");
vtoy_ssprintf(buf, pos, "vfs.root.mountfrom=\"%s\"\n", "ufs:md0s0");
return pos;
}
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
@@ -368,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;
@@ -431,6 +616,10 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
{
g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1]);
}
else if (grub_strcmp(args[0], "DragonFly") == 0)
{
g_conf_new_len += ventoy_dragonfly_append_conf(data + file->size, args[1]);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@@ -474,6 +663,7 @@ grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char
data = grub_malloc(file->size);
if (!data)
{
debug("Failed to alloc memory for new ko %d\n", (int)file->size);
grub_file_close(file);
return 1;
}
@@ -487,6 +677,105 @@ grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
grub_uint8_t *byte;
grub_uint32_t memsize;
ventoy_image_desc *desc;
grub_uint8_t flag[32] = {
0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
};
(void)ctxt;
(void)argc;
(void)args;
debug("ventoy_cmd_unix_fill_image_desc %p\n", g_mod_new_data);
if (!g_mod_new_data)
{
goto end;
}
byte = (grub_uint8_t *)g_mod_new_data;
for (i = 0; i < g_mod_new_len - 32; i += 16)
{
if (byte[i] == 0xFF && byte[i + 1] == 0xEE)
{
if (grub_memcmp(flag, byte + i, 32) == 0)
{
debug("Find position flag at %d(0x%x)\n", i, i);
break;
}
}
}
if (i >= g_mod_new_len - 32)
{
debug("Failed to find position flag %d\n", i);
goto end;
}
desc = (ventoy_image_desc *)(byte + i);
desc->disk_size = g_ventoy_disk_size;
desc->part1_size = g_ventoy_disk_part_size[0];
grub_memcpy(desc->disk_uuid, g_ventoy_part_info->MBR.BootCode + 0x180, 16);
grub_memcpy(desc->disk_signature, g_ventoy_part_info->MBR.BootCode + 0x1B8, 4);
desc->img_chunk_count = g_img_chunk_list.cur_chunk;
memsize = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
debug("image chunk count:%u memsize:%u\n", desc->img_chunk_count, memsize);
if (memsize >= VTOY_SIZE_1MB * 8)
{
grub_printf("image chunk count:%u memsize:%u too big\n", desc->img_chunk_count, memsize);
goto end;
}
grub_memcpy(desc + 1, g_img_chunk_list.chunk, memsize);
end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args)
{
int newlen;
grub_uint8_t *buf;
(void)ctxt;
(void)argc;
(void)args;
debug("ventoy_cmd_unix_gzip_newko %p\n", g_mod_new_data);
if (!g_mod_new_data)
{
goto end;
}
buf = grub_malloc(g_mod_new_len);
if (!buf)
{
goto end;
}
newlen = ventoy_gzip_compress(g_mod_new_data, g_mod_new_len, buf, g_mod_new_len);
grub_free(g_mod_new_data);
debug("gzip org len:%d newlen:%d\n", g_mod_new_len, newlen);
g_mod_new_data = (char *)buf;
g_mod_new_len = newlen;
end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
int ventoy_compatible = 0;

View File

@@ -44,14 +44,12 @@
GRUB_MOD_LICENSE ("GPLv3+");
static int g_vhdboot_bcd_offset = 0;
static int g_vhdboot_bcd_len = 0;
static int g_vhdboot_isolen = 0;
static char *g_vhdboot_totbuf = NULL;
static char *g_vhdboot_isobuf = NULL;
static grub_uint64_t g_img_trim_head_secnum = 0;
static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen, const char *path)
{
grub_uint32_t offset;
grub_file_t file;
@@ -61,10 +59,9 @@ static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(vhdiso)/boot/bcd");
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(vhdiso)%s", path);
if (!file)
{
grub_printf("Failed to open bcd file in the image file\n");
return 1;
}
@@ -83,13 +80,15 @@ static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
return 0;
}
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2,
int bcdoffset, int bcdlen)
{
int i;
int cnt = 0;
char *pos;
grub_size_t pathlen;
const char *plat;
char *newpath = NULL;
grub_uint16_t *unicode_path;
const grub_uint8_t winloadexe[] =
{
@@ -97,6 +96,11 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
0x65, 0x00, 0x78, 0x00, 0x65, 0x00
};
while ((*vhdpath) != '/')
{
vhdpath++;
}
pathlen = sizeof(grub_uint16_t) * (grub_strlen(vhdpath) + 1);
debug("unicode path for <%s> len:%d\n", vhdpath, (int)pathlen);
@@ -110,10 +114,10 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
if (plat && (plat[0] == 'e')) /* UEFI */
{
pos = g_vhdboot_isobuf + g_vhdboot_bcd_offset;
pos = g_vhdboot_isobuf + bcdoffset;
/* winload.exe ==> winload.efi */
for (i = 0; i + (int)sizeof(winloadexe) < g_vhdboot_bcd_len; i++)
for (i = 0; i + (int)sizeof(winloadexe) < bcdlen; i++)
{
if (*((grub_uint32_t *)(pos + i)) == 0x00690077 &&
grub_memcmp(pos + i, winloadexe, sizeof(winloadexe)) == 0)
@@ -127,7 +131,8 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
debug("winload patch %d times\n", cnt);
}
for (pos = vhdpath; *pos; pos++)
newpath = grub_strdup(vhdpath);
for (pos = newpath; *pos; pos++)
{
if (*pos == '/')
{
@@ -135,40 +140,159 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
}
}
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)vhdpath, -1, NULL);
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)newpath, -1, NULL);
grub_memcpy(patch1->vhd_file_path, unicode_path, pathlen);
grub_memcpy(patch2->vhd_file_path, unicode_path, pathlen);
grub_free(newpath);
return 0;
}
static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
static int ventoy_vhd_read_parttbl(const char *filename, ventoy_gpt_info *gpt, int *index)
{
int i;
int ret = 1;
grub_uint64_t start;
grub_file_t file = NULL;
grub_disk_t disk = NULL;
grub_uint8_t zeroguid[16] = {0};
file = grub_file_open(filename, VENTOY_FILE_TYPE);
if (!file)
{
goto end;
}
disk = grub_disk_open(file->device->disk->name);
if (!disk)
{
goto end;
}
grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), gpt);
start = file->device->disk->partition->start;
if (grub_memcmp(gpt->Head.Signature, "EFI PART", 8) == 0)
{
debug("GPT part start: %llu\n", (ulonglong)start);
for (i = 0; i < 128; i++)
{
if (grub_memcmp(gpt->PartTbl[i].PartGuid, zeroguid, 16))
{
if (start == gpt->PartTbl[i].StartLBA)
{
*index = i;
break;
}
}
}
}
else
{
debug("MBR part start: %llu\n", (ulonglong)start);
for (i = 0; i < 4; i++)
{
if ((grub_uint32_t)start == gpt->MBR.PartTbl[i].StartSectorId)
{
*index = i;
break;
}
}
}
ret = 0;
end:
check_free(file, grub_file_close);
check_free(disk, grub_disk_close);
return ret;
}
static int ventoy_vhd_patch_disk(const char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
int partIndex = 0;
grub_uint64_t offset = 0;
char efipart[16] = {0};
ventoy_gpt_info *gpt = NULL;
grub_memcpy(efipart, g_ventoy_part_info->Head.Signature, sizeof(g_ventoy_part_info->Head.Signature));
if (vhdpath[0] == '/')
{
gpt = g_ventoy_part_info;
partIndex = 0;
debug("This is Ventoy ISO partIndex %d %s\n", partIndex, vhdpath);
}
else
{
gpt = grub_zalloc(sizeof(ventoy_gpt_info));
ventoy_vhd_read_parttbl(vhdpath, gpt, &partIndex);
debug("This is HDD partIndex %d %s\n", partIndex, vhdpath);
}
debug("part1 type: 0x%x <%s>\n", g_ventoy_part_info->MBR.PartTbl[0].FsFlag, efipart);
grub_memcpy(efipart, gpt->Head.Signature, sizeof(gpt->Head.Signature));
grub_memset(patch1, 0, OFFSET_OF(ventoy_patch_vhd, vhd_file_path));
grub_memset(patch2, 0, OFFSET_OF(ventoy_patch_vhd, vhd_file_path));
if (grub_strncmp(efipart, "EFI PART", 8) == 0)
{
ventoy_debug_dump_guid("GPT disk GUID: ", g_ventoy_part_info->Head.DiskGuid);
ventoy_debug_dump_guid("GPT part GUID: ", g_ventoy_part_info->PartTbl[0].PartGuid);
ventoy_debug_dump_guid("GPT disk GUID: ", gpt->Head.DiskGuid);
ventoy_debug_dump_guid("GPT partIndex GUID: ", gpt->PartTbl[partIndex].PartGuid);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch1->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch2->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
grub_memcpy(patch1->disk_signature_or_guid, gpt->Head.DiskGuid, 16);
grub_memcpy(patch1->part_offset_or_guid, gpt->PartTbl[partIndex].PartGuid, 16);
grub_memcpy(patch2->disk_signature_or_guid, gpt->Head.DiskGuid, 16);
grub_memcpy(patch2->part_offset_or_guid, gpt->PartTbl[partIndex].PartGuid, 16);
patch1->part_type = patch2->part_type = 0;
}
else
{
debug("MBR disk signature: %02x%02x%02x%02x\n",
g_ventoy_part_info->MBR.BootCode[0x1b8 + 0], g_ventoy_part_info->MBR.BootCode[0x1b8 + 1],
g_ventoy_part_info->MBR.BootCode[0x1b8 + 2], g_ventoy_part_info->MBR.BootCode[0x1b8 + 3]);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
offset = gpt->MBR.PartTbl[partIndex].StartSectorId;
offset *= 512;
debug("MBR disk signature: %02x%02x%02x%02x Part(%d) offset:%llu\n",
gpt->MBR.BootCode[0x1b8 + 0], gpt->MBR.BootCode[0x1b8 + 1],
gpt->MBR.BootCode[0x1b8 + 2], gpt->MBR.BootCode[0x1b8 + 3],
partIndex + 1, offset);
grub_memcpy(patch1->part_offset_or_guid, &offset, 8);
grub_memcpy(patch2->part_offset_or_guid, &offset, 8);
grub_memcpy(patch1->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4);
grub_memcpy(patch2->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4);
patch1->part_type = patch2->part_type = 1;
}
if (gpt != g_ventoy_part_info)
{
grub_free(gpt);
}
return 0;
}
static int ventoy_find_vhdpatch_offset(int bcdoffset, int bcdlen, int *offset)
{
int i;
int cnt = 0;
grub_uint8_t *buf = (grub_uint8_t *)(g_vhdboot_isobuf + bcdoffset);
grub_uint8_t magic[16] = {
0x5C, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00
};
for (i = 0; i < bcdlen - 16 && cnt < 2; i++)
{
if (*(grub_uint32_t *)(buf + i) == 0x0058005C)
{
if (grub_memcmp(magic, buf + i, 16) == 0)
{
*offset++ = i - (int)OFFSET_OF(ventoy_patch_vhd, vhd_file_path);
cnt++;
}
}
}
return 0;
@@ -177,6 +301,8 @@ static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *pat
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc;
int bcdoffset, bcdlen;
int patchoffset[2];
ventoy_patch_vhd *patch1;
ventoy_patch_vhd *patch2;
char envbuf[64];
@@ -194,18 +320,39 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
return 0;
}
rc = ventoy_vhd_find_bcd(&g_vhdboot_bcd_offset, &g_vhdboot_bcd_len);
rc = ventoy_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/bcd");
if (rc)
{
debug("failed to get bcd location %d\n", rc);
return 0;
}
else
{
ventoy_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset);
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]);
debug("Find /boot/bcd (%d %d) now patch it (offset: 0x%x 0x%x) ...\n",
bcdoffset, bcdlen, patchoffset[0], patchoffset[1]);
ventoy_vhd_patch_disk(args[0], patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen);
}
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x495a);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x50aa);
ventoy_vhd_patch_disk(patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2);
rc = ventoy_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/BCD");
if (rc)
{
debug("No file /boot/BCD \n");
}
else
{
ventoy_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset);
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]);
debug("Find /boot/BCD (%d %d) now patch it (offset: 0x%x 0x%x) ...\n",
bcdoffset, bcdlen, patchoffset[0], patchoffset[1]);
ventoy_vhd_patch_disk(args[0], patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen);
}
/* set buffer and size */
#ifdef GRUB_MACHINE_EFI
@@ -220,7 +367,7 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
grub_env_set("vtoy_vhd_buf_size", envbuf);
#endif
return 0;
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
@@ -342,8 +489,10 @@ static int ventoy_raw_trim_head(grub_uint64_t offset)
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
int altboot = 0;
int offset = -1;
grub_file_t file;
grub_uint8_t data = 0;
vhd_footer_t vhdfoot;
VDIPREHEADER vdihdr;
char type[16] = {0};
@@ -394,7 +543,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
}
grub_env_set(args[1], type);
debug("<%s> vtoy type: <%s> ", args[0], type);
debug("<%s> vtoy type: <%s> offset:%d\n", args[0], type, offset);
if (offset >= 0)
{
@@ -427,6 +576,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
if (grub_memcmp(gpt->PartTbl[i].PartType, "Hah!IdontNeedEFI", 16) == 0)
{
debug("part %d is grub_bios part\n", i);
altboot = 1;
grub_env_set(args[3], "1");
break;
}
@@ -436,6 +586,28 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
}
}
}
if (!altboot)
{
if (gpt->MBR.BootCode[92] == 0x22)
{
grub_file_seek(file, offset + 17908);
grub_file_read(file, &data, 1);
if (data == 0x23)
{
altboot = 1;
grub_env_set(args[3], "1");
}
else
{
debug("offset data=0x%x\n", data);
}
}
else
{
debug("BootCode: 0x%x\n", gpt->MBR.BootCode[92]);
}
}
}
else
{
@@ -447,6 +619,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
if (gpt->MBR.PartTbl[i].FsFlag == 0xEF)
{
debug("part %d is esp part in MBR mode\n", i);
altboot = 1;
grub_env_set(args[3], "1");
break;
}

View File

@@ -314,6 +314,90 @@ static int ventoy_is_pe64(grub_uint8_t *buffer)
return 0;
}
grub_err_t ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args)
{
int ret = 1;
grub_file_t file;
grub_uint8_t buf[512];
(void)ctxt;
(void)argc;
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
if (!file)
{
return 1;
}
grub_memset(buf, 0, 512);
grub_file_read(file, buf, 512);
if (ventoy_is_pe64(buf))
{
debug("%s is PE64\n", args[0]);
ret = 0;
}
else
{
debug("%s is PE32\n", args[0]);
}
grub_file_close(file);
return ret;
}
grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int size;
char *buf = NULL;
char configfile[128];
(void)ctxt;
(void)argc;
(void)args;
debug("select wimboot argc:%d\n", argc);
buf = (char *)grub_malloc(8192);
if (!buf)
{
return 0;
}
size = (int)grub_snprintf(buf, 8192,
"menuentry \"Windows Setup (32-bit)\" {\n"
" set vtoy_wimboot_sel=32\n"
"}\n"
"menuentry \"Windows Setup (64-bit)\" {\n"
" set vtoy_wimboot_sel=64\n"
"}\n"
);
buf[size] = 0;
g_ventoy_menu_esc = 1;
g_ventoy_suppress_esc = 1;
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
grub_script_execute_sourcecode(configfile);
g_ventoy_menu_esc = 0;
g_ventoy_suppress_esc = 0;
grub_free(buf);
if (g_ventoy_last_entry == 0)
{
debug("last entry=%d %s=32\n", g_ventoy_last_entry, args[0]);
grub_env_set(args[0], "32");
}
else
{
debug("last entry=%d %s=64\n", g_ventoy_last_entry, args[0]);
grub_env_set(args[0], "64");
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args)
{
wim_patch *next = NULL;
@@ -464,6 +548,8 @@ static int ventoy_read_resource(grub_file_t fp, wim_header *wimhdr, wim_resource
chunk_num = (head->raw_size + WIM_CHUNK_LEN - 1) / WIM_CHUNK_LEN;
cur_offset = (chunk_num - 1) * 4;
chunk_offset = (grub_uint32_t *)buffer_compress;
//debug("%llu %llu chunk_num=%lu", (ulonglong)head->size_in_wim, (ulonglong)head->raw_size, chunk_num);
cur_dst = buffer_decompress;
@@ -516,9 +602,11 @@ static int ventoy_read_resource(grub_file_t fp, wim_header *wimhdr, wim_resource
decompress_len = (int)lzx_decompress(buffer_compress + cur_offset, head->size_in_wim - cur_offset, cur_dst);
}
}
cur_dst += decompress_len;
total_decompress += decompress_len;
//debug("last chunk_size:%u decompresslen:%d tot:%d\n", last_chunk_size, decompress_len, total_decompress);
if (cur_dst != buffer_decompress + head->raw_size)
{
@@ -572,25 +660,31 @@ static wim_directory_entry * search_full_wim_dirent
static wim_directory_entry * search_replace_wim_dirent(void *meta_data, wim_directory_entry *dir)
{
wim_directory_entry *wim_dirent = NULL;
wim_directory_entry *wim_dirent1 = NULL;
wim_directory_entry *wim_dirent2 = NULL;
const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL };
const char *wpeinit_path[] = { "Windows", "System32", "wpeinit.exe", NULL };
const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL };
//const char *native_path[] = { "Windows", "System32", "native.exe", NULL };
wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path);
debug("search winpeshl.exe %p\n", wim_dirent);
if (wim_dirent)
wim_dirent1 = search_full_wim_dirent(meta_data, dir, pecmd_path);
debug("search pecmd.exe %p\n", wim_dirent1);
if (wim_dirent1)
{
return wim_dirent;
wim_dirent2 = search_full_wim_dirent(meta_data, dir, wpeinit_path);
debug("search wpeinit.exe %p\n", wim_dirent1);
if (wim_dirent2)
{
return wim_dirent2;
}
return wim_dirent1;
}
#if 0
wim_dirent = search_full_wim_dirent(meta_data, dir, native_path);
debug("search native.exe %p\n", wim_dirent);
if (wim_dirent)
wim_dirent1 = search_full_wim_dirent(meta_data, dir, winpeshl_path);
debug("search winpeshl.exe %p\n", wim_dirent1);
if (wim_dirent1)
{
return wim_dirent;
return wim_dirent1;
}
#endif
return NULL;
}
@@ -636,6 +730,21 @@ static wim_lookup_entry * ventoy_find_meta_entry(wim_header *header, wim_lookup_
return NULL;
}
static grub_uint64_t ventoy_get_stream_len(wim_directory_entry *dir)
{
grub_uint16_t i;
grub_uint64_t offset = 0;
wim_stream_entry *stream = (wim_stream_entry *)((char *)dir + dir->len);
for (i = 0; i < dir->streams; i++)
{
offset += stream->len;
stream = (wim_stream_entry *)((char *)stream + stream->len);
}
return offset;
}
static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directory_entry *dir)
{
if ((meta_data == NULL) || (dir == NULL))
@@ -660,8 +769,15 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo
{
ventoy_update_all_hash(patch, meta_data, (wim_directory_entry *)((char *)meta_data + dir->subdir));
}
dir = (wim_directory_entry *)((char *)dir + dir->len);
if (dir->streams)
{
dir = (wim_directory_entry *)((char *)dir + dir->len + ventoy_get_stream_len(dir));
}
else
{
dir = (wim_directory_entry *)((char *)dir + dir->len);
}
} while (dir->len >= sizeof(wim_directory_entry));
return 0;
@@ -776,7 +892,14 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
grub_crypto_hash(GRUB_MD_SHA1, wim_data->bin_hash.sha1, wim_data->jump_bin_data, wim_data->bin_raw_len);
security = (wim_security_header *)wim_data->new_meta_data;
rootdir = (wim_directory_entry *)(wim_data->new_meta_data + ((security->len + 7) & 0xFFFFFFF8U));
if (security->len > 0)
{
rootdir = (wim_directory_entry *)(wim_data->new_meta_data + ((security->len + 7) & 0xFFFFFFF8U));
}
else
{
rootdir = (wim_directory_entry *)(wim_data->new_meta_data + 8);
}
/* update all winpeshl.exe dirent entry's hash */
ventoy_update_all_hash(node, wim_data->new_meta_data, rootdir);
@@ -860,7 +983,14 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
}
security = (wim_security_header *)decompress_data;
rootdir = (wim_directory_entry *)(decompress_data + ((security->len + 7) & 0xFFFFFFF8U));
if (security->len > 0)
{
rootdir = (wim_directory_entry *)(decompress_data + ((security->len + 7) & 0xFFFFFFF8U));
}
else
{
rootdir = (wim_directory_entry *)(decompress_data + 8);
}
/* search winpeshl.exe dirent entry */
search = search_replace_wim_dirent(decompress_data, rootdir);
@@ -1054,7 +1184,48 @@ static void ventoy_windows_fill_override_data_iso9660( grub_uint64_t isosize,
return;
}
static void ventoy_windows_fill_override_data_udf( grub_uint64_t isosize, void *override)
static int ventoy_windows_fill_udf_short_ad(grub_file_t isofile, grub_uint32_t curpos,
wim_tail *wim_data, grub_uint32_t new_wim_size)
{
int i;
grub_uint32_t total = 0;
grub_uint32_t left_size = 0;
ventoy_udf_override *udf = NULL;
ventoy_udf_override tmp[4];
grub_memset(tmp, 0, sizeof(tmp));
grub_file_seek(isofile, wim_data->override_offset);
grub_file_read(isofile, tmp, sizeof(tmp));
left_size = new_wim_size;
udf = (ventoy_udf_override *)wim_data->override_data;
for (i = 0; i < 4; i++)
{
total += tmp[i].length;
if (total >= wim_data->wim_raw_size)
{
udf->length = left_size;
udf->position = curpos;
return 0;
}
else
{
udf->length = tmp[i].length;
udf->position = curpos;
}
left_size -= tmp[i].length;
curpos += udf->length / 2048;
udf++;
wim_data->override_len += sizeof(ventoy_udf_override);
}
debug("######## Too many udf ad ######\n");
return 1;
}
static void ventoy_windows_fill_override_data_udf(grub_file_t isofile, void *override)
{
grub_uint32_t data32;
grub_uint64_t data64;
@@ -1065,9 +1236,8 @@ static void ventoy_windows_fill_override_data_udf( grub_uint64_t isosize, voi
ventoy_override_chunk *cur;
wim_patch *node = NULL;
wim_tail *wim_data = NULL;
ventoy_udf_override *udf = NULL;
sector = (isosize + 2047) / 2048;
sector = (isofile->size + 2047) / 2048;
cur = (ventoy_override_chunk *)override;
@@ -1077,7 +1247,7 @@ static void ventoy_windows_fill_override_data_udf( grub_uint64_t isosize, voi
cur++;
}
debug("ventoy_windows_fill_override_data_udf %lu\n", (ulong)isosize);
debug("ventoy_windows_fill_override_data_udf %lu\n", (ulong)isofile->size);
for (node = g_wim_patch_head; node; node = node->next)
{
@@ -1118,13 +1288,11 @@ static void ventoy_windows_fill_override_data_udf( grub_uint64_t isosize, voi
data64 = new_wim_size;
grub_memcpy(cur->override_data, &(data64), 8);
udf = (ventoy_udf_override *)wim_data->override_data;
udf->length = new_wim_size;
udf->position = (grub_uint32_t)sector - udf_start_block;
/* override 3: position and length in extend data */
ventoy_windows_fill_udf_short_ad(isofile, (grub_uint32_t)sector - udf_start_block, wim_data, new_wim_size);
sector += (new_wim_size / 2048);
/* override 3: position and length in extend data */
cur++;
cur->img_offset = wim_data->override_offset;
cur->override_size = wim_data->override_len;
@@ -1301,6 +1469,54 @@ end:
return rc;
}
grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t size = 0;
const char *addr = NULL;
ventoy_chain_head *chain = NULL;
ventoy_os_param *param = NULL;
char envbuf[64];
(void)ctxt;
(void)argc;
(void)args;
addr = grub_env_get("vtoy_chain_mem_addr");
if (!addr)
{
debug("Failed to find vtoy_chain_mem_addr\n");
return 1;
}
chain = (ventoy_chain_head *)(void *)grub_strtoul(addr, NULL, 16);
if (grub_memcmp(&g_ventoy_guid, &chain->os_param.guid, 16) != 0)
{
debug("os_param.guid not match\n");
return 1;
}
size = sizeof(ventoy_os_param) + sizeof(ventoy_windows_data);
param = (ventoy_os_param *)grub_zalloc(size);
if (!param)
{
return 1;
}
grub_memcpy(param, &chain->os_param, sizeof(ventoy_os_param));
ventoy_fill_windows_rtdata(param + 1, param->vtoy_img_path);
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)param);
grub_env_set("vtoy_wimboot_mem_addr", envbuf);
debug("vtoy_wimboot_mem_addr: %s\n", envbuf);
grub_snprintf(envbuf, sizeof(envbuf), "%u", size);
grub_env_set("vtoy_wimboot_mem_size", envbuf);
debug("vtoy_wimboot_mem_size: %s\n", envbuf);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
int unknown_image = 0;
@@ -1470,7 +1686,7 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
}
else
{
ventoy_windows_fill_override_data_udf(isosize, (char *)chain + chain->override_chunk_offset);
ventoy_windows_fill_override_data_udf(file, (char *)chain + chain->override_chunk_offset);
}
/* part 5: virt chunk */
@@ -1492,7 +1708,7 @@ static grub_uint32_t ventoy_get_wim_iso_offset(const char *filepath)
grub_file_t file;
char cmdbuf[128];
grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback wimiso %s", filepath);
grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback wimiso \"%s\"", filepath);
grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(wimiso)/boot/boot.wim");
@@ -1542,6 +1758,41 @@ static int ventoy_get_wim_chunklist(const char *filename, ventoy_img_chunk_list
return 0;
}
grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t boot_index;
grub_file_t file = NULL;
wim_header *wimhdr = NULL;
(void)ctxt;
(void)argc;
wimhdr = grub_zalloc(sizeof(wim_header));
if (!wimhdr)
{
return 1;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
grub_free(wimhdr);
return 1;
}
grub_file_read(file, wimhdr, sizeof(wim_header));
grub_file_close(file);
boot_index = wimhdr->boot_index;
grub_free(wimhdr);
if (boot_index == 0)
{
return 1;
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t i = 0;
@@ -1698,3 +1949,29 @@ grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
int ventoy_chain_file_size(const char *path)
{
int size;
grub_file_t file;
file = grub_file_open(path, VENTOY_FILE_TYPE);
size = (int)(file->size);
grub_file_close(file);
return size;
}
int ventoy_chain_file_read(const char *path, int offset, int len, void *buf)
{
int size;
grub_file_t file;
file = grub_file_open(path, VENTOY_FILE_TYPE);
grub_file_seek(file, offset);
size = grub_file_read(file, buf, len);
grub_file_close(file);
return size;
}

View File

@@ -0,0 +1,56 @@
/* cache.h - Flush the processor's cache. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2004,2007 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_CACHE_H
#define GRUB_CACHE_H 1
#include <grub/symbol.h>
#include <grub/types.h>
#if defined (__i386__) || defined (__x86_64__)
static inline void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#else
void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
#endif
#ifndef GRUB_MACHINE_EMU
#if defined (__aarch64__) || defined (__ia64__) || defined (__powerpc__) || \
defined (__sparc__)
#elif defined (__i386__) || defined (__x86_64__)
static inline void
grub_arch_sync_dma_caches (volatile void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#elif defined(__mips__) && (_MIPS_SIM != _ABI64)
void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address, grub_size_t len);
#endif
#endif
#ifdef __arm__
void
grub_arm_cache_enable (void);
#endif
#endif /* ! GRUB_CACHE_HEADER */

View File

@@ -0,0 +1,309 @@
/* dl.h - types and prototypes for loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_DL_H
#define GRUB_DL_H 1
#include <grub/symbol.h>
#ifndef ASM_FILE
#include <grub/err.h>
#include <grub/types.h>
#include <grub/elf.h>
#include <grub/list.h>
#include <grub/misc.h>
#endif
/*
* Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules
* to collect module names, so we define them only when they are not
* defined already.
*/
#ifndef ASM_FILE
#ifndef GRUB_MOD_INIT
#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
static void \
grub_mod_fini (void)
#elif defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void \
grub_##name##_init (void) { grub_mod_init (0); } \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
void \
grub_##name##_fini (void) { grub_mod_fini (); } \
static void \
grub_mod_fini (void)
#else
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void grub_##name##_init (void); \
void \
grub_##name##_init (void) { grub_mod_init (0); } \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
void grub_##name##_fini (void); \
void \
grub_##name##_fini (void) { grub_mod_fini (); } \
static void \
grub_mod_fini (void)
#endif
#endif
#endif
#ifndef ASM_FILE
#ifdef __APPLE__
#define GRUB_MOD_SECTION(x) "_" #x ", _" #x ""
#else
#define GRUB_MOD_SECTION(x) "." #x
#endif
#else
#ifdef __APPLE__
#define GRUB_MOD_SECTION(x) _ ## x , _ ##x
#else
#define GRUB_MOD_SECTION(x) . ## x
#endif
#endif
/* Me, Vladimir Serbinenko, hereby I add this module check as per new
GNU module policy. Note that this license check is informative only.
Modules have to be licensed under GPLv3 or GPLv3+ (optionally
multi-licensed under other licences as well) independently of the
presence of this check and solely by linking (module loading in GRUB
constitutes linking) and GRUB core being licensed under GPLv3+.
Be sure to understand your license obligations.
*/
#ifndef ASM_FILE
#if GNUC_PREREQ (3,2)
#define ATTRIBUTE_USED __used__
#else
#define ATTRIBUTE_USED __unused__
#endif
#define GRUB_MOD_LICENSE(license) \
static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license;
#define GRUB_MOD_DEP(name) \
static const char grub_module_depend_##name[] \
__attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name
#define GRUB_MOD_NAME(name) \
static const char grub_module_name_##name[] \
__attribute__((section(GRUB_MOD_SECTION(modname)), __used__)) = #name
#else
#ifdef __APPLE__
.macro GRUB_MOD_LICENSE
.section GRUB_MOD_SECTION(module_license)
.ascii "LICENSE="
.ascii $0
.byte 0
.endm
#else
.macro GRUB_MOD_LICENSE license
.section GRUB_MOD_SECTION(module_license), "a"
.ascii "LICENSE="
.ascii "\license"
.byte 0
.endm
#endif
#endif
/* Under GPL license obligations you have to distribute your module
under GPLv3(+). However, you can also distribute the same code under
another license as long as GPLv3(+) version is provided.
*/
#define GRUB_MOD_DUAL_LICENSE(x)
#ifndef ASM_FILE
struct grub_dl_segment
{
struct grub_dl_segment *next;
void *addr;
grub_size_t size;
unsigned section;
};
typedef struct grub_dl_segment *grub_dl_segment_t;
struct grub_dl;
struct grub_dl_dep
{
struct grub_dl_dep *next;
struct grub_dl *mod;
};
typedef struct grub_dl_dep *grub_dl_dep_t;
#ifndef GRUB_UTIL
struct grub_dl
{
char *name;
int ref_count;
int persistent;
grub_dl_dep_t dep;
grub_dl_segment_t segment;
Elf_Sym *symtab;
grub_size_t symsize;
void (*init) (struct grub_dl *mod);
void (*fini) (void);
#if !defined (__i386__) && !defined (__x86_64__)
void *got;
void *gotptr;
void *tramp;
void *trampptr;
#endif
#if defined(__mips__) && (_MIPS_SIM != _ABI64)
grub_uint32_t *reginfo;
#endif
void *base;
grub_size_t sz;
struct grub_dl *next;
};
#endif
typedef struct grub_dl *grub_dl_t;
grub_dl_t grub_dl_load_file (const char *filename);
grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size);
int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
void grub_dl_unload_unneeded (void);
int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
extern grub_dl_t EXPORT_VAR(grub_dl_head);
#ifndef GRUB_UTIL
#define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
#ifdef GRUB_MACHINE_EMU
void *
grub_osdep_dl_memalign (grub_size_t align, grub_size_t size);
void
grub_dl_osdep_dl_free (void *ptr);
#endif
static inline void
grub_dl_init (grub_dl_t mod)
{
if (mod->init)
(mod->init) (mod);
mod->next = grub_dl_head;
grub_dl_head = mod;
}
static inline grub_dl_t
grub_dl_get (const char *name)
{
grub_dl_t l;
FOR_DL_MODULES(l)
if (grub_strcmp (name, l->name) == 0)
return l;
return 0;
}
static inline void
grub_dl_set_persistent (grub_dl_t mod)
{
mod->persistent = 1;
}
static inline int
grub_dl_is_persistent (grub_dl_t mod)
{
return mod->persistent;
}
#endif
grub_err_t grub_dl_register_symbol (const char *name, void *addr,
int isfunc, grub_dl_t mod);
grub_err_t grub_arch_dl_check_header (void *ehdr);
#ifndef GRUB_UTIL
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
Elf_Shdr *s, grub_dl_segment_t seg);
#endif
#if defined (__mips__) && (_MIPS_SIM != _ABI64)
#define GRUB_LINKER_HAVE_INIT 1
void grub_arch_dl_init_linker (void);
#endif
#define GRUB_IA64_DL_TRAMP_ALIGN 16
#define GRUB_IA64_DL_GOT_ALIGN 16
grub_err_t
grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
grub_err_t
grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
#if defined (__ia64__)
#define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN
#define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN
#define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size
#elif defined (__aarch64__)
#define grub_arch_dl_get_tramp_got_size grub_arm64_dl_get_tramp_got_size
#else
grub_err_t
grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
#endif
#if defined (__powerpc__) || (defined (__mips__) && (_MIPS_SIM != _ABI64)) || defined (__arm__) || \
(defined(__riscv) && (__riscv_xlen == 32))
#define GRUB_ARCH_DL_TRAMP_ALIGN 4
#define GRUB_ARCH_DL_GOT_ALIGN 4
#endif
#if defined (__aarch64__) || defined (__sparc__) || (defined (__mips__) && (_MIPS_SIM == _ABI64)) || \
(defined(__riscv) && (__riscv_xlen == 64))
#define GRUB_ARCH_DL_TRAMP_ALIGN 8
#define GRUB_ARCH_DL_GOT_ALIGN 8
#endif
#endif
#endif /* ! GRUB_DL_H */

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More