├── src ├── package │ ├── boot │ │ └── grub2 │ │ │ ├── files │ │ │ └── grub-early.cfg │ │ │ ├── patches │ │ │ ├── 300-CVE-2015-8370.patch │ │ │ ├── 001-verifiers-Blocklist-fallout-cleanup.patch │ │ │ └── 100-grub_setup_root.patch │ │ │ └── Makefile │ └── base-files │ │ └── files │ │ └── lib │ │ └── upgrade │ │ └── common.sh ├── Screenshots │ ├── 1.png │ └── 2.png ├── target │ └── linux │ │ └── x86 │ │ ├── image │ │ ├── grub-efi.cfg │ │ ├── gen_image_efi.sh │ │ ├── Makefile │ │ └── Makefile-jow-version │ │ └── base-files │ │ └── lib │ │ ├── preinit │ │ └── 79_move_config │ │ └── upgrade │ │ └── platform.sh ├── tools │ ├── popt │ │ ├── Makefile │ │ └── patches │ │ │ └── 900-autoconf-compat.patch │ ├── gptfdisk │ │ └── Makefile │ └── Makefile ├── uefi.log └── config │ └── Config-images.in ├── .gitignore ├── platform.patch ├── tools.patch ├── common.patch ├── README.md ├── Config-images.patch ├── RunMe.sh ├── Image.patch └── LICENSE /src/package/boot/grub2/files/grub-early.cfg: -------------------------------------------------------------------------------- 1 | configfile (hd0,msdos1)/boot/grub/grub.cfg 2 | -------------------------------------------------------------------------------- /src/Screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falafalafala1668/OpenWrt-UEFI-Support/HEAD/src/Screenshots/1.png -------------------------------------------------------------------------------- /src/Screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falafalafala1668/OpenWrt-UEFI-Support/HEAD/src/Screenshots/2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | src/target/linux/x86/image/Makefile.bak 3 | src/package/base-files/files/lib/upgrade/common.sh.bak 4 | -------------------------------------------------------------------------------- /src/target/linux/x86/image/grub-efi.cfg: -------------------------------------------------------------------------------- 1 | @SERIAL_CONFIG@ 2 | @TERMINAL_CONFIG@ 3 | 4 | set default="0" 5 | set timeout="@TIMEOUT@" 6 | set root='(hd0,gpt1)' 7 | 8 | menuentry "@TITLE@" { 9 | linux /boot/vmlinuz @GPT_ROOTPART@ @CMDLINE@ noinitrd 10 | } 11 | menuentry "@TITLE@ (failsafe)" { 12 | linux /boot/vmlinuz failsafe=true @GPT_ROOTPART@ @CMDLINE@ noinitrd 13 | } 14 | -------------------------------------------------------------------------------- /src/tools/popt/Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=popt 4 | PKG_VERSION:=1.16 5 | 6 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 7 | PKG_SOURCE_URL:=http://rpm5.org/files/popt 8 | PKG_HASH:=e728ed296fe9f069a0e005003c3d6b2dde3d9cad453422a10d6558616d304cc8 9 | 10 | HOST_FIXUP:=autoreconf 11 | 12 | include $(INCLUDE_DIR)/host-build.mk 13 | 14 | HOST_CONFIGURE_ARGS += \ 15 | --disable-nls \ 16 | --disable-rpath \ 17 | --enable-shared=no \ 18 | --without-libiconv-prefix \ 19 | --without-libintl-prefix 20 | 21 | $(eval $(call HostBuild)) 22 | -------------------------------------------------------------------------------- /src/uefi.log: -------------------------------------------------------------------------------- 1 | modified: package/base-files/files/lib/upgrade/common.sh 2 | renamed: package/boot/grub2/Makefile -> package/boot/grub2/common.mk 3 | new file: package/boot/grub2/grub2-efi/Makefile 4 | new file: package/boot/grub2/grub2/Makefile 5 | new file: target/linux/x86/image/gen_image_efi.sh 6 | modified: tools/Makefile 7 | new file: tools/gptfdisk/Makefile 8 | new file: tools/popt/Makefile 9 | new file: tools/popt/patches/900-autoconf-compat.patch 10 | both modified: config/Config-images.in 11 | both modified: target/linux/x86/image/Makefile 12 | -------------------------------------------------------------------------------- /src/target/linux/x86/base-files/lib/preinit/79_move_config: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012-2015 OpenWrt.org 2 | 3 | move_config() { 4 | local partdev parttype=ext4 5 | 6 | . /lib/upgrade/common.sh 7 | 8 | if export_bootdevice && export_partdevice partdev 1; then 9 | mkdir -p /boot 10 | part_magic_fat "/dev/$partdev" && parttype=vfat 11 | mount -t $parttype -o rw,noatime "/dev/$partdev" /boot 12 | if [ -f "/boot/$BACKUP_FILE" ]; then 13 | mv -f "/boot/$BACKUP_FILE" / 14 | fi 15 | mount --bind /boot/boot /boot 16 | fi 17 | } 18 | 19 | boot_hook_add preinit_mount_root move_config 20 | -------------------------------------------------------------------------------- /platform.patch: -------------------------------------------------------------------------------- 1 | --- target/linux/x86/base-files/lib/upgrade/platform.sh 2021-07-19 13:53:00.384594776 +0800 2 | +++ OpenWrt-UEFI-Support/src/target/linux/x86/base-files/lib/upgrade/platform.sh 2021-07-14 23:33:16.064276218 +0800 3 | @@ -35,10 +35,11 @@ 4 | } 5 | 6 | platform_copy_config() { 7 | - local partdev 8 | + local partdev parttype=ext4 9 | 10 | if export_partdevice partdev 1; then 11 | - mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt 12 | + part_magic_fat "/dev/$partdev" && parttype=vfat 13 | + mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 14 | cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE" 15 | umount /mnt 16 | fi 17 | -------------------------------------------------------------------------------- /src/tools/popt/patches/900-autoconf-compat.patch: -------------------------------------------------------------------------------- 1 | --- a/configure.ac 2 | +++ b/configure.ac 3 | @@ -46,7 +46,7 @@ AC_GCC_TRADITIONAL 4 | AC_SYS_LARGEFILE 5 | 6 | AC_ISC_POSIX 7 | -AM_C_PROTOTYPES 8 | +AC_C_PROTOTYPES 9 | 10 | AC_CHECK_HEADERS(float.h fnmatch.h glob.h langinfo.h libintl.h mcheck.h unistd.h) 11 | 12 | --- a/Makefile.am 13 | +++ b/Makefile.am 14 | @@ -35,9 +35,10 @@ tdict_LDADD = $(usrlib_LTLIBRARIES) 15 | noinst_SCRIPTS = testit.sh 16 | 17 | TESTS_ENVIRONMENT = \ 18 | +TESTS_DIR="$(top_srcdir)" \ 19 | test1="$(top_builddir)/test1" 20 | 21 | -TESTS = $(top_srcdir)/testit.sh 22 | +TESTS = testit.sh 23 | 24 | include_HEADERS = popt.h 25 | 26 | -------------------------------------------------------------------------------- /src/tools/gptfdisk/Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=gptfdisk 4 | PKG_VERSION:=1.0.1 5 | 6 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 7 | PKG_SOURCE_URL:=http://www.rodsbooks.com/gdisk/ 8 | PKG_HASH:=864c8aee2efdda50346804d7e6230407d5f42a8ae754df70404dd8b2fdfaeac7 9 | 10 | HOST_BUILD_PARALLEL := 1 11 | 12 | include $(INCLUDE_DIR)/host-build.mk 13 | 14 | HOST_CPPFLAGS += \ 15 | -I$(STAGING_DIR_HOST)/include/e2fsprogs 16 | 17 | define Host/Compile 18 | $(call Host/Compile/Default,sgdisk) 19 | endef 20 | 21 | define Host/Install 22 | $(INSTALL_BIN) $(HOST_BUILD_DIR)/sgdisk $(STAGING_DIR_HOST)/bin/ 23 | endef 24 | 25 | define Host/Clean 26 | rm -f $(STAGING_DIR_HOST)/bin/sgdisk 27 | endef 28 | 29 | $(eval $(call HostBuild)) 30 | -------------------------------------------------------------------------------- /tools.patch: -------------------------------------------------------------------------------- 1 | --- tools/Makefile 2021-07-19 13:53:00.387578168 +0800 2 | +++ OpenWrt-UEFI-Support/src/tools/Makefile 2020-12-12 20:43:12.549168593 +0800 3 | @@ -29,6 +29,7 @@ 4 | tools-y += mtools dosfstools libressl 5 | tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2 6 | tools-$(CONFIG_TARGET_x86) += qemu 7 | +tools-$(CONFIG_EFI_IMAGES) += gptfdisk popt 8 | tools-$(CONFIG_TARGET_mxs) += elftosb sdimage 9 | tools-$(CONFIG_TARGET_ar71xx) += lzma-old 10 | tools-$(CONFIG_TARGET_ar71xx)$(CONFIG_TARGET_ath79) += squashfs 11 | @@ -78,6 +79,7 @@ 12 | $(curdir)/lzma-old/compile := $(curdir)/zlib/compile 13 | $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile 14 | $(curdir)/cbootimage/compile += $(curdir)/automake/compile 15 | +$(curdir)/gptfdisk/compile += $(curdir)/e2fsprogs/compile $(curdir)/popt/compile 16 | 17 | ifneq ($(HOST_OS),Linux) 18 | $(curdir)/squashfskit4/compile += $(curdir)/coreutils/compile 19 | -------------------------------------------------------------------------------- /src/target/linux/x86/image/gen_image_efi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x 3 | [ $# == 5 -o $# == 6 ] || { 4 | echo "SYNTAX: $0 []" 5 | exit 1 6 | } 7 | 8 | OUTPUT="$1" 9 | KERNELSIZE="$2" 10 | KERNELDIR="$3" 11 | ROOTFSSIZE="$4" 12 | ROOTFSIMAGE="$5" 13 | ALIGN="$6" 14 | 15 | rm -f "$OUTPUT" 16 | 17 | head=16 18 | sect=63 19 | 20 | cyl=$(( ($KERNELSIZE + $ROOTFSSIZE) * 1024 * 1024 / ($head * $sect * 512) )) 21 | 22 | # create partition table 23 | set `ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE}` 24 | 25 | KERNELOFFSET="$(($1 / 512))" 26 | KERNELSIZE="$2" 27 | ROOTFSOFFSET="$(($3 / 512))" 28 | ROOTFSSIZE="$(($4 / 512))" 29 | 30 | 31 | dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE" 32 | dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc 33 | 34 | rm -rf ${KERNELDIR%/*}/kernel.efi || true 35 | mkfs.fat -C ${KERNELDIR%/*}/kernel.efi -S 512 "$((KERNELSIZE / 1024))" 36 | mcopy -s -i "${KERNELDIR%/*}/kernel.efi" "$KERNELDIR"/* ::/ 37 | dd if="${KERNELDIR%/*}/kernel.efi" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc 38 | -------------------------------------------------------------------------------- /src/package/boot/grub2/patches/300-CVE-2015-8370.patch: -------------------------------------------------------------------------------- 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 | From: Hector Marco-Gisbert 3 | Date: Fri, 13 Nov 2015 16:21:09 +0100 4 | Subject: [PATCH] Fix security issue when reading username and password 5 | 6 | This patch fixes two integer underflows at: 7 | * grub-core/lib/crypto.c 8 | * grub-core/normal/auth.c 9 | 10 | Resolves: CVE-2015-8370 11 | 12 | Signed-off-by: Hector Marco-Gisbert 13 | Signed-off-by: Ismael Ripoll-Ripoll 14 | --- 15 | grub-core/lib/crypto.c | 2 +- 16 | grub-core/normal/auth.c | 2 +- 17 | 2 files changed, 2 insertions(+), 2 deletions(-) 18 | 19 | --- a/grub-core/lib/crypto.c 20 | +++ b/grub-core/lib/crypto.c 21 | @@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned 22 | break; 23 | } 24 | 25 | - if (key == '\b') 26 | + if (key == '\b' && cur_len) 27 | { 28 | if (cur_len) 29 | cur_len--; 30 | --- a/grub-core/normal/auth.c 31 | +++ b/grub-core/normal/auth.c 32 | @@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned 33 | break; 34 | } 35 | 36 | - if (key == GRUB_TERM_BACKSPACE) 37 | + if (key == GRUB_TERM_BACKSPACE && cur_len) 38 | { 39 | if (cur_len) 40 | { 41 | -------------------------------------------------------------------------------- /src/package/boot/grub2/patches/001-verifiers-Blocklist-fallout-cleanup.patch: -------------------------------------------------------------------------------- 1 | From: David Michael 2 | Date: Fri, 5 Jul 2019 07:45:59 -0400 3 | Subject: [PATCH] verifiers: Blocklist fallout cleanup 4 | 5 | Blocklist fallout cleanup after commit 5c6f9bc15 (generic/blocklist: Fix 6 | implicit declaration of function grub_file_filter_disable_compression()). 7 | 8 | Signed-off-by: David Michael 9 | Reviewed-by: Daniel Kiper 10 | --- 11 | 12 | --- a/grub-core/osdep/generic/blocklist.c 13 | +++ b/grub-core/osdep/generic/blocklist.c 14 | @@ -59,7 +59,7 @@ grub_install_get_blocklist (grub_device_ 15 | 16 | grub_disk_cache_invalidate_all (); 17 | 18 | - file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | FILE_TYPE_NO_DECOMPRESS); 19 | + file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | GRUB_FILE_TYPE_NO_DECOMPRESS); 20 | if (file) 21 | { 22 | if (grub_file_size (file) != core_size) 23 | @@ -116,7 +116,7 @@ grub_install_get_blocklist (grub_device_ 24 | 25 | grub_file_t file; 26 | /* Now read the core image to determine where the sectors are. */ 27 | - file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | FILE_TYPE_NO_DECOMPRESS); 28 | + file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | GRUB_FILE_TYPE_NO_DECOMPRESS); 29 | if (! file) 30 | grub_util_error ("%s", grub_errmsg); 31 | 32 | -------------------------------------------------------------------------------- /src/target/linux/x86/base-files/lib/upgrade/platform.sh: -------------------------------------------------------------------------------- 1 | platform_check_image() { 2 | local diskdev partdev diff 3 | [ "$#" -gt 1 ] && return 1 4 | 5 | case "$(get_magic_word "$1")" in 6 | eb48|eb63) ;; 7 | *) 8 | echo "Invalid image type" 9 | return 1 10 | ;; 11 | esac 12 | 13 | export_bootdevice && export_partdevice diskdev 0 || { 14 | echo "Unable to determine upgrade device" 15 | return 1 16 | } 17 | 18 | get_partitions "/dev/$diskdev" bootdisk 19 | 20 | #extract the boot sector from the image 21 | get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null 22 | 23 | get_partitions /tmp/image.bs image 24 | 25 | #compare tables 26 | diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" 27 | 28 | rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image 29 | 30 | if [ -n "$diff" ]; then 31 | echo "Partition layout has changed. Full image will be written." 32 | ask_bool 0 "Abort" && exit 1 33 | return 0 34 | fi 35 | } 36 | 37 | platform_copy_config() { 38 | local partdev parttype=ext4 39 | 40 | if export_partdevice partdev 1; then 41 | part_magic_fat "/dev/$partdev" && parttype=vfat 42 | mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 43 | cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE" 44 | umount /mnt 45 | fi 46 | } 47 | 48 | platform_do_upgrade() { 49 | local diskdev partdev diff 50 | 51 | export_bootdevice && export_partdevice diskdev 0 || { 52 | echo "Unable to determine upgrade device" 53 | return 1 54 | } 55 | 56 | sync 57 | 58 | if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then 59 | get_partitions "/dev/$diskdev" bootdisk 60 | 61 | #extract the boot sector from the image 62 | get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 63 | 64 | get_partitions /tmp/image.bs image 65 | 66 | #compare tables 67 | diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" 68 | else 69 | diff=1 70 | fi 71 | 72 | if [ -n "$diff" ]; then 73 | get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync 74 | 75 | # Separate removal and addtion is necessary; otherwise, partition 1 76 | # will be missing if it overlaps with the old partition 2 77 | partx -d - "/dev/$diskdev" 78 | partx -a - "/dev/$diskdev" 79 | 80 | return 0 81 | fi 82 | 83 | #iterate over each partition from the image and write it to the boot disk 84 | while read part start size; do 85 | if export_partdevice partdev $part; then 86 | echo "Writing image to /dev/$partdev..." 87 | get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync 88 | else 89 | echo "Unable to find partition $part device, skipped." 90 | fi 91 | done < /tmp/partmap.image 92 | 93 | #copy partition uuid 94 | echo "Writing new UUID to /dev/$diskdev..." 95 | get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync 96 | } 97 | -------------------------------------------------------------------------------- /common.patch: -------------------------------------------------------------------------------- 1 | --- package/base-files/files/lib/upgrade/common.sh 2021-10-19 01:16:08.610141522 +0800 2 | +++ OpenWrt-UEFI-Support/src/package/base-files/files/lib/upgrade/common.sh 2021-10-18 23:52:51.000000000 +0800 3 | @@ -102,6 +102,29 @@ 4 | (get_image "$@" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null 5 | } 6 | 7 | +get_magic_gpt() { 8 | + (get_image "$@" | dd bs=8 count=1 skip=64) 2>/dev/null 9 | +} 10 | + 11 | +get_magic_vfat() { 12 | + (get_image "$@" | dd bs=3 count=1 skip=18) 2>/dev/null 13 | +} 14 | + 15 | +get_magic_fat32() { 16 | + (get_image "$@" | dd bs=1 count=5 skip=82) 2>/dev/null 17 | +} 18 | + 19 | +part_magic_efi() { 20 | + local magic=$(get_magic_gpt "$@") 21 | + [ "$magic" = "EFI PART" ] 22 | +} 23 | + 24 | +part_magic_fat() { 25 | + local magic=$(get_magic_vfat "$@") 26 | + local magic_fat32=$(get_magic_fat32 "$@") 27 | + [ "$magic" = "FAT" ] || [ "$magic_fat32" = "FAT32" ] 28 | +} 29 | + 30 | export_bootdevice() { 31 | local cmdline bootdisk rootpart uuid blockdev uevent line class 32 | local MAJOR MINOR DEVNAME DEVTYPE 33 | @@ -125,6 +148,19 @@ 34 | esac 35 | 36 | case "$rootpart" in 37 | + PARTUUID=????????-????-????-????-????????0002) 38 | + uuid="${rootpart#PARTUUID=}" 39 | + for blockdev in $(find /dev -type b); do 40 | + set -- $(dd if=$blockdev bs=1 skip=1168 count=16 2>/dev/null | hexdump -v -e '8/1 "%02X "" "2/1 "%02X""-"6/1 "%02X"') 41 | + if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then 42 | + blockdev=${blockdev##*/} 43 | + uevent="/sys/class/block/${blockdev%[0-9]}/uevent" 44 | + export UPGRADE_OPT_SAVE_PARTITIONS="0" 45 | + break 46 | + fi 47 | + done 48 | + 49 | + ;; 50 | PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-[a-f0-9][a-f0-9]) 51 | uuid="${rootpart#PARTUUID=}" 52 | uuid="${uuid%-[a-f0-9][a-f0-9]}" 53 | @@ -208,7 +244,25 @@ 54 | 55 | local part 56 | for part in 1 2 3 4; do 57 | - set -- $(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk") 58 | + part_magic_efi "$disk" && { 59 | + case $(hexdump -v -n 16 -s "$(( 0x380 + $part * 128 ))" -e '4/4 "%08X"' "$disk") in 60 | + "0FC63DAF47728483693D798EE47D47D8") 61 | + gptTypeID="0x00000083" 62 | + ;; 63 | + "C12A732811D2F81FA0004BBA3BC93EC9") 64 | + gptTypeID="0x000000EE" 65 | + ;; 66 | + *) 67 | + gptTypeID="0x00000000" 68 | + ;; 69 | + esac 70 | + 71 | + gptLBA=$(hexdump -v -n 4 -s $(( 0x3A0 + $part * 128 )) -e '1/4 "0x%08X"' "$disk") 72 | + gptNUM=$(hexdump -v -n 4 -s $(( 0x3A8 + $part * 128 )) -e '1/4 "0x%08X"' "$disk") 73 | + set -- $gptTypeID $gptLBA $gptNUM 74 | + } || { 75 | + set -- $(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk") 76 | + } 77 | 78 | local type="$(( $(hex_le32_to_cpu $1) % 256))" 79 | local lba="$(( $(hex_le32_to_cpu $2) ))" 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenWrt UEFI Support (19.07 Branch, Unofficial Support) 2 | ### IMPORTANT 3 | 4 | **Openwrt has officially supported UEFI, but v19.07 and v18.06 not. So v19.07 and v18.06 will continue to update.** 5 | 6 | --- 7 | Since OpenWrt Project has not yet accepted any UEFI-Boot approach, extract based on the original jow.git and modify it to be compatible with the current version. 8 | 9 | These patches are for the convenience of quickly adding UEFI startup support and these are **temporary solutions**. 10 | 11 | Tested in Openwrt 19.07.8 12 | 13 | ![](https://github.com/falafalafala1668/OpenWrt-UEFI-Support/blob/master/src/Screenshots/2.png) 14 | 15 | # Usage 16 | Before clone the patches, please check your OpenWrt source branch: 17 | 18 | **19.07** 19 | ``` 20 | git clone https://github.com/falafalafala1668/OpenWrt-UEFI-Support.git -b openwrt-19.07 21 | ``` 22 | 23 | **18.06** 24 | ``` 25 | git clone https://github.com/falafalafala1668/OpenWrt-UEFI-Support.git -b openwrt-18.06 26 | ``` 27 | 28 | then, in your OpenWrt source dir, enter: 29 | 30 | ``` 31 | ./OpenWrt-UEFI-Support/RunMe.sh apply 32 | ``` 33 | 34 | After patches, run make menuconfig. 35 | 36 | Go to **Target Images** and make sure that **Build EFI grub images** option is checked. 37 | 38 | ![](https://github.com/falafalafala1668/OpenWrt-UEFI-Support/blob/master/src/Screenshots/1.png) 39 | 40 | ## Update 41 | 42 | Before update, Please ensure that the following folder or files have not been modified. 43 | ``` 44 | config/Config-images.in 45 | package/base-files/files/lib/upgrade/common.sh 46 | package/boot/grub2 47 | tools/Makefile 48 | target/linux/x86/base-files/lib/upgrade/platform.sh 49 | target/linux/x86/image/Makefile 50 | ``` 51 | 52 | If the patch has been applied, restore it: 53 | ``` 54 | ./OpenWrt-UEFI-Support/RunMe.sh restore 55 | ``` 56 | 57 | then enter: 58 | 59 | ``` 60 | ./OpenWrt-UEFI-Support/RunMe.sh update 61 | ``` 62 | 63 | Finally apply the patch: 64 | ``` 65 | ./OpenWrt-UEFI-Support/RunMe.sh apply 66 | ``` 67 | 68 | ## Restore 69 | 70 | ``` 71 | ./OpenWrt-UEFI-Support/RunMe.sh restore 72 | ``` 73 | 74 | # Known Issues 75 | 76 | Booting UEFI Image on PVE will be panic or freeze because on graphic card driver issue.(Thanks reporter [#2](https://github.com/falafalafala1668/OpenWrt-UEFI-Support/issues/2)) 77 | 78 | ### Solution 79 | 80 | Add ``nomodeset`` to stop using the graphic card driver (``Target Images -> Extra kernel boot options``). 81 | 82 | # Advanced Settings 83 | If you OpenWrt isn't official sources, or you have been modified these folder or files. You can generate patches by yourself. 84 | 85 | ``` 86 | config/Config-images.in 87 | package/base-files/files/lib/upgrade/common.sh 88 | package/boot/grub2 89 | tools/Makefile 90 | target/linux/x86/base-files/lib/upgrade/platform.sh 91 | target/linux/x86/image/Makefile 92 | ``` 93 | 94 | then enter: 95 | 96 | ``` 97 | ./OpenWrt-UEFI-Support/RunMe.sh generate 98 | ``` 99 | then apply the patches 100 | ``` 101 | ./OpenWrt-UEFI-Support/RunMe.sh apply 102 | ``` 103 | 104 | # Acknowledgement 105 | [OpenWrt Project](https://github.com/openwrt/openwrt.git) 106 | 107 | [Jo-Philipp Wich](https://git.openwrt.org/openwrt/staging/jow.git) 108 | 109 | [Alif M. Ahmad](https://github.com/alive4ever/openwrt) 110 | 111 | # Reference 112 | [OpenWrt on UEFI based x86 systems](https://openwrt.org/docs/guide-developer/uefi-bootable-image) 113 | -------------------------------------------------------------------------------- /Config-images.patch: -------------------------------------------------------------------------------- 1 | --- config/Config-images.in 2021-07-19 13:53:17.172776454 +0800 2 | +++ OpenWrt-UEFI-Support/src/config/Config-images.in 2021-07-18 23:40:59.420839832 +0800 3 | @@ -193,21 +193,29 @@ 4 | depends on TARGET_x86 5 | depends on TARGET_ROOTFS_EXT4FS || TARGET_ROOTFS_ISO || TARGET_ROOTFS_JFFS2 || TARGET_ROOTFS_SQUASHFS 6 | select PACKAGE_grub2 7 | + default n 8 | + 9 | + config EFI_IMAGES 10 | + bool "Build EFI GRUB images (Linux x86 or x86_64 host only)" 11 | + depends on TARGET_x86 12 | + depends on TARGET_ROOTFS_EXT4FS || TARGET_ROOTFS_ISO || TARGET_ROOTFS_JFFS2 || TARGET_ROOTFS_SQUASHFS 13 | + select PACKAGE_grub2-efi 14 | + select PACKAGE_kmod-fs-vfat 15 | default y 16 | 17 | config GRUB_CONSOLE 18 | bool "Use Console Terminal (in addition to Serial)" 19 | - depends on GRUB_IMAGES 20 | + depends on GRUB_IMAGES || EFI_IMAGES 21 | default y 22 | 23 | config GRUB_SERIAL 24 | string "Serial port device" 25 | - depends on GRUB_IMAGES 26 | + depends on GRUB_IMAGES || EFI_IMAGES 27 | default "ttyS0" 28 | 29 | config GRUB_BAUDRATE 30 | int "Serial port baud rate" 31 | - depends on GRUB_IMAGES 32 | + depends on GRUB_IMAGES || EFI_IMAGES 33 | default 38400 if TARGET_x86_generic 34 | default 115200 35 | 36 | @@ -218,20 +226,20 @@ 37 | 38 | config GRUB_BOOTOPTS 39 | string "Extra kernel boot options" 40 | - depends on GRUB_IMAGES 41 | + depends on GRUB_IMAGES || EFI_IMAGES 42 | help 43 | If you don't know, just leave it blank. 44 | 45 | config GRUB_TIMEOUT 46 | string "Seconds to wait before booting the default entry" 47 | - depends on GRUB_IMAGES 48 | + depends on GRUB_IMAGES || EFI_IMAGES 49 | default "5" 50 | help 51 | If you don't know, 5 seconds is a reasonable default. 52 | 53 | config GRUB_TITLE 54 | string "Title for the menu entry in GRUB" 55 | - depends on GRUB_IMAGES 56 | + depends on GRUB_IMAGES || EFI_IMAGES 57 | default "OpenWrt" 58 | help 59 | This is the title of the GRUB menu entry. 60 | @@ -240,14 +248,14 @@ 61 | config VDI_IMAGES 62 | bool "Build VirtualBox image files (VDI)" 63 | depends on TARGET_x86 64 | - select GRUB_IMAGES 65 | + select EFI_IMAGES 66 | select TARGET_IMAGES_PAD 67 | select PACKAGE_kmod-e1000 68 | 69 | config VMDK_IMAGES 70 | bool "Build VMware image files (VMDK)" 71 | depends on TARGET_x86 72 | - select GRUB_IMAGES 73 | + select EFI_IMAGES 74 | select TARGET_IMAGES_PAD 75 | select PACKAGE_kmod-e1000 76 | 77 | @@ -266,21 +274,21 @@ 78 | 79 | config TARGET_KERNEL_PARTSIZE 80 | int "Kernel partition size (in MB)" 81 | - depends on GRUB_IMAGES || USES_BOOT_PART 82 | + depends on GRUB_IMAGES || EFI_IMAGES || USES_BOOT_PART 83 | default 8 if TARGET_apm821xx_sata 84 | default 20 if TARGET_brcm2708 85 | default 16 86 | 87 | config TARGET_ROOTFS_PARTSIZE 88 | int "Root filesystem partition size (in MB)" 89 | - depends on GRUB_IMAGES || USES_ROOTFS_PART || TARGET_ROOTFS_EXT4FS || TARGET_omap || TARGET_rb532 || TARGET_sunxi || TARGET_uml 90 | + depends on GRUB_IMAGES || EFI_IMAGES || USES_ROOTFS_PART || TARGET_ROOTFS_EXT4FS || TARGET_omap || TARGET_rb532 || TARGET_sunxi || TARGET_uml 91 | default 256 92 | help 93 | Select the root filesystem partition size. 94 | 95 | config TARGET_ROOTFS_PARTNAME 96 | string "Root partition on target device" 97 | - depends on GRUB_IMAGES 98 | + depends on GRUB_IMAGES || EFI_IMAGES 99 | help 100 | Override the root partition on the final device. If left empty, 101 | it will be mounted by PARTUUID which makes the kernel find the 102 | -------------------------------------------------------------------------------- /src/package/boot/grub2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2006-2015 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | include $(INCLUDE_DIR)/kernel.mk 10 | 11 | PKG_NAME:=grub 12 | PKG_CPE_ID:=cpe:/a:gnu:grub2 13 | PKG_VERSION:=2.04 14 | PKG_RELEASE:=3 15 | 16 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz 17 | PKG_SOURCE_URL:=@GNU/grub 18 | PKG_HASH:=e5292496995ad42dabe843a0192cf2a2c502e7ffcc7479398232b10a472df77d 19 | 20 | HOST_BUILD_PARALLEL:=1 21 | PKG_BUILD_DEPENDS:=grub2/host 22 | 23 | PKG_ASLR_PIE:=0 24 | PKG_SSP:=0 25 | 26 | PKG_FLAGS:=nonshared 27 | 28 | include $(INCLUDE_DIR)/host-build.mk 29 | include $(INCLUDE_DIR)/package.mk 30 | 31 | define Package/grub2/Default 32 | CATEGORY:=Boot Loaders 33 | SECTION:=boot 34 | TITLE:=GRand Unified Bootloader ($(1)) 35 | URL:=http://www.gnu.org/software/grub/ 36 | DEPENDS:=@TARGET_x86 37 | VARIANT:=$(1) 38 | endef 39 | 40 | Package/grub2=$(call Package/grub2/Default,pc) 41 | Package/grub2-efi=$(call Package/grub2/Default,efi) 42 | 43 | define Package/grub2-editenv 44 | CATEGORY:=Utilities 45 | SECTION:=utils 46 | SUBMENU:=Boot Loaders 47 | TITLE:=Grub2 Environment editor 48 | URL:=http://www.gnu.org/software/grub/ 49 | DEPENDS:=@TARGET_x86 50 | VARIANT:=pc 51 | endef 52 | 53 | define Package/grub2-editenv/description 54 | Edit grub2 environment files. 55 | endef 56 | 57 | HOST_BUILD_PREFIX := $(STAGING_DIR_HOST) 58 | 59 | CONFIGURE_VARS += \ 60 | grub_build_mkfont_excuse="don't want fonts" 61 | 62 | CONFIGURE_ARGS += \ 63 | --target=$(REAL_GNU_TARGET_NAME) \ 64 | --disable-werror \ 65 | --disable-nls \ 66 | --disable-device-mapper \ 67 | --disable-libzfs \ 68 | --disable-grub-mkfont \ 69 | --with-platform=$(BUILD_VARIANT) 70 | 71 | HOST_CONFIGURE_VARS += \ 72 | grub_build_mkfont_excuse="don't want fonts" 73 | 74 | HOST_CONFIGURE_ARGS += \ 75 | --disable-grub-mkfont \ 76 | --target=$(REAL_GNU_TARGET_NAME) \ 77 | --sbindir="$(STAGING_DIR_HOST)/bin" \ 78 | --disable-werror \ 79 | --disable-libzfs \ 80 | --disable-nls \ 81 | --with-platform=none 82 | 83 | HOST_MAKE_FLAGS += \ 84 | TARGET_RANLIB=$(TARGET_RANLIB) \ 85 | LIBLZMA=$(STAGING_DIR_HOST)/lib/liblzma.a 86 | 87 | TARGET_CFLAGS := $(filter-out -fno-plt,$(TARGET_CFLAGS)) 88 | 89 | define Host/Configure 90 | $(SED) 's,(RANLIB),(TARGET_RANLIB),' $(HOST_BUILD_DIR)/grub-core/Makefile.in 91 | $(Host/Configure/Default) 92 | endef 93 | 94 | define Package/grub2/install 95 | $(INSTALL_DIR) $(1)/usr/sbin 96 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-bios-setup $(1)/usr/sbin/ 97 | $(INSTALL_DIR) $(STAGING_DIR_IMAGE)/grub2 98 | $(CP) $(PKG_BUILD_DIR)/grub-core/boot.img $(STAGING_DIR_IMAGE)/grub2/ 99 | $(CP) $(PKG_BUILD_DIR)/grub-core/cdboot.img $(STAGING_DIR_IMAGE)/grub2/ 100 | endef 101 | 102 | define Package/grub2-efi/install 103 | sed 's#msdos1#gpt1#g' ./files/grub-early.cfg > $(PKG_BUILD_DIR)/grub-early.cfg 104 | test -d "$(STAGING_DIR_IMAGE)" || mkdir -p "$(STAGING_DIR_IMAGE)/grub2" 105 | $(STAGING_DIR_HOST)/bin/grub-mkimage \ 106 | -d $(PKG_BUILD_DIR)/grub-core \ 107 | -p /boot/grub \ 108 | -O $(CONFIG_ARCH)-efi \ 109 | -c $(PKG_BUILD_DIR)/grub-early.cfg \ 110 | -o $(STAGING_DIR_IMAGE)/grub2/boot$(if $(CONFIG_x86_64),x64,ia32).efi \ 111 | at_keyboard boot chain configfile fat linux ls part_gpt reboot serial efi_gop efi_uga 112 | endef 113 | 114 | define Package/grub2-editenv/install 115 | $(INSTALL_DIR) $(1)/usr/sbin 116 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-editenv $(1)/usr/sbin/ 117 | endef 118 | 119 | $(eval $(call HostBuild)) 120 | $(eval $(call BuildPackage,grub2)) 121 | $(eval $(call BuildPackage,grub2-efi)) 122 | $(eval $(call BuildPackage,grub2-editenv)) 123 | -------------------------------------------------------------------------------- /RunMe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | restore_patch() { 3 | if [ -f ".UEFIDone" ]; then 4 | echo "###### Restoring Patches ######" 5 | for i in $(ls $(currentdir)/*.patch) 6 | do 7 | if [ "${i}" = "OpenWrt-UEFI-Support/platform.patch" ] && [ "$(cat .UEFIDone)" = "" ]; then 8 | echo "platform.sh nothing to restore" 9 | else 10 | patch -REp0 < "$i" 11 | fi 12 | done 13 | 14 | rm -rf "package/boot/grub2" 15 | git checkout "package/boot/grub2" "target/linux/x86/base-files/lib/preinit/79_move_config" 16 | # rm -rf package/libs/gnuefi package/utils/efi* package/utils/sbsigntool 17 | rm -rf "tools/gptfdisk" "tools/popt" 18 | rm -f "target/linux/x86/image/gen_image_efi.sh" "target/linux/x86/image/grub-efi.cfg" 19 | rm -f ".UEFIDone" 20 | else 21 | echo "Already Restored." 22 | fi 23 | } 24 | 25 | apply_patch() { 26 | if [ ! -f ".UEFIDone" ]; then 27 | echo "###### Applying patches ######" 28 | for i in $(ls $(currentdir)/*.patch) 29 | do 30 | patch -p0 < "$i" 31 | done 32 | 33 | echo "Copying necessary files..." 34 | # cp -r $(currentdir)/src/package/libs/gnu-efi package/libs/ 35 | # cp -r $(currentdir)/src/package/utils/sbsigntool package/utils/ 36 | # cp -r $(currentdir)/src/package/utils/efi* package/utils/ 37 | rm -rf "package/boot/grub2" 38 | cp -r "$(currentdir)/src/package/boot/grub2" "package/boot/" 39 | cp -f "$(currentdir)/src/target/linux/x86/image/gen_image_efi.sh" "$(currentdir)/src/target/linux/x86/image/grub-efi.cfg" "target/linux/x86/image/" 40 | cp -f "$(currentdir)/src/target/linux/x86/base-files/lib/preinit/79_move_config" "target/linux/x86/base-files/lib/preinit/79_move_config" 41 | cp -r "$(currentdir)/src/tools/gptfdisk" "tools/" 42 | cp -r "$(currentdir)/src/tools/popt" "tools" 43 | echo "pre-21.02.0" > ".UEFIDone" 44 | echo "Done." 45 | else 46 | echo "Already Patched." 47 | fi 48 | } 49 | 50 | update() { 51 | echo "###### Updating Patches ######" 52 | cd "$(currentdir)" 53 | git pull 54 | cd .. 55 | 56 | } 57 | 58 | generate_patch() { 59 | echo "###### Generating Patches ######" 60 | diff -Naur config/Config-images.in $(currentdir)/src/config/Config-images.in > $(currentdir)/Config-images.patch 61 | diff -Naur package/base-files/files/lib/upgrade/common.sh $(currentdir)/src/package/base-files/files/lib/upgrade/common.sh > $(currentdir)/common.patch 62 | diff -Naur target/linux/x86/base-files/lib/upgrade/platform.sh $(currentdir)/src/target/linux/x86/base-files/lib/upgrade/platform.sh > $(currentdir)/platform.patch 63 | # diff -Naur package/boot/grub2/Makefile $(currentdir)/src/package/boot/grub2/Makefile > $(currentdir)/Grub-Makefile.patch 64 | diff -Naur tools/Makefile $(currentdir)/src/tools/Makefile > $(currentdir)/tools.patch 65 | diff -Naur target/linux/x86/image/Makefile $(currentdir)/src/target/linux/x86/image/Makefile > $(currentdir)/Image.patch 66 | } 67 | 68 | currentdir() { 69 | SOURCE="$0" 70 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 71 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 72 | SOURCE="$(readlink "$SOURCE")" 73 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located 74 | done 75 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 76 | echo ${DIR##*/} 2>/dev/null 77 | } 78 | 79 | case "$1" in 80 | "apply") 81 | apply_patch 82 | ;; 83 | "restore") 84 | restore_patch 85 | ;; 86 | "generate") 87 | generate_patch 88 | ;; 89 | "update") 90 | restore_patch 91 | update 92 | apply_patch 93 | ;; 94 | *) 95 | echo "Please add parameter. Apply or Restore\n e.g: ./$(currentdir)/RunMe.sh apply" 96 | ;; 97 | esac 98 | -------------------------------------------------------------------------------- /src/package/boot/grub2/patches/100-grub_setup_root.patch: -------------------------------------------------------------------------------- 1 | --- a/util/grub-setup.c 2 | +++ b/util/grub-setup.c 3 | @@ -87,6 +87,8 @@ static struct argp_option options[] = { 4 | N_("install even if problems are detected"), 0}, 5 | {"skip-fs-probe",'s',0, 0, 6 | N_("do not probe for filesystems in DEVICE"), 0}, 7 | + {"root-device", 'r', N_("DEVICE"), 0, 8 | + N_("use DEVICE as the root device"), 0}, 9 | {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, 10 | {"allow-floppy", 'a', 0, 0, 11 | /* TRANSLATORS: The potential breakage isn't limited to floppies but it's 12 | @@ -130,6 +132,7 @@ struct arguments 13 | char *core_file; 14 | char *dir; 15 | char *dev_map; 16 | + char *root_dev; 17 | int force; 18 | int fs_probe; 19 | int allow_floppy; 20 | @@ -178,6 +181,13 @@ argp_parser (int key, char *arg, struct 21 | arguments->dev_map = xstrdup (arg); 22 | break; 23 | 24 | + case 'r': 25 | + if (arguments->root_dev) 26 | + free (arguments->root_dev); 27 | + 28 | + arguments->root_dev = xstrdup (arg); 29 | + break; 30 | + 31 | case 'f': 32 | arguments->force = 1; 33 | break; 34 | @@ -313,7 +323,7 @@ main (int argc, char *argv[]) 35 | GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY, 36 | arguments.boot_file ? : DEFAULT_BOOT_FILE, 37 | arguments.core_file ? : DEFAULT_CORE_FILE, 38 | - dest_dev, arguments.force, 39 | + arguments.root_dev, dest_dev, arguments.force, 40 | arguments.fs_probe, arguments.allow_floppy, 41 | arguments.add_rs_codes); 42 | 43 | --- a/util/setup.c 44 | +++ b/util/setup.c 45 | @@ -252,13 +252,12 @@ identify_partmap (grub_disk_t disk __att 46 | void 47 | SETUP (const char *dir, 48 | const char *boot_file, const char *core_file, 49 | - const char *dest, int force, 50 | + const char *root, const char *dest, int force, 51 | int fs_probe, int allow_floppy, 52 | int add_rs_codes __attribute__ ((unused))) /* unused on sparc64 */ 53 | { 54 | char *core_path; 55 | char *boot_img, *core_img, *boot_path; 56 | - char *root = 0; 57 | size_t boot_size, core_size; 58 | grub_uint16_t core_sectors; 59 | grub_device_t root_dev = 0, dest_dev, core_dev; 60 | @@ -307,7 +306,10 @@ SETUP (const char *dir, 61 | 62 | core_dev = dest_dev; 63 | 64 | - { 65 | + if (root) 66 | + root_dev = grub_device_open(root); 67 | + 68 | + if (!root_dev) { 69 | char **root_devices = grub_guess_root_devices (dir); 70 | char **cur; 71 | int found = 0; 72 | @@ -320,6 +322,8 @@ SETUP (const char *dir, 73 | char *drive; 74 | grub_device_t try_dev; 75 | 76 | + if (root_dev) 77 | + break; 78 | drive = grub_util_get_grub_dev (*cur); 79 | if (!drive) 80 | continue; 81 | --- a/include/grub/util/install.h 82 | +++ b/include/grub/util/install.h 83 | @@ -191,13 +191,13 @@ grub_install_get_image_target (const cha 84 | void 85 | grub_util_bios_setup (const char *dir, 86 | const char *boot_file, const char *core_file, 87 | - const char *dest, int force, 88 | + const char *root, const char *dest, int force, 89 | int fs_probe, int allow_floppy, 90 | int add_rs_codes); 91 | void 92 | grub_util_sparc_setup (const char *dir, 93 | const char *boot_file, const char *core_file, 94 | - const char *dest, int force, 95 | + const char *root, const char *dest, int force, 96 | int fs_probe, int allow_floppy, 97 | int add_rs_codes); 98 | 99 | --- a/util/grub-install.c 100 | +++ b/util/grub-install.c 101 | @@ -1712,7 +1712,7 @@ main (int argc, char *argv[]) 102 | /* Now perform the installation. */ 103 | if (install_bootsector) 104 | grub_util_bios_setup (platdir, "boot.img", "core.img", 105 | - install_drive, force, 106 | + NULL, install_drive, force, 107 | fs_probe, allow_floppy, add_rs_codes); 108 | break; 109 | } 110 | @@ -1738,7 +1738,7 @@ main (int argc, char *argv[]) 111 | /* Now perform the installation. */ 112 | if (install_bootsector) 113 | grub_util_sparc_setup (platdir, "boot.img", "core.img", 114 | - install_drive, force, 115 | + NULL, install_drive, force, 116 | fs_probe, allow_floppy, 117 | 0 /* unused */ ); 118 | break; 119 | -------------------------------------------------------------------------------- /Image.patch: -------------------------------------------------------------------------------- 1 | --- target/linux/x86/image/Makefile 2021-10-19 21:25:59.853341069 +0800 2 | +++ OpenWrt-UEFI-Support/src/target/linux/x86/image/Makefile 2021-10-19 21:18:41.000000000 +0800 3 | @@ -1,4 +1,4 @@ 4 | -# 5 | +# 6 | # Copyright (C) 2006-2012 OpenWrt.org 7 | # 8 | # This is free software, licensed under the GNU General Public License v2. 9 | @@ -41,36 +41,81 @@ 10 | endif 11 | 12 | SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))') 13 | +EFI_SIGNATURE:=$(strip $(shell uuidgen | sed "s/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]$$/0002/" | tr '[a-z]' '[A-Z]')) 14 | ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) 15 | ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02) 16 | +EFI_ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) 17 | +EFI_ROOTPART:=$(if $(EFI_ROOTPART),$(EFI_ROOTPART),PARTUUID=$(EFI_SIGNATURE)) 18 | 19 | GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT)) 20 | GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE)) 21 | 22 | -ifneq ($(CONFIG_GRUB_IMAGES),) 23 | +BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS)) 24 | 25 | - BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS)) 26 | +define Image/cmdline/ext4 27 | + root=$(ROOTPART) rootfstype=ext4 rootwait 28 | +endef 29 | 30 | - define Image/cmdline/ext4 31 | - root=$(ROOTPART) rootfstype=ext4 rootwait 32 | - endef 33 | +define Image/cmdline/squashfs 34 | + root=$(ROOTPART) rootfstype=squashfs rootwait 35 | +endef 36 | 37 | - define Image/cmdline/squashfs 38 | - root=$(ROOTPART) rootfstype=squashfs rootwait 39 | - endef 40 | +# UEFI Start 41 | +ifneq ($(CONFIG_EFI_IMAGES),) 42 | + 43 | +define Image/cmdline/efi 44 | + $(subst $(SIGNATURE)-02,$2,$(call Image/cmdline/$(1))) 45 | +endef 46 | +define Image/Build/efi 47 | + # Build the efi grub version 48 | + rm -rf $(KDIR)/grub2.efi/ || true 49 | + $(INSTALL_DIR) $(KDIR)/grub2.efi/efi/boot/ 50 | + 51 | + # Copy the EFI grub binary 52 | + $(CP) $(STAGING_DIR_IMAGE)/grub2/boot$(if $(CONFIG_x86_64),x64,ia32).efi $(KDIR)/grub2.efi/efi/boot/ 53 | + 54 | + $(INSTALL_DIR) $(KDIR)/grub2.efi/boot/grub $(KDIR)/grub2 55 | + $(CP) $(KDIR)/bzImage $(KDIR)/grub2.efi/boot/vmlinuz 56 | + echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img' > $(KDIR)/grub2/device.map 57 | + sed \ 58 | + -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 59 | + -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 60 | + -e 's#@GPT_ROOTPART@#$(call Image/cmdline/efi,$(1),$(EFI_SIGNATURE))#g' \ 61 | + -e 's#@CMDLINE@#$(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE)#g' \ 62 | + -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 63 | + -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 64 | + ./grub-efi.cfg > $(KDIR)/grub2.efi/boot/grub/grub.cfg 65 | + 66 | + SIGNATURE="$(EFI_SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_efi.sh \ 67 | + $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 68 | + $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/grub2.efi \ 69 | + $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ 70 | + 256 71 | 72 | - define Image/Build/grub2 73 | + # Convert the MBR partition to GPT and set EFI ROOTFS signature 74 | + dd if=/dev/zero of="$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" bs=512 count=34 conv=notrunc oflag=append 75 | + sgdisk -g "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 76 | + sgdisk -t 1:EF00 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 77 | + sgdisk -u 2:$(EFI_SIGNATURE) "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 78 | + 79 | + echo -e -n "\xeb\x63\x99" | dd of="$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" bs=4 conv=notrunc 80 | + 81 | +endef 82 | +endif 83 | + 84 | +ifneq ($(CONFIG_GRUB_IMAGES),) 85 | +define Image/Build/grub2 86 | # left here because the image builder doesnt need these 87 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 88 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 89 | grub-mkimage \ 90 | -p /boot/grub \ 91 | - -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \ 92 | + -d $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core \ 93 | -o $(KDIR)/grub2/core.img \ 94 | -O i386-pc \ 95 | -c ./grub-early.cfg \ 96 | $(GRUB2_MODULES) 97 | - $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/ 98 | + $(CP) $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core/*.img $(KDIR)/grub2/ 99 | echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map 100 | sed \ 101 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 102 | @@ -90,7 +135,7 @@ 103 | -d "$(KDIR)/grub2" \ 104 | -r "hd0,msdos1" \ 105 | "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img" 106 | - endef 107 | +endef 108 | endif 109 | 110 | define Image/Build/squashfs 111 | @@ -102,13 +147,13 @@ 112 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 113 | grub-mkimage \ 114 | -p /boot/grub \ 115 | - -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \ 116 | + -d $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core \ 117 | -o $(KDIR)/grub2/eltorito.img \ 118 | -O i386-pc \ 119 | -c ./grub-early.cfg \ 120 | $(GRUB2_MODULES_ISO) 121 | cat \ 122 | - $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \ 123 | + $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core/cdboot.img \ 124 | $(KDIR)/grub2/eltorito.img \ 125 | > $(KDIR)/root.grub/boot/grub/eltorito.img 126 | sed \ 127 | @@ -130,6 +175,12 @@ 128 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ 129 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi 130 | endef 131 | + define Image/Build/vdi_efi 132 | + rm $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vdi || true 133 | + qemu-img convert -f raw -O vdi \ 134 | + $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 135 | + $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vdi 136 | + endef 137 | endif 138 | 139 | ifneq ($(CONFIG_VMDK_IMAGES),) 140 | @@ -139,11 +190,22 @@ 141 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ 142 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk 143 | endef 144 | + define Image/Build/vmdk_efi 145 | + rm $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vmdk || true 146 | + qemu-img convert -f raw -O vmdk \ 147 | + $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 148 | + $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vmdk 149 | + endef 150 | endif 151 | 152 | define Image/Build/gzip 153 | - gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img 154 | gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img 155 | +ifneq ($(CONFIG_GRUB_IMAGES),) 156 | + gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img 157 | +endif 158 | +ifneq ($(CONFIG_EFI_IMAGES),) 159 | + gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img 160 | +endif 161 | endef 162 | 163 | ifneq ($(CONFIG_TARGET_IMAGES_GZIP),) 164 | @@ -170,9 +232,16 @@ 165 | define Image/Build 166 | $(call Image/Build/$(1)) 167 | ifneq ($(1),iso) 168 | + ifneq ($(CONFIG_GRUB_IMAGES),) 169 | $(call Image/Build/grub2,$(1)) 170 | $(call Image/Build/vdi,$(1)) 171 | $(call Image/Build/vmdk,$(1)) 172 | + endif 173 | + ifneq ($(CONFIG_EFI_IMAGES),) 174 | + $(call Image/Build/efi,$(1)) 175 | + $(call Image/Build/vdi_efi,$(1)) 176 | + $(call Image/Build/vmdk_efi,$(1)) 177 | + endif 178 | $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img 179 | else 180 | $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso 181 | -------------------------------------------------------------------------------- /src/tools/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2006-2011 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | # Main makefile for the host tools 8 | # 9 | curdir:=tools 10 | 11 | # subdirectories to descend into 12 | tools-y := 13 | 14 | ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) 15 | BUILD_TOOLCHAIN := y 16 | ifdef CONFIG_GCC_USE_GRAPHITE 17 | BUILD_ISL = y 18 | endif 19 | endif 20 | ifneq ($(CONFIG_SDK)$(CONFIG_PACKAGE_kmod-b43)$(CONFIG_PACKAGE_b43legacy-firmware)$(CONFIG_BRCMSMAC_USE_FW_FROM_WL),) 21 | BUILD_B43_TOOLS = y 22 | endif 23 | 24 | tools-$(BUILD_TOOLCHAIN) += gmp mpfr mpc libelf expat 25 | tools-y += m4 libtool autoconf automake flex bison pkg-config mklibs zlib 26 | tools-y += sstrip make-ext4fs e2fsprogs mtd-utils mkimage 27 | tools-y += firmware-utils patch-image quilt padjffs2 28 | tools-y += mm-macros missing-macros cmake scons bc findutils gengetopt patchelf 29 | tools-y += mtools dosfstools libressl 30 | tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2 31 | tools-$(CONFIG_TARGET_x86) += qemu 32 | tools-$(CONFIG_EFI_IMAGES) += gptfdisk popt 33 | tools-$(CONFIG_TARGET_mxs) += elftosb sdimage 34 | tools-$(CONFIG_TARGET_ar71xx) += lzma-old 35 | tools-$(CONFIG_TARGET_ar71xx)$(CONFIG_TARGET_ath79) += squashfs 36 | tools-$(CONFIG_USES_MINOR) += kernel2minor 37 | tools-y += lzma squashfskit4 zip 38 | tools-$(BUILD_B43_TOOLS) += b43-tools 39 | tools-$(BUILD_ISL) += isl 40 | tools-$(CONFIG_USE_SPARSE) += sparse 41 | tools-$(CONFIG_TARGET_apm821xx)$(CONFIG_TARGET_gemini) += genext2fs 42 | tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs 43 | 44 | # builddir dependencies 45 | $(curdir)/bison/compile := $(curdir)/flex/compile 46 | $(curdir)/flex/compile := $(curdir)/libtool/compile 47 | $(curdir)/libtool/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/automake/compile $(curdir)/missing-macros/compile 48 | $(curdir)/squashfs/compile := $(curdir)/lzma-old/compile 49 | $(curdir)/squashfskit4/compile := $(curdir)/xz/compile $(curdir)/zlib/compile 50 | $(curdir)/quilt/compile := $(curdir)/autoconf/compile $(curdir)/findutils/compile 51 | $(curdir)/autoconf/compile := $(curdir)/m4/compile 52 | $(curdir)/automake/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/pkg-config/compile $(curdir)/xz/compile 53 | $(curdir)/gmp/compile := $(curdir)/libtool/compile 54 | $(curdir)/mpc/compile := $(curdir)/mpfr/compile $(curdir)/gmp/compile 55 | $(curdir)/mpfr/compile := $(curdir)/gmp/compile 56 | $(curdir)/mtd-utils/compile := $(curdir)/libtool/compile $(curdir)/e2fsprogs/compile $(curdir)/zlib/compile 57 | $(curdir)/mklibs/compile := $(curdir)/libtool/compile 58 | $(curdir)/qemu/compile := $(curdir)/e2fsprogs/compile $(curdir)/zlib/compile 59 | $(curdir)/upslug2/compile := $(curdir)/libtool/compile 60 | $(curdir)/mm-macros/compile := $(curdir)/libtool/compile 61 | $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile 62 | $(curdir)/e2fsprogs/compile := $(curdir)/libtool/compile 63 | $(curdir)/libelf/compile := $(curdir)/libtool/compile 64 | $(curdir)/sdcc/compile := $(curdir)/bison/compile 65 | $(curdir)/b43-tools/compile := $(curdir)/bison/compile 66 | $(curdir)/padjffs2/compile := $(curdir)/findutils/compile 67 | $(curdir)/isl/compile := $(curdir)/gmp/compile 68 | $(curdir)/bc/compile := $(curdir)/bison/compile 69 | $(curdir)/findutils/compile := $(curdir)/bison/compile 70 | $(curdir)/gengetopt/compile := $(curdir)/libtool/compile 71 | $(curdir)/patchelf/compile := $(curdir)/libtool/compile 72 | $(curdir)/dosfstools/compile := $(curdir)/autoconf/compile $(curdir)/automake/compile 73 | $(curdir)/libressl/compile := $(curdir)/pkg-config/compile 74 | $(curdir)/mkimage/compile += $(curdir)/libressl/compile 75 | $(curdir)/firmware-utils/compile += $(curdir)/libressl/compile $(curdir)/zlib/compile 76 | $(curdir)/cmake/compile += $(curdir)/libressl/compile 77 | $(curdir)/zlib/compile := $(curdir)/cmake/compile 78 | $(curdir)/wrt350nv2-builder/compile := $(curdir)/zlib/compile 79 | $(curdir)/lzma-old/compile := $(curdir)/zlib/compile 80 | $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile 81 | $(curdir)/cbootimage/compile += $(curdir)/automake/compile 82 | $(curdir)/gptfdisk/compile += $(curdir)/e2fsprogs/compile $(curdir)/popt/compile 83 | 84 | ifneq ($(HOST_OS),Linux) 85 | $(curdir)/squashfskit4/compile += $(curdir)/coreutils/compile 86 | tools-y += coreutils 87 | endif 88 | 89 | ifneq ($(CONFIG_CCACHE)$(CONFIG_SDK),) 90 | $(foreach tool, $(filter-out xz patch,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/compile)) 91 | tools-y += ccache 92 | endif 93 | 94 | # in case there is no patch tool on the host we need to make patch tool a 95 | # dependency for tools which have patches directory 96 | $(foreach tool, $(tools-y), $(if $(wildcard $(curdir)/$(tool)/patches),$(eval $(curdir)/$(tool)/compile += $(curdir)/patch/compile))) 97 | 98 | $(foreach tool, $(filter-out xz,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/xz/compile)) 99 | 100 | # make any tool depend on tar, xz and patch to ensure that archives can be unpacked and patched properly 101 | tools-core := tar xz patch 102 | 103 | $(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(patsubst %,$(curdir)/%/compile,$(tools-core)))) 104 | tools-y += $(tools-core) 105 | 106 | # make core tools depend on sed and flock 107 | $(foreach tool, $(filter-out xz,$(tools-core)), $(eval $(curdir)/$(tool)/compile += $(curdir)/sed/compile)) 108 | $(curdir)/xz/compile += $(curdir)/flock/compile 109 | 110 | $(curdir)/sed/compile := $(curdir)/flock/compile $(curdir)/xz/compile 111 | tools-y += flock sed 112 | 113 | $(curdir)/autoremove := 1 114 | $(curdir)/builddirs := $(tools-y) $(tools-dep) $(tools-) 115 | $(curdir)/builddirs-default := $(tools-y) 116 | 117 | ifdef CHECK_ALL 118 | $(curdir)/builddirs-check:=$($(curdir)/builddirs) 119 | $(curdir)/builddirs-download:=$($(curdir)/builddirs) 120 | endif 121 | 122 | ifndef DUMP_TARGET_DB 123 | define PrepareStaging 124 | @for dir in $(1); do ( \ 125 | $(if $(QUIET),,set -x;) \ 126 | mkdir -p "$$dir"; \ 127 | cd "$$dir"; \ 128 | mkdir -p bin lib include stamp usr/include usr/lib; \ 129 | ); done 130 | endef 131 | 132 | # preparatory work 133 | $(STAGING_DIR)/.prepared: $(TMP_DIR)/.build 134 | $(call PrepareStaging,$(STAGING_DIR)) 135 | mkdir -p $(BUILD_DIR)/stamp 136 | touch $@ 137 | 138 | $(STAGING_DIR_HOST)/.prepared: $(TMP_DIR)/.build 139 | $(call PrepareStaging,$(STAGING_DIR_HOST)) 140 | mkdir -p $(BUILD_DIR_HOST)/stamp $(STAGING_DIR_HOST)/include/sys 141 | $(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/ 142 | $(INSTALL_DATA) $(TOPDIR)/tools/include/sys/*.h $(STAGING_DIR_HOST)/include/sys/ 143 | ln -sf lib $(STAGING_DIR_HOST)/lib64 144 | touch $@ 145 | 146 | endif 147 | 148 | $(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared 149 | $(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared 150 | 151 | # prerequisites for the individual targets 152 | $(curdir)/ := .config prereq 153 | 154 | $(curdir)/install: $(curdir)/compile 155 | 156 | tools_enabled = $(foreach tool,$(sort $(tools-y) $(tools-)),$(if $(filter $(tool),$(tools-y)),y,n)) 157 | $(eval $(call stampfile,$(curdir),tools,compile,,_$(subst $(space),,$(tools_enabled)))) 158 | $(eval $(call stampfile,$(curdir),tools,check,$(TMP_DIR)/.build)) 159 | $(eval $(call subdir,$(curdir))) 160 | -------------------------------------------------------------------------------- /src/package/base-files/files/lib/upgrade/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RAM_ROOT=/tmp/root 4 | 5 | export BACKUP_FILE=sysupgrade.tgz # file extracted by preinit 6 | 7 | [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } 8 | libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; } 9 | 10 | install_file() { # [ ... ] 11 | local target dest dir 12 | for file in "$@"; do 13 | if [ -L "$file" ]; then 14 | target="$(readlink -f "$file")" 15 | dest="$RAM_ROOT/$file" 16 | [ ! -f "$dest" ] && { 17 | dir="$(dirname "$dest")" 18 | mkdir -p "$dir" 19 | ln -s "$target" "$dest" 20 | } 21 | file="$target" 22 | fi 23 | dest="$RAM_ROOT/$file" 24 | [ -f "$file" -a ! -f "$dest" ] && { 25 | dir="$(dirname "$dest")" 26 | mkdir -p "$dir" 27 | cp "$file" "$dest" 28 | } 29 | done 30 | } 31 | 32 | install_bin() { 33 | local src files 34 | src=$1 35 | files=$1 36 | [ -x "$src" ] && files="$src $(libs $src)" 37 | install_file $files 38 | } 39 | 40 | run_hooks() { 41 | local arg="$1"; shift 42 | for func in "$@"; do 43 | eval "$func $arg" 44 | done 45 | } 46 | 47 | ask_bool() { 48 | local default="$1"; shift; 49 | local answer="$default" 50 | 51 | [ "$INTERACTIVE" -eq 1 ] && { 52 | case "$default" in 53 | 0) echo -n "$* (y/N): ";; 54 | *) echo -n "$* (Y/n): ";; 55 | esac 56 | read answer 57 | case "$answer" in 58 | y*) answer=1;; 59 | n*) answer=0;; 60 | *) answer="$default";; 61 | esac 62 | } 63 | [ "$answer" -gt 0 ] 64 | } 65 | 66 | v() { 67 | [ "$VERBOSE" -ge 1 ] && echo "$@" 68 | } 69 | 70 | json_string() { 71 | local v="$1" 72 | v="${v//\\/\\\\}" 73 | v="${v//\"/\\\"}" 74 | echo "\"$v\"" 75 | } 76 | 77 | rootfs_type() { 78 | /bin/mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }' 79 | } 80 | 81 | get_image() { # [ ] 82 | local from="$1" 83 | local cmd="$2" 84 | 85 | if [ -z "$cmd" ]; then 86 | local magic="$(dd if="$from" bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" 87 | case "$magic" in 88 | 1f8b) cmd="zcat";; 89 | 425a) cmd="bzcat";; 90 | *) cmd="cat";; 91 | esac 92 | fi 93 | 94 | cat "$from" 2>/dev/null | $cmd 95 | } 96 | 97 | get_magic_word() { 98 | (get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null 99 | } 100 | 101 | get_magic_long() { 102 | (get_image "$@" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null 103 | } 104 | 105 | get_magic_gpt() { 106 | (get_image "$@" | dd bs=8 count=1 skip=64) 2>/dev/null 107 | } 108 | 109 | get_magic_vfat() { 110 | (get_image "$@" | dd bs=3 count=1 skip=18) 2>/dev/null 111 | } 112 | 113 | get_magic_fat32() { 114 | (get_image "$@" | dd bs=1 count=5 skip=82) 2>/dev/null 115 | } 116 | 117 | part_magic_efi() { 118 | local magic=$(get_magic_gpt "$@") 119 | [ "$magic" = "EFI PART" ] 120 | } 121 | 122 | part_magic_fat() { 123 | local magic=$(get_magic_vfat "$@") 124 | local magic_fat32=$(get_magic_fat32 "$@") 125 | [ "$magic" = "FAT" ] || [ "$magic_fat32" = "FAT32" ] 126 | } 127 | 128 | export_bootdevice() { 129 | local cmdline bootdisk rootpart uuid blockdev uevent line class 130 | local MAJOR MINOR DEVNAME DEVTYPE 131 | 132 | if read cmdline < /proc/cmdline; then 133 | case "$cmdline" in 134 | *block2mtd=*) 135 | bootdisk="${cmdline##*block2mtd=}" 136 | bootdisk="${bootdisk%%,*}" 137 | ;; 138 | *root=*) 139 | rootpart="${cmdline##*root=}" 140 | rootpart="${rootpart%% *}" 141 | ;; 142 | esac 143 | 144 | case "$bootdisk" in 145 | /dev/*) 146 | uevent="/sys/class/block/${bootdisk##*/}/uevent" 147 | ;; 148 | esac 149 | 150 | case "$rootpart" in 151 | PARTUUID=????????-????-????-????-????????0002) 152 | uuid="${rootpart#PARTUUID=}" 153 | for blockdev in $(find /dev -type b); do 154 | set -- $(dd if=$blockdev bs=1 skip=1168 count=16 2>/dev/null | hexdump -v -e '8/1 "%02X "" "2/1 "%02X""-"6/1 "%02X"') 155 | if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then 156 | blockdev=${blockdev##*/} 157 | uevent="/sys/class/block/${blockdev%[0-9]}/uevent" 158 | export UPGRADE_OPT_SAVE_PARTITIONS="0" 159 | break 160 | fi 161 | done 162 | 163 | ;; 164 | PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-[a-f0-9][a-f0-9]) 165 | uuid="${rootpart#PARTUUID=}" 166 | uuid="${uuid%-[a-f0-9][a-f0-9]}" 167 | for blockdev in $(find /dev -type b); do 168 | set -- $(dd if=$blockdev bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "') 169 | if [ "$4$3$2$1" = "$uuid" ]; then 170 | uevent="/sys/class/block/${blockdev##*/}/uevent" 171 | break 172 | fi 173 | done 174 | ;; 175 | /dev/*) 176 | uevent="/sys/class/block/${rootpart##*/}/../uevent" 177 | ;; 178 | 0x[a-f0-9][a-f0-9][a-f0-9] | 0x[a-f0-9][a-f0-9][a-f0-9][a-f0-9] | \ 179 | [a-f0-9][a-f0-9][a-f0-9] | [a-f0-9][a-f0-9][a-f0-9][a-f0-9]) 180 | rootpart=0x${rootpart#0x} 181 | for class in /sys/class/block/*; do 182 | while read line; do 183 | export -n "$line" 184 | done < "$class/uevent" 185 | if [ $((rootpart/256)) = $MAJOR -a $((rootpart%256)) = $MINOR ]; then 186 | uevent="$class/../uevent" 187 | fi 188 | done 189 | ;; 190 | esac 191 | 192 | if [ -e "$uevent" ]; then 193 | while read line; do 194 | export -n "$line" 195 | done < "$uevent" 196 | export BOOTDEV_MAJOR=$MAJOR 197 | export BOOTDEV_MINOR=$MINOR 198 | return 0 199 | fi 200 | fi 201 | 202 | return 1 203 | } 204 | 205 | export_partdevice() { 206 | local var="$1" offset="$2" 207 | local uevent line MAJOR MINOR DEVNAME DEVTYPE 208 | 209 | for uevent in /sys/class/block/*/uevent; do 210 | while read line; do 211 | export -n "$line" 212 | done < "$uevent" 213 | if [ $BOOTDEV_MAJOR = $MAJOR -a $(($BOOTDEV_MINOR + $offset)) = $MINOR -a -b "/dev/$DEVNAME" ]; then 214 | export "$var=$DEVNAME" 215 | return 0 216 | fi 217 | done 218 | 219 | return 1 220 | } 221 | 222 | hex_le32_to_cpu() { 223 | [ "$(echo 01 | hexdump -v -n 2 -e '/2 "%x"')" = "3031" ] && { 224 | echo "${1:0:2}${1:8:2}${1:6:2}${1:4:2}${1:2:2}" 225 | return 226 | } 227 | echo "$@" 228 | } 229 | 230 | get_partitions() { # 231 | local disk="$1" 232 | local filename="$2" 233 | 234 | if [ -b "$disk" -o -f "$disk" ]; then 235 | v "Reading partition table from $filename..." 236 | 237 | local magic=$(dd if="$disk" bs=2 count=1 skip=255 2>/dev/null) 238 | if [ "$magic" != $'\x55\xAA' ]; then 239 | v "Invalid partition table on $disk" 240 | exit 241 | fi 242 | 243 | rm -f "/tmp/partmap.$filename" 244 | 245 | local part 246 | for part in 1 2 3 4; do 247 | part_magic_efi "$disk" && { 248 | case $(hexdump -v -n 16 -s "$(( 0x380 + $part * 128 ))" -e '4/4 "%08X"' "$disk") in 249 | "0FC63DAF47728483693D798EE47D47D8") 250 | gptTypeID="0x00000083" 251 | ;; 252 | "C12A732811D2F81FA0004BBA3BC93EC9") 253 | gptTypeID="0x000000EE" 254 | ;; 255 | *) 256 | gptTypeID="0x00000000" 257 | ;; 258 | esac 259 | 260 | gptLBA=$(hexdump -v -n 4 -s $(( 0x3A0 + $part * 128 )) -e '1/4 "0x%08X"' "$disk") 261 | gptNUM=$(hexdump -v -n 4 -s $(( 0x3A8 + $part * 128 )) -e '1/4 "0x%08X"' "$disk") 262 | set -- $gptTypeID $gptLBA $gptNUM 263 | } || { 264 | set -- $(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk") 265 | } 266 | 267 | local type="$(( $(hex_le32_to_cpu $1) % 256))" 268 | local lba="$(( $(hex_le32_to_cpu $2) ))" 269 | local num="$(( $(hex_le32_to_cpu $3) ))" 270 | 271 | [ $type -gt 0 ] || continue 272 | 273 | printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename" 274 | done 275 | fi 276 | } 277 | 278 | indicate_upgrade() { 279 | . /etc/diag.sh 280 | set_state upgrade 281 | } 282 | 283 | # Flash firmware to MTD partition 284 | # 285 | # $(1): path to image 286 | # $(2): (optional) pipe command to extract firmware, e.g. dd bs=n skip=m 287 | default_do_upgrade() { 288 | sync 289 | if [ -n "$UPGRADE_BACKUP" ]; then 290 | get_image "$1" "$2" | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j "$UPGRADE_BACKUP" write - "${PART_NAME:-image}" 291 | else 292 | get_image "$1" "$2" | mtd $MTD_ARGS write - "${PART_NAME:-image}" 293 | fi 294 | [ $? -ne 0 ] && exit 1 295 | } 296 | -------------------------------------------------------------------------------- /src/config/Config-images.in: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2006-2013 OpenWrt.org 2 | # 3 | # This is free software, licensed under the GNU General Public License v2. 4 | # See /LICENSE for more information. 5 | # 6 | 7 | menu "Target Images" 8 | 9 | menuconfig TARGET_ROOTFS_INITRAMFS 10 | bool "ramdisk" 11 | default y if USES_INITRAMFS 12 | help 13 | Embed the root filesystem into the kernel (initramfs). 14 | 15 | choice 16 | prompt "Compression" 17 | default TARGET_INITRAMFS_COMPRESSION_LZMA if TARGET_apm821xx 18 | default TARGET_INITRAMFS_COMPRESSION_LZMA if TARGET_ar71xx 19 | default TARGET_INITRAMFS_COMPRESSION_LZMA if TARGET_lantiq 20 | default TARGET_INITRAMFS_COMPRESSION_LZMA if TARGET_mpc85xx 21 | default TARGET_INITRAMFS_COMPRESSION_LZMA if TARGET_ramips 22 | default TARGET_INITRAMFS_COMPRESSION_NONE 23 | depends on TARGET_ROOTFS_INITRAMFS 24 | help 25 | Select ramdisk compression. 26 | 27 | config TARGET_INITRAMFS_COMPRESSION_NONE 28 | bool "none" 29 | 30 | config TARGET_INITRAMFS_COMPRESSION_GZIP 31 | bool "gzip" 32 | 33 | config TARGET_INITRAMFS_COMPRESSION_BZIP2 34 | bool "bzip2" 35 | 36 | config TARGET_INITRAMFS_COMPRESSION_LZMA 37 | bool "lzma" 38 | 39 | config TARGET_INITRAMFS_COMPRESSION_LZO 40 | bool "lzo" 41 | 42 | config TARGET_INITRAMFS_COMPRESSION_LZ4 43 | bool "lz4" 44 | 45 | config TARGET_INITRAMFS_COMPRESSION_XZ 46 | bool "xz" 47 | endchoice 48 | 49 | config EXTERNAL_CPIO 50 | string 51 | prompt "Use external cpio" if TARGET_ROOTFS_INITRAMFS 52 | default "" 53 | help 54 | Kernel uses specified external cpio as INITRAMFS_SOURCE. 55 | 56 | config TARGET_INITRAMFS_FORCE 57 | bool "Force" 58 | depends on TARGET_ROOTFS_INITRAMFS 59 | default n 60 | help 61 | Ignore the initramfs passed by the bootloader. 62 | 63 | comment "Root filesystem archives" 64 | 65 | config TARGET_ROOTFS_CPIOGZ 66 | bool "cpio.gz" 67 | default y if USES_CPIOGZ 68 | help 69 | Build a compressed cpio archive of the root filesystem. 70 | 71 | config TARGET_ROOTFS_TARGZ 72 | bool "tar.gz" 73 | default y if USES_TARGZ 74 | help 75 | Build a compressed tar archive of the root filesystem. 76 | 77 | comment "Root filesystem images" 78 | 79 | menuconfig TARGET_ROOTFS_EXT4FS 80 | bool "ext4" 81 | default y if USES_EXT4 82 | help 83 | Build an ext4 root filesystem. 84 | 85 | config TARGET_EXT4_RESERVED_PCT 86 | int "Percentage of reserved blocks in root filesystem" 87 | depends on TARGET_ROOTFS_EXT4FS 88 | default 0 89 | help 90 | Select the percentage of reserved blocks in the root filesystem. 91 | 92 | choice 93 | prompt "Root filesystem block size" 94 | default TARGET_EXT4_BLOCKSIZE_4K 95 | depends on TARGET_ROOTFS_EXT4FS 96 | help 97 | Select the block size of the root filesystem. 98 | 99 | config TARGET_EXT4_BLOCKSIZE_4K 100 | bool "4k" 101 | 102 | config TARGET_EXT4_BLOCKSIZE_2K 103 | bool "2k" 104 | 105 | config TARGET_EXT4_BLOCKSIZE_1K 106 | bool "1k" 107 | endchoice 108 | 109 | config TARGET_EXT4_BLOCKSIZE 110 | int 111 | default 4096 if TARGET_EXT4_BLOCKSIZE_4K 112 | default 2048 if TARGET_EXT4_BLOCKSIZE_2K 113 | default 1024 if TARGET_EXT4_BLOCKSIZE_1K 114 | depends on TARGET_ROOTFS_EXT4FS 115 | 116 | config TARGET_EXT4_JOURNAL 117 | bool "Create a journaling filesystem" 118 | depends on TARGET_ROOTFS_EXT4FS 119 | default n 120 | help 121 | Create an ext4 filesystem with a journal. 122 | 123 | config TARGET_ROOTFS_ISO 124 | bool "iso" 125 | default n 126 | depends on TARGET_x86_generic 127 | help 128 | Create a bootable ISO image. 129 | 130 | config TARGET_ROOTFS_JFFS2 131 | bool "jffs2" 132 | depends on USES_JFFS2 133 | help 134 | Build a JFFS2 root filesystem. 135 | 136 | config TARGET_ROOTFS_JFFS2_NAND 137 | bool "jffs2 for NAND" 138 | default y if USES_JFFS2_NAND 139 | depends on USES_JFFS2_NAND 140 | help 141 | Build a JFFS2 root filesystem for NAND flash. 142 | 143 | menuconfig TARGET_ROOTFS_SQUASHFS 144 | bool "squashfs" 145 | default y if USES_SQUASHFS 146 | help 147 | Build a squashfs-lzma root filesystem. 148 | 149 | config TARGET_SQUASHFS_BLOCK_SIZE 150 | int "Block size (in KiB)" 151 | depends on TARGET_ROOTFS_SQUASHFS 152 | default 64 if LOW_MEMORY_FOOTPRINT 153 | default 1024 if (SMALL_FLASH && !LOW_MEMORY_FOOTPRINT) 154 | default 256 155 | 156 | menuconfig TARGET_ROOTFS_UBIFS 157 | bool "ubifs" 158 | default y if USES_UBIFS 159 | depends on USES_UBIFS 160 | help 161 | Build a UBIFS root filesystem. 162 | 163 | choice 164 | prompt "compression" 165 | default TARGET_UBIFS_COMPRESSION_ZLIB 166 | depends on TARGET_ROOTFS_UBIFS 167 | help 168 | Select compression type 169 | 170 | config TARGET_UBIFS_COMPRESSION_NONE 171 | bool "none" 172 | 173 | config TARGET_UBIFS_COMPRESSION_LZO 174 | bool "lzo" 175 | 176 | config TARGET_UBIFS_COMPRESSION_ZLIB 177 | bool "zlib" 178 | endchoice 179 | 180 | config TARGET_UBIFS_FREE_SPACE_FIXUP 181 | bool "free space fixup" if TARGET_ROOTFS_UBIFS 182 | default y 183 | help 184 | The filesystem free space has to be fixed up on first mount. 185 | 186 | config TARGET_UBIFS_JOURNAL_SIZE 187 | string 188 | prompt "journal size" if TARGET_ROOTFS_UBIFS 189 | default "" 190 | 191 | config GRUB_IMAGES 192 | bool "Build GRUB images (Linux x86 or x86_64 host only)" 193 | depends on TARGET_x86 194 | depends on TARGET_ROOTFS_EXT4FS || TARGET_ROOTFS_ISO || TARGET_ROOTFS_JFFS2 || TARGET_ROOTFS_SQUASHFS 195 | select PACKAGE_grub2 196 | default n 197 | 198 | config EFI_IMAGES 199 | bool "Build EFI GRUB images (Linux x86 or x86_64 host only)" 200 | depends on TARGET_x86 201 | depends on TARGET_ROOTFS_EXT4FS || TARGET_ROOTFS_ISO || TARGET_ROOTFS_JFFS2 || TARGET_ROOTFS_SQUASHFS 202 | select PACKAGE_grub2-efi 203 | select PACKAGE_kmod-fs-vfat 204 | default y 205 | 206 | config GRUB_CONSOLE 207 | bool "Use Console Terminal (in addition to Serial)" 208 | depends on GRUB_IMAGES || EFI_IMAGES 209 | default y 210 | 211 | config GRUB_SERIAL 212 | string "Serial port device" 213 | depends on GRUB_IMAGES || EFI_IMAGES 214 | default "ttyS0" 215 | 216 | config GRUB_BAUDRATE 217 | int "Serial port baud rate" 218 | depends on GRUB_IMAGES || EFI_IMAGES 219 | default 38400 if TARGET_x86_generic 220 | default 115200 221 | 222 | config GRUB_FLOWCONTROL 223 | bool "Use RTE/CTS on serial console" 224 | depends on GRUB_SERIAL != "" 225 | default n 226 | 227 | config GRUB_BOOTOPTS 228 | string "Extra kernel boot options" 229 | depends on GRUB_IMAGES || EFI_IMAGES 230 | help 231 | If you don't know, just leave it blank. 232 | 233 | config GRUB_TIMEOUT 234 | string "Seconds to wait before booting the default entry" 235 | depends on GRUB_IMAGES || EFI_IMAGES 236 | default "5" 237 | help 238 | If you don't know, 5 seconds is a reasonable default. 239 | 240 | config GRUB_TITLE 241 | string "Title for the menu entry in GRUB" 242 | depends on GRUB_IMAGES || EFI_IMAGES 243 | default "OpenWrt" 244 | help 245 | This is the title of the GRUB menu entry. 246 | If unspecified, it defaults to OpenWrt. 247 | 248 | config VDI_IMAGES 249 | bool "Build VirtualBox image files (VDI)" 250 | depends on TARGET_x86 251 | select EFI_IMAGES 252 | select TARGET_IMAGES_PAD 253 | select PACKAGE_kmod-e1000 254 | 255 | config VMDK_IMAGES 256 | bool "Build VMware image files (VMDK)" 257 | depends on TARGET_x86 258 | select EFI_IMAGES 259 | select TARGET_IMAGES_PAD 260 | select PACKAGE_kmod-e1000 261 | 262 | config TARGET_IMAGES_PAD 263 | bool "Pad images to filesystem size (for JFFS2)" 264 | depends on GRUB_IMAGES 265 | 266 | config TARGET_IMAGES_GZIP 267 | bool "GZip images" 268 | depends on TARGET_IMAGES_PAD || TARGET_ROOTFS_EXT4FS || TARGET_x86 269 | default y 270 | 271 | comment "Image Options" 272 | 273 | source "target/linux/*/image/Config.in" 274 | 275 | config TARGET_KERNEL_PARTSIZE 276 | int "Kernel partition size (in MB)" 277 | depends on GRUB_IMAGES || EFI_IMAGES || USES_BOOT_PART 278 | default 8 if TARGET_apm821xx_sata 279 | default 20 if TARGET_brcm2708 280 | default 16 281 | 282 | config TARGET_ROOTFS_PARTSIZE 283 | int "Root filesystem partition size (in MB)" 284 | depends on GRUB_IMAGES || EFI_IMAGES || USES_ROOTFS_PART || TARGET_ROOTFS_EXT4FS || TARGET_omap || TARGET_rb532 || TARGET_sunxi || TARGET_uml 285 | default 256 286 | help 287 | Select the root filesystem partition size. 288 | 289 | config TARGET_ROOTFS_PARTNAME 290 | string "Root partition on target device" 291 | depends on GRUB_IMAGES || EFI_IMAGES 292 | help 293 | Override the root partition on the final device. If left empty, 294 | it will be mounted by PARTUUID which makes the kernel find the 295 | appropriate disk automatically. 296 | 297 | endmenu 298 | -------------------------------------------------------------------------------- /src/target/linux/x86/image/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2006-2012 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | include $(TOPDIR)/rules.mk 8 | include $(INCLUDE_DIR)/image.mk 9 | 10 | export PATH=$(TARGET_PATH):/sbin 11 | 12 | GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga 13 | GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga 14 | GRUB_TERMINALS = 15 | GRUB_SERIAL_CONFIG = 16 | GRUB_TERMINAL_CONFIG = 17 | GRUB_CONSOLE_CMDLINE = 18 | 19 | USE_ATKBD = generic 64 20 | 21 | ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),) 22 | GRUB2_MODULES += at_keyboard 23 | GRUB2_MODULES_ISO += at_keyboard 24 | endif 25 | 26 | ifneq ($(CONFIG_GRUB_CONSOLE),) 27 | GRUB_CONSOLE_CMDLINE += console=tty0 28 | GRUB_TERMINALS += console 29 | endif 30 | 31 | GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL)) 32 | 33 | ifneq ($(GRUB_SERIAL),) 34 | GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8$(if $(CONFIG_GRUB_FLOWCONTROL),r,) 35 | GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,off) 36 | GRUB_TERMINALS += serial 37 | endif 38 | 39 | ifneq ($(GRUB_TERMINALS),) 40 | GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS) 41 | endif 42 | 43 | SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))') 44 | EFI_SIGNATURE:=$(strip $(shell uuidgen | sed "s/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]$$/0002/" | tr '[a-z]' '[A-Z]')) 45 | ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) 46 | ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02) 47 | EFI_ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) 48 | EFI_ROOTPART:=$(if $(EFI_ROOTPART),$(EFI_ROOTPART),PARTUUID=$(EFI_SIGNATURE)) 49 | 50 | GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT)) 51 | GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE)) 52 | 53 | BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS)) 54 | 55 | define Image/cmdline/ext4 56 | root=$(ROOTPART) rootfstype=ext4 rootwait 57 | endef 58 | 59 | define Image/cmdline/squashfs 60 | root=$(ROOTPART) rootfstype=squashfs rootwait 61 | endef 62 | 63 | # UEFI Start 64 | ifneq ($(CONFIG_EFI_IMAGES),) 65 | 66 | define Image/cmdline/efi 67 | $(subst $(SIGNATURE)-02,$2,$(call Image/cmdline/$(1))) 68 | endef 69 | define Image/Build/efi 70 | # Build the efi grub version 71 | rm -rf $(KDIR)/grub2.efi/ || true 72 | $(INSTALL_DIR) $(KDIR)/grub2.efi/efi/boot/ 73 | 74 | # Copy the EFI grub binary 75 | $(CP) $(STAGING_DIR_IMAGE)/grub2/boot$(if $(CONFIG_x86_64),x64,ia32).efi $(KDIR)/grub2.efi/efi/boot/ 76 | 77 | $(INSTALL_DIR) $(KDIR)/grub2.efi/boot/grub $(KDIR)/grub2 78 | $(CP) $(KDIR)/bzImage $(KDIR)/grub2.efi/boot/vmlinuz 79 | echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img' > $(KDIR)/grub2/device.map 80 | sed \ 81 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 82 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 83 | -e 's#@GPT_ROOTPART@#$(call Image/cmdline/efi,$(1),$(EFI_SIGNATURE))#g' \ 84 | -e 's#@CMDLINE@#$(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE)#g' \ 85 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 86 | -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 87 | ./grub-efi.cfg > $(KDIR)/grub2.efi/boot/grub/grub.cfg 88 | 89 | SIGNATURE="$(EFI_SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_efi.sh \ 90 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 91 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/grub2.efi \ 92 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ 93 | 256 94 | 95 | # Convert the MBR partition to GPT and set EFI ROOTFS signature 96 | dd if=/dev/zero of="$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" bs=512 count=34 conv=notrunc oflag=append 97 | sgdisk -g "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 98 | sgdisk -t 1:EF00 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 99 | sgdisk -u 2:$(EFI_SIGNATURE) "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" 100 | 101 | echo -e -n "\xeb\x63\x99" | dd of="$(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img" bs=4 conv=notrunc 102 | 103 | endef 104 | endif 105 | 106 | ifneq ($(CONFIG_GRUB_IMAGES),) 107 | define Image/Build/grub2 108 | # left here because the image builder doesnt need these 109 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 110 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 111 | grub-mkimage \ 112 | -p /boot/grub \ 113 | -d $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core \ 114 | -o $(KDIR)/grub2/core.img \ 115 | -O i386-pc \ 116 | -c ./grub-early.cfg \ 117 | $(GRUB2_MODULES) 118 | $(CP) $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core/*.img $(KDIR)/grub2/ 119 | echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map 120 | sed \ 121 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 122 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 123 | -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ 124 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 125 | -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 126 | ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg 127 | -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/ 128 | PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \ 129 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ 130 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \ 131 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ 132 | 256 133 | grub-bios-setup \ 134 | --device-map="$(KDIR)/grub2/device.map" \ 135 | -d "$(KDIR)/grub2" \ 136 | -r "hd0,msdos1" \ 137 | "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img" 138 | endef 139 | endif 140 | 141 | define Image/Build/squashfs 142 | dd if=/dev/zero bs=128k count=1 >> $(KDIR)/root.squashfs 143 | endef 144 | 145 | define Image/Build/iso 146 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 147 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 148 | grub-mkimage \ 149 | -p /boot/grub \ 150 | -d $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core \ 151 | -o $(KDIR)/grub2/eltorito.img \ 152 | -O i386-pc \ 153 | -c ./grub-early.cfg \ 154 | $(GRUB2_MODULES_ISO) 155 | cat \ 156 | $(PKG_BUILD_DIR)/grub-pc/grub-2.04/grub-core/cdboot.img \ 157 | $(KDIR)/grub2/eltorito.img \ 158 | > $(KDIR)/root.grub/boot/grub/eltorito.img 159 | sed \ 160 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 161 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 162 | -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ 163 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 164 | -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 165 | ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg 166 | -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/ 167 | mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \ 168 | -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR) 169 | endef 170 | 171 | ifneq ($(CONFIG_VDI_IMAGES),) 172 | define Image/Build/vdi 173 | rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true 174 | qemu-img convert -f raw -O vdi \ 175 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ 176 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi 177 | endef 178 | define Image/Build/vdi_efi 179 | rm $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vdi || true 180 | qemu-img convert -f raw -O vdi \ 181 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 182 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vdi 183 | endef 184 | endif 185 | 186 | ifneq ($(CONFIG_VMDK_IMAGES),) 187 | define Image/Build/vmdk 188 | rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true 189 | qemu-img convert -f raw -O vmdk \ 190 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ 191 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk 192 | endef 193 | define Image/Build/vmdk_efi 194 | rm $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vmdk || true 195 | qemu-img convert -f raw -O vmdk \ 196 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img \ 197 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.vmdk 198 | endef 199 | endif 200 | 201 | define Image/Build/gzip 202 | gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img 203 | ifneq ($(CONFIG_GRUB_IMAGES),) 204 | gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img 205 | endif 206 | ifneq ($(CONFIG_EFI_IMAGES),) 207 | gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-$(1)-combined-efi.img 208 | endif 209 | endef 210 | 211 | ifneq ($(CONFIG_TARGET_IMAGES_GZIP),) 212 | define Image/Build/gzip/ext4 213 | $(call Image/Build/gzip,ext4) 214 | endef 215 | define Image/Build/gzip/squashfs 216 | $(call Image/Build/gzip,squashfs) 217 | endef 218 | endif 219 | 220 | define Image/BuildKernel 221 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz 222 | endef 223 | 224 | define Image/Prepare 225 | $(call Image/Prepare/grub2) 226 | endef 227 | 228 | define Image/Build/Initramfs 229 | $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage 230 | endef 231 | 232 | define Image/Build 233 | $(call Image/Build/$(1)) 234 | ifneq ($(1),iso) 235 | ifneq ($(CONFIG_GRUB_IMAGES),) 236 | $(call Image/Build/grub2,$(1)) 237 | $(call Image/Build/vdi,$(1)) 238 | $(call Image/Build/vmdk,$(1)) 239 | endif 240 | ifneq ($(CONFIG_EFI_IMAGES),) 241 | $(call Image/Build/efi,$(1)) 242 | $(call Image/Build/vdi_efi,$(1)) 243 | $(call Image/Build/vmdk_efi,$(1)) 244 | endif 245 | $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img 246 | else 247 | $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso 248 | endif 249 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz 250 | $(call Image/Build/gzip/$(1)) 251 | ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) 252 | $(call Image/Build/Initramfs) 253 | endif 254 | endef 255 | 256 | $(eval $(call BuildImage)) 257 | -------------------------------------------------------------------------------- /src/target/linux/x86/image/Makefile-jow-version: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2006-2012 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | include $(TOPDIR)/rules.mk 8 | include $(INCLUDE_DIR)/image.mk 9 | 10 | export PATH=$(TARGET_PATH):/sbin 11 | 12 | GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga 13 | GRUB2_MODULES_LEGACY = $(GRUB2_MODULES) 14 | GRUB2_MODULES_LEGACY += part_gpt search fat exfat 15 | GRUB2_MODULES_EFI = boot chain configfile ext2 linux ls part_msdos reboot serial part_gpt part_msdos search fat exfat ext2 efi_gop efi_uga gfxterm 16 | GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga 17 | GRUB_TERMINALS = 18 | GRUB_SERIAL_CONFIG = 19 | GRUB_TERMINAL_CONFIG = 20 | GRUB_CONSOLE_CMDLINE = 21 | 22 | USE_ATKBD = generic 64 23 | 24 | ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),) 25 | GRUB2_MODULES += at_keyboard 26 | GRUB2_MODULES_ISO += at_keyboard 27 | endif 28 | 29 | ifneq ($(CONFIG_GRUB_CONSOLE),) 30 | GRUB_CONSOLE_CMDLINE += console=tty0 31 | GRUB_TERMINALS += console 32 | endif 33 | 34 | GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL)) 35 | 36 | ifneq ($(GRUB_SERIAL),) 37 | GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8$(if $(CONFIG_GRUB_FLOWCONTROL),r,) 38 | GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,off) 39 | GRUB_TERMINALS += serial 40 | endif 41 | 42 | ifneq ($(GRUB_TERMINALS),) 43 | GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS) 44 | endif 45 | 46 | SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))') 47 | EFI_SIGNATURE:=$(strip $(shell uuidgen | sed "s/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]$$/0002/" | tr '[a-z]' '[A-Z]')) 48 | ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) 49 | ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02) 50 | 51 | GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT)) 52 | GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE)) 53 | 54 | ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),) 55 | 56 | BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS)) 57 | 58 | define Image/cmdline/ext4 59 | root=$(ROOTPART) rootfstype=ext4 rootwait 60 | endef 61 | 62 | define Image/cmdline/squashfs 63 | root=$(ROOTPART) rootfstype=squashfs rootwait 64 | endef 65 | 66 | ifneq ($(CONFIG_EFI_IMAGES),) 67 | 68 | define Image/cmdline/efi 69 | $(subst $(SIGNATURE)-02,$2,$(call Image/cmdline/$(1))) 70 | endef 71 | 72 | define Image/Build/efi 73 | # left here because the image builder doesnt need these 74 | rm -rf $(KDIR)/root.grub/ || true 75 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 76 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 77 | echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img' > $(KDIR)/grub2/device.map 78 | sed \ 79 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 80 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 81 | -e 's#@CMDLINE@#$(strip $(call Image/cmdline/efi,$(1),$(EFI_SIGNATURE)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ 82 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 83 | -e 's#set root.*#search --file /boot/grub/$(SIGNATURE).cfg --set=root#g' \ 84 | ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg 85 | sed \ 86 | -e 's/(hd0,msdos1)/(hd0,gpt1)/' ./grub-early.cfg > \ 87 | $(KDIR)/root.grub/boot/grub/grub-early.cfg 88 | 89 | $(CP) $(KDIR)/root.grub/boot/grub/grub.cfg $(KDIR)/root.grub/boot/grub/$(SIGNATURE).cfg 90 | grub-mkimage \ 91 | -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \ 92 | -o $(KDIR)/grub2/core.img \ 93 | -O i386-pc \ 94 | -p '(hd0,gpt1)/boot/grub' \ 95 | -c $(KDIR)/root.grub/boot/grub/grub-early.cfg \ 96 | $(GRUB2_MODULES_LEGACY) 97 | $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/ 98 | 99 | # Build the efi grub version 100 | rm -rf $(KDIR)/grub2.efi/ || true 101 | $(INSTALL_DIR) $(KDIR)/grub2.efi/efi/boot/ 102 | 103 | # Generate the grub search root config (grub will search for the $(SIGNATURE).cfg file placed on the boot partition as grub does not support search of GPT UUID yet) 104 | echo "search --file /boot/grub/$(SIGNATURE).cfg --set=root" > $(KDIR)/grub2.efi/efi/boot/grub.cfg 105 | echo "configfile /boot/grub/grub.cfg" >> $(KDIR)/grub2.efi/efi/boot/grub.cfg 106 | 107 | # Create the EFI grub binary 108 | grub-mkimage-efi \ 109 | -d $(STAGING_DIR_HOST)/lib/grub/x86_64-efi \ 110 | -o $(KDIR)/grub2.efi/efi/boot/bootx64.efi \ 111 | -O x86_64-efi \ 112 | -p /efi/boot \ 113 | -c $(KDIR)/grub2.efi/efi/boot/grub.cfg \ 114 | $(GRUB2_MODULES_EFI) 115 | 116 | # Generate the EFI VFAT bootfs 117 | rm $(KDIR)/kernel.efi || true 118 | mkfs.fat -C $(KDIR)/kernel.efi -S 512 1024 119 | mcopy -s -i "$(KDIR)/kernel.efi" $(KDIR)/grub2.efi/* ::/ 120 | 121 | SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_efi.sh \ 122 | $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img \ 123 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \ 124 | 1 $(KDIR)/kernel.efi \ 125 | 1 \ 126 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ 127 | 256 128 | 129 | # Setup legacy bios for hybrid MBR (optional) 130 | grub-bios-setup \ 131 | --device-map="$(KDIR)/grub2/device.map" \ 132 | -d "$(KDIR)/grub2" \ 133 | -r "hd0,msdos1" \ 134 | "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 135 | 136 | # Convert the MBR partition to GPT and set EFI ROOTFS signature 137 | dd if=/dev/zero of="$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" bs=512 count=33 conv=notrunc oflag=append 138 | sgdisk -g "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 139 | sgdisk -t 2:EF00 "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 140 | sgdisk -t 3:EF02 "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 141 | sgdisk -u 4:$(EFI_SIGNATURE) "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 142 | sgdisk -h "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 143 | 144 | # Setup EFI grub 145 | grub-bios-setup-efi \ 146 | --device-map="$(KDIR)/grub2/device.map" \ 147 | -d "$(KDIR)/grub2" \ 148 | -r "hd0,gpt1" \ 149 | "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" 150 | endef 151 | endif 152 | 153 | ifneq ($(CONFIG_GRUB_IMAGES),) 154 | define Image/Build/grub2 155 | # left here because the image builder doesnt need these 156 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 157 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 158 | grub-mkimage \ 159 | -p /boot/grub \ 160 | -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \ 161 | -o $(KDIR)/grub2/core.img \ 162 | -O i386-pc \ 163 | -c ./grub-early.cfg \ 164 | $(GRUB2_MODULES) 165 | $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/ 166 | echo '(hd0) $(BIN_DIR)/$(IMG_COMBINED)-$(1).img' > $(KDIR)/grub2/device.map 167 | sed \ 168 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 169 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 170 | -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ 171 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 172 | -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 173 | ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg 174 | -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/ 175 | PADDING="1" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \ 176 | $(BIN_DIR)/$(IMG_COMBINED)-$(1).img \ 177 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \ 178 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ 179 | 256 180 | grub-bios-setup \ 181 | --device-map="$(KDIR)/grub2/device.map" \ 182 | -d "$(KDIR)/grub2" \ 183 | -r "hd0,msdos1" \ 184 | "$(BIN_DIR)/$(IMG_COMBINED)-$(1).img" 185 | endef 186 | endif 187 | 188 | endif 189 | 190 | define Image/Build/iso 191 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 192 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 193 | grub-mkimage \ 194 | -p /boot/grub \ 195 | -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \ 196 | -o $(KDIR)/grub2/eltorito.img \ 197 | -O i386-pc \ 198 | -c ./grub-early.cfg \ 199 | $(GRUB2_MODULES_ISO) 200 | cat \ 201 | $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \ 202 | $(KDIR)/grub2/eltorito.img \ 203 | > $(KDIR)/root.grub/boot/grub/eltorito.img 204 | sed \ 205 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ 206 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ 207 | -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ 208 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ 209 | -e 's#@TITLE@#$(GRUB_TITLE)#g' \ 210 | ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg 211 | -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/ 212 | mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \ 213 | -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR) 214 | endef 215 | 216 | ifneq ($(CONFIG_VDI_IMAGES),) 217 | define Image/Build/vdi 218 | rm $(BIN_DIR)/$(IMG_COMBINED)-$(1).vdi || true 219 | qemu-img convert -f raw -O vdi \ 220 | $(BIN_DIR)/$(IMG_COMBINED)-$(1).img \ 221 | $(BIN_DIR)/$(IMG_COMBINED)-$(1).vdi 222 | endef 223 | define Image/Build/vdi_efi 224 | rm $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).vdi || true 225 | qemu-img convert -f raw -O vdi \ 226 | $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img \ 227 | $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).vdi 228 | # XXX: VBoxManage insists on setting perms to 0600 229 | chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).vdi 230 | endef 231 | endif 232 | 233 | ifneq ($(CONFIG_VMDK_IMAGES),) 234 | define Image/Build/vmdk 235 | rm $(BIN_DIR)/$(IMG_COMBINED)-$(1).vmdk || true 236 | qemu-img convert -f raw -O vmdk \ 237 | $(BIN_DIR)/$(IMG_COMBINED)-$(1).img \ 238 | $(BIN_DIR)/$(IMG_COMBINED)-$(1).vmdk 239 | endef 240 | define Image/Build/vmdk_efi 241 | rm $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).vmdk || true 242 | qemu-img convert -f raw -O vmdk \ 243 | $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img \ 244 | $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).vmdk 245 | endef 246 | endif 247 | 248 | define Image/Build/gzip 249 | gzip -f9n $(BIN_DIR)/$(IMG_ROOTFS)-$(1).img 250 | ifneq ($(CONFIG_GRUB_IMAGES),) 251 | gzip -f9n $(BIN_DIR)/$(IMG_COMBINED)-$(1).img 252 | endif 253 | ifneq ($(CONFIG_EFI_IMAGES),) 254 | gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img 255 | endif 256 | endef 257 | 258 | $(eval $(call Image/gzip-ext4-padded-squashfs)) 259 | 260 | define Image/BuildKernel 261 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz 262 | endef 263 | 264 | define Image/Prepare 265 | $(call Image/Prepare/grub2) 266 | endef 267 | 268 | define Image/Build/Initramfs 269 | $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage 270 | endef 271 | 272 | define Image/Build 273 | $(call Image/Build/$(1)) 274 | ifneq ($(1),iso) 275 | $(call Image/Build/grub2,$(1)) 276 | $(call Image/Build/efi,$(1)) 277 | ifneq ($(CONFIG_GRUB_IMAGES),) 278 | $(call Image/Build/vdi,$(1)) 279 | $(call Image/Build/vmdk,$(1)) 280 | endif 281 | ifneq ($(CONFIG_EFI_IMAGES),) 282 | $(call Image/Build/vdi_efi,$(1)) 283 | $(call Image/Build/vmdk_efi,$(1)) 284 | endif 285 | $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_ROOTFS)-$(1).img 286 | else 287 | $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso 288 | endif 289 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz 290 | $(call Image/Build/gzip/$(1)) 291 | ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) 292 | $(call Image/Build/Initramfs) 293 | endif 294 | endef 295 | 296 | $(eval $(call BuildImage)) 297 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------