ci-test-sample/debian/patches/live-build-3.0~a57-ltz-efi....

494 lines
15 KiB
Diff

From: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Date: Tue, 18 Jul 2017 17:21:09 +0800
Subject: live-build-3.0~a57-ltz-efi
===================================================================
---
scripts/build/lb_binary | 1 +
scripts/build/lb_binary_grub2-efi | 364 ++++++++++++++++++++++++++++++++++
scripts/build/lb_binary_iso | 3 +-
scripts/build/lb_binary_package-lists | 33 +++
templates/grub2/grub.cfg | 15 +-
5 files changed, 411 insertions(+), 5 deletions(-)
create mode 100644 scripts/build/lb_binary_grub2-efi
diff --git a/scripts/build/lb_binary b/scripts/build/lb_binary
index 600d893..13540ec 100755
--- a/scripts/build/lb_binary
+++ b/scripts/build/lb_binary
@@ -65,6 +65,7 @@ lb binary_debian-installer ${*}
lb binary_memtest ${*}
lb binary_grub ${*}
lb binary_grub2 ${*}
+lb binary_grub2-efi ${*}
lb binary_syslinux ${*}
lb binary_yaboot ${*}
lb binary_silo ${*}
diff --git a/scripts/build/lb_binary_grub2-efi b/scripts/build/lb_binary_grub2-efi
new file mode 100644
index 0000000..489d06b
--- /dev/null
+++ b/scripts/build/lb_binary_grub2-efi
@@ -0,0 +1,364 @@
+#!/bin/sh
+
+set -e
+
+# Including common functions
+( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'installs grub2 efi into binary')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+ARCHITECTURE="$(echo ${LB_ARCHITECTURES} | sed -e 's| |/|g')"
+
+Arguments "${@}"
+
+if [ -f .build/chroot_has_efi ] || [ -f .build/binary_has_efi ];then
+ Echo_message "Begin installing grub2 efi..."
+else
+ Echo_message "Kylin add has .build/no_efi, exit grub2-efi"
+ exit 0
+fi
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
+Set_defaults
+
+# Requiring stage file
+Require_stagefile .build/config .build/bootstrap
+
+# Checking stage file
+Check_stagefile .build/binary_grub2_efi
+
+# Checking grub2 templates
+Check_templates grub2
+
+# Checking lock file
+Check_lockfile .lock
+
+# Creating lock file
+Create_lockfile .lock
+
+# Check architecture
+Check_architectures amd64 arm64
+Check_crossarchitectures
+
+# Checking depends
+case ${ARCHITECTURE} in
+ 'amd64')
+ Check_package chroot/usr/bin/grub-mkimage grub-efi-amd64
+ ;;
+ 'arm64')
+ Check_package chroot/usr/bin/grub-mkimage grub-efi-arm64
+ ;;
+ *)
+ Echo_message "not amd64 or arm64, grub2-efi exit"
+ exit 0
+ ;;
+esac
+
+# Restoring cache
+Restore_cache cache/packages.binary
+
+# Installing depends
+Install_package
+
+case ${LB_BINARY_IMAGES} in
+ iso*)
+ if [ ! -d chroot/usr/lib/grub/x86_64-efi ] && [ ! -d chroot/usr/lib/grub/arm64-efi ];then
+ exit 0
+ fi
+ ;;
+
+ *)
+ exit 0
+ ;;
+esac
+
+
+Echo_message "Begin installing grub2 efi doing..."
+# Local functions
+Grub_live_entry ()
+{
+ LABEL="${1}"
+ KERNEL="${2}"
+ INITRD="${3}"
+ APPEND="${4}"
+ DEVICETREE="${5}"
+
+ LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"${LABEL}\" {"
+ LINUX_LIVE="${LINUX_LIVE}\nlinux\t\t/${KERNEL} ${APPEND}"
+ LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
+ if [ -n "$DEVICETREE" ];then
+ LINUX_LIVE="${LINUX_LIVE}\ndevicetree\t\t/${DEVICETREE}"
+ fi
+ LINUX_LIVE="${LINUX_LIVE}\n}"
+}
+
+Grub_install_entry ()
+{
+ LABEL="${1}"
+ KERNEL="${2}"
+ INITRD="${3}"
+ APPEND="${4}"
+ DEVICETREE="${5}"
+
+ if [ -e "${KERNEL}" ] && [ -e "${APPEND}" ];then
+ LINUX_INSTALL="${LINUX_INSTALL}\nmenuentry \"${LABEL}\" {"
+ LINUX_INSTALL="${LINUX_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
+ LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
+ if [ -n "$DEVICETREE" ];then
+ LINUX_INSTALL="${LINUX_INSTALL}\ndevicetree\t\t/${DEVICETREE}"
+ fi
+ LINUX_INSTALL="${LINUX_INSTALL}\n}"
+ fi
+}
+
+case "${LB_INITRAMFS}" in
+ casper)
+ INITFS="casper"
+ ;;
+
+ live-boot)
+ INITFS="live"
+ ;;
+
+ *)
+ INITFS=""
+ ;;
+esac
+
+# Setting destination directory
+case "${LB_BINARY_IMAGES}" in
+ iso*|tar)
+ case "${LB_INITRAMFS}" in
+ casper)
+ DESTDIR_LIVE="binary/casper"
+ ;;
+
+ live-boot)
+ DESTDIR_LIVE="binary/live"
+ ;;
+
+ *)
+ DESTDIR_LIVE="binary/live"
+ ;;
+ esac
+
+ DESTDIR_INSTALL="binary/install"
+ ;;
+
+ hdd*|netboot)
+ Echo_warning "Bootloader in this image type not yet supported by live-build."
+ Echo_warning "This would produce a not bootable image, aborting (FIXME)."
+ exit 1
+ ;;
+esac
+
+Check_multiarchitectures
+
+# Creating directory
+mkdir -p "${DESTDIR_LIVE}"
+
+# Setting boot parameters
+if [ "${LB_UNION_FILESYSTEM}" != "aufs" ]
+then
+ LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} union=${LB_UNION_FILESYSTEM}"
+fi
+
+if [ -n "${LB_NET_COW_PATH}" ]
+then
+ Echo_error "Net cow not yet supported on grub"
+ exit 1
+fi
+
+if [ "${LB_EXPOSED_ROOT}" != "false" ]
+then
+ LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} exposedroot"
+fi
+
+LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's| ||')"
+
+# Assembling kernel configuration
+
+# Default entries
+DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
+DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
+DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
+
+
+case ${ARCHITECTURE} in
+ 'amd64')
+ Grub_live_entry "Try Kylin without installing" "/casper/vmlinuz" "/casper/initrd.lz" "boot=casper locale=zh_CN quiet splash"
+ Grub_live_entry "Install Kylin" "/casper/vmlinuz" "/casper/initrd.lz" "boot=casper only-ubiquity locale=zh_CN quiet splash"
+ ;;
+ 'arm64')
+ #Grub_live_entry "Try Kylin without installing" "/casper/Image" "/casper/initrd.img" "boot=casper locale=zh_CN quiet splash" "/casper/u-boot-general.dtb"
+ #Grub_live_entry "Install Kylin" "/casper/Image" "/casper/initrd.img" "boot=casper only-ubiquity locale=zh_CN quiet splash" "/casper/u-boot-general.dtb"
+ Grub_live_entry "Try Kylin without installing" "/casper/Image" "/casper/initrd.img" "boot=casper rootwait ro locale=zh_CN KEYBOARDTYPE=pc KEYTABLE=us ignore_uuid quiet"
+ Grub_live_entry "Install Kylin" "/casper/Image" "/casper/initrd.img" "boot=casper only-ubiquity rootwait ro locale=zh_CN KEYBOARDTYPE=pc KEYTABLE=us ignore_uuid quiet"
+ ;;
+esac
+
+LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
+
+# Assembling debian-installer configuration
+if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
+then
+ case ${ARCHITECTURE} in
+ 'amd64')
+ LINUX_LIVE="#\t \"Live\"\n${LINUX_LIVE}"
+ LINUX_INSTALL="#\t \"Installer\"\n"
+
+ VMLINUZ_DI="install/vmlinuz"
+ INITRD_DI="install/initrd.gz"
+ APPEND_DI="vga=normal"
+
+ VMLINUZ_GI="install/gtk/vmlinuz"
+ INITRD_GI="install/gtk/initrd.gz"
+ APPEND_GI="video=vesa:ywrap,mtrr vga=788"
+
+ Grub_install_entry "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
+ Grub_install_entry "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
+ Grub_install_entry "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
+ Grub_install_entry "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
+ Grub_install_entry "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
+ Grub_install_entry "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
+ Grub_install_entry "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
+ Grub_install_entry "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
+ ;;
+ 'arm64')
+ LINUX_LIVE="#\t \"Live\"\n${LINUX_LIVE}"
+ LINUX_INSTALL="#\t \"Installer\"\n"
+
+ VMLINUZ_DI="install/Image"
+ INITRD_DI="install/initrd.img"
+ APPEND_DI="vga=normal rootwait"
+
+ VMLINUZ_GI="install/gtk/vmlinuz"
+ INITRD_GI="install/gtk/initrd.img"
+ APPEND_GI="video=vesa:ywrap,mtrr vga=788 rootwait"
+
+ Grub_install_entry "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
+ Grub_install_entry "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
+ Grub_install_entry "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
+ Grub_install_entry "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
+ Grub_install_entry "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
+ Grub_install_entry "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
+ Grub_install_entry "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
+ Grub_install_entry "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
+ ;;
+ esac
+fi
+
+LINUX_INSTALL="$(/bin/echo ${LINUX_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
+
+# Assembling memtest configuration
+if [ -f "${DESTDIR_LIVE}"/memtest ]
+then
+ MEMTEST="#\t \"Other\"\n"
+ MEMTEST="${MEMTEST}\nmenuentry\t\"${LB_MEMTEST}\" {\nlinux16\t$(basename ${DESTDIR_LIVE})/memtest\n}"
+ MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
+fi
+
+# Copying templates
+mkdir -p binary/boot/grub
+cp -r "${TEMPLATES}"/* binary/boot/grub
+
+case ${LB_BINARY_IMAGES} in
+ iso*)
+ case ${ARCHITECTURE} in
+ 'amd64')
+ FILES="chroot/usr/lib/grub/x86_64-efi chroot/usr/share/grub/*.pf2"
+ ;;
+ 'arm64')
+ FILES="chroot/usr/lib/grub/arm64-efi chroot/usr/share/grub/*.pf2"
+ ;;
+ esac
+ ;;
+esac
+
+# Copying grub
+cp -r ${FILES} binary/boot/grub
+
+if [ "${LB_BUILD_WITH_CHROOT}" = "false" ]
+then
+ FILES="$(echo ${FILES} | sed -e 's|chroot||g')"
+fi
+
+# Copying local configuration file
+if [ -f config/binary_grub/grub.cfg ]
+then
+ cp config/binary_grub/grub.cfg binary/boot/grub/grub.cfg
+fi
+
+sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/grub.cfg
+sed -i -e "s|LB_BOOTAPPEND_INSTALL|${LB_BOOTAPPEND_INSTALL}|" -e "s|LB_BOOTAPPEND_LIVE|${LB_BOOTAPPEND_LIVE}|" binary/boot/grub/grub.cfg
+
+sed -i -e 's|\ $||g' binary/boot/grub/grub.cfg
+
+#kylin create efi.img
+KY_EFI=""
+KY_EFI_NAME=""
+if [ -d chroot/usr/lib/grub/x86_64-efi ];then
+ KY_EFI="/usr/lib/grub/x86_64-efi"
+ KY_EFI_NAME="x86_64-efi"
+ KY_BOOT_EFI_NAME="bootx64.efi"
+elif [ -d chroot/usr/lib/grub/arm64-efi ];then
+ KY_EFI="/usr/lib/grub/arm64-efi"
+ KY_EFI_NAME="arm64-efi"
+ KY_BOOT_EFI_NAME="bootaa64.efi"
+fi
+
+mkdir -p binary/boot/grub
+if [ -n "${KY_EFI}" ];then
+ cat > kylin_efi.sh << EOF
+input_efi_dir=${KY_EFI}
+core_efi_img=\$(mktemp)
+efi_mount_tmp=\$(mktemp -d)
+grub-mkimage -o \${core_efi_img} -O ${KY_EFI_NAME} -d \${input_efi_dir} fat part_msdos search_fs_uuid search_label search_fs_file search normal linux font all_video reboot configfile test iso9660
+dd if=/dev/zero of=efi.img bs=1M count=100
+mkfs.vfat efi.img
+mount -o loop efi.img \${efi_mount_tmp}
+mkdir -p \${efi_mount_tmp}/efi/boot/
+cp \${core_efi_img} \${efi_mount_tmp}/efi/boot/${KY_BOOT_EFI_NAME}
+umount \${efi_mount_tmp}
+rm -rf \${efi_mount_tmp}
+rm -rf \${core_efi_img}
+cp -rf \${input_efi_dir} binary/boot/grub
+mv efi.img binary/boot/grub/
+EOF
+
+ case "${LB_BUILD_WITH_CHROOT}" in
+ true)
+ # Moving image
+ mv kylin_efi.sh chroot
+ mv binary chroot
+
+ Chroot chroot "sh kylin_efi.sh"
+
+ # Move image
+ mv chroot/binary ./
+ ;;
+
+ false)
+ sh kylin_efi.sh
+ ;;
+ esac
+fi
+
+if [ -f chroot/boot/grub/grub_ba.efi ];then
+ cp chroot/boot/grub/grub_ba.efi binary/boot/grub/
+fi
+
+if [ -f chroot/boot/grub/grub_kl.efi ];then
+ cp chroot/boot/grub/grub_kl.efi binary/boot/grub/
+fi
+#end
+
+
+# Saving cache
+Save_cache cache/packages.binary
+
+# Creating stage file
+Create_stagefile .build/binary_grub2_efi
diff --git a/scripts/build/lb_binary_iso b/scripts/build/lb_binary_iso
index 4180fae..4d25199 100755
--- a/scripts/build/lb_binary_iso
+++ b/scripts/build/lb_binary_iso
@@ -17,6 +17,7 @@ set -e
DESCRIPTION="$(Echo 'build iso binary image')"
HELP=""
USAGE="${PROGRAM} [--force]"
+ARCHITECTURE="$(echo ${LB_ARCHITECTURES} | sed -e 's| |/|g')"
Arguments "${@}"
@@ -225,7 +226,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
# Move image
mv chroot/binary chroot/${IMAGE} ./
- rm -f chroot/binary.sh
+ #rm -f chroot/binary.sh
;;
false)
diff --git a/scripts/build/lb_binary_package-lists b/scripts/build/lb_binary_package-lists
index 1492cb1..a22da5a 100755
--- a/scripts/build/lb_binary_package-lists
+++ b/scripts/build/lb_binary_package-lists
@@ -38,6 +38,23 @@ Check_lockfile .lock
# Creating lock file
Create_lockfile .lock
+#kylin add efi
+ARCHITECTURE="$(echo ${LB_ARCHITECTURES} | sed -e 's| |/|g')"
+case ${ARCHITECTURE} in
+ 'arm64'|'amd64')
+ ky_chroot_has_efi="$(cat binary/casper/filesystem.manifest | grep grub-efi- | wc -l)"
+ if [ "${ky_chroot_has_efi}" = "0" ];then
+ touch .build/chroot_no_efi
+ else
+ touch .build/chroot_has_efi
+ fi
+ ;;
+ *)
+ touch .build/chroot_no_efi
+ ;;
+esac
+#end kylin efi
+
if ls config/package-lists/*.list > /dev/null 2>&1 || \
ls config/package-lists/*.list.binary > /dev/null 2>&1
then
@@ -109,6 +126,22 @@ then
fi
done
+ #kylin add efi
+ case ${ARCHITECTURE} in
+ 'arm64'|'amd64')
+ efi_pkg_num="$(ls chroot/binary.deb/archives/grub-efi*.deb | wc -l)"
+ if [ "${efi_pkg_num}" = "0" ];then
+ touch .build/binary_no_efi
+ else
+ touch .build/binary_has_efi
+ fi
+ ;;
+ *)
+ touch .build/binary_no_efi
+ ;;
+ esac
+ #end kylin efi
+
for FILE in chroot/binary.deb/archives/*.deb
do
SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')"
diff --git a/templates/grub2/grub.cfg b/templates/grub2/grub.cfg
index 4ad86bd..e65e389 100644
--- a/templates/grub2/grub.cfg
+++ b/templates/grub2/grub.cfg
@@ -1,9 +1,16 @@
set default=0
+set timeout=3
-insmod tga
-background_image ($root)/boot/grub/xbmc.tga
-set color_normal=cyan/blue
-set color_highlight=white/blue
+set color_normal=white/black
+set color_highlight=black/light-gray
+
+if loadfont /boot/grub/unicode.pf2 ; then
+ set gfxmode=auto
+ insmod efi_gop
+ insmod efi_uga
+ insmod gfxterm
+ terminal_output gfxterm
+fi
LINUX_LIVE