mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-07-24 13:36:31 +00:00
Use GRUB bootloader for all UEFI platforms (#1762)
* Use GRUB bootloader for all UEFI platforms * Introduce and use file_env command * Compress squashfs for aarch64 as well
This commit is contained in:
parent
b0bbe70315
commit
d1cc7394b5
@ -1 +1 @@
|
||||
cmdline=""
|
||||
console=tty1 console=ttyS0
|
||||
|
@ -43,7 +43,7 @@ fi
|
||||
save_env A_TRY A_OK B_TRY B_OK ORDER MACHINE_ID
|
||||
|
||||
default_cmdline="rootwait zram.enabled=1 zram.num_devices=3 apparmor=1 security=apparmor systemd.machine_id=$MACHINE_ID cgroup_enable=memory fsck.repair=yes"
|
||||
source ($root)/cmdline.txt
|
||||
file_env -f ($root)/cmdline.txt cmdline
|
||||
|
||||
# root is a full HDD/partition definition in GRUB format like hd0,gpt1
|
||||
# We extract the part before the comma to then append our own partition index
|
||||
|
@ -1,10 +0,0 @@
|
||||
CONFIG_MMU=y
|
||||
CONFIG_MALLOC_SIZE=0x0
|
||||
CONFIG_MALLOC_TLSF=y
|
||||
CONFIG_DRIVER_SERIAL_EFI=y
|
||||
CONFIG_DRIVER_SERIAL_EFI_STDIO=y
|
||||
# CONFIG_SPI is not set
|
||||
CONFIG_DISK=y
|
||||
CONFIG_DISK_WRITE=y
|
||||
CONFIG_FS_EFI=y
|
||||
CONFIG_FS_EFIVARFS=y
|
@ -3,13 +3,15 @@
|
||||
|
||||
function hassos_pre_image() {
|
||||
local BOOT_DATA="$(path_boot_dir)"
|
||||
local EFIPART_DATA="${BINARIES_DIR}/efi-part"
|
||||
|
||||
mkdir -p "${BOOT_DATA}/EFI/BOOT"
|
||||
mkdir -p "${BOOT_DATA}/EFI/barebox"
|
||||
|
||||
cp "${BINARIES_DIR}/barebox.bin" "${BOOT_DATA}/EFI/BOOT/BOOTx64.EFI"
|
||||
cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi.dtb" "${BOOT_DATA}/EFI/barebox/state.dtb"
|
||||
cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt"
|
||||
cp "${BOARD_DIR}/../grub.cfg" "${EFIPART_DATA}/EFI/BOOT/grub.cfg"
|
||||
cp "${BOARD_DIR}/cmdline.txt" "${EFIPART_DATA}/cmdline.txt"
|
||||
grub-editenv "${EFIPART_DATA}/EFI/BOOT/grubenv" create
|
||||
|
||||
cp -r "${EFIPART_DATA}/"* "${BOOT_DATA}/"
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
BOARD_ID=generic-x86-64
|
||||
BOARD_NAME="Generic x86-64"
|
||||
CHASSIS=embedded
|
||||
BOOTLOADER=barebox
|
||||
BOOTLOADER=grub
|
||||
KERNEL_FILE=bzImage
|
||||
BOOT_SYS=efi
|
||||
BOOT_SPL=false
|
||||
|
59
buildroot-external/board/pc/grub.cfg
Normal file
59
buildroot-external/board/pc/grub.cfg
Normal file
@ -0,0 +1,59 @@
|
||||
set default=99
|
||||
set timeout=5
|
||||
|
||||
set ORDER="A B"
|
||||
set A_OK=0
|
||||
set B_OK=0
|
||||
set A_TRY=0
|
||||
set B_TRY=0
|
||||
set MACHINE_ID=""
|
||||
load_env
|
||||
|
||||
# select bootable slot
|
||||
for SLOT in $ORDER; do
|
||||
if [ "$SLOT" == "A" ]; then
|
||||
INDEX=0
|
||||
OK=$A_OK
|
||||
TRY=$A_TRY
|
||||
A_TRY=1
|
||||
fi
|
||||
if [ "$SLOT" == "B" ]; then
|
||||
INDEX=1
|
||||
OK=$B_OK
|
||||
TRY=$B_TRY
|
||||
B_TRY=1
|
||||
fi
|
||||
if [ "$OK" -eq 1 -a "$TRY" -eq 0 ]; then
|
||||
default=$INDEX
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# reset booted flags
|
||||
if [ "$default" -eq 99 ]; then
|
||||
if [ "$A_OK" -eq 1 -a "$A_TRY" -eq 1 ]; then
|
||||
A_TRY=0
|
||||
fi
|
||||
if [ "$B_OK" -eq 1 -a "$B_TRY" -eq 1 ]; then
|
||||
B_TRY=0
|
||||
fi
|
||||
default=0
|
||||
fi
|
||||
|
||||
save_env A_TRY A_OK B_TRY B_OK ORDER MACHINE_ID
|
||||
|
||||
default_cmdline="rootwait zram.enabled=1 zram.num_devices=3 apparmor=1 security=apparmor systemd.machine_id=$MACHINE_ID cgroup_enable=memory fsck.repair=yes"
|
||||
file_env -f ($root)/cmdline.txt cmdline
|
||||
|
||||
# root is a full HDD/partition definition in GRUB format like hd0,gpt1
|
||||
# We extract the part before the comma to then append our own partition index
|
||||
# at the end. This is hacky but the best way I found
|
||||
regexp --set 1:boothd (.+),.+ ${root}
|
||||
|
||||
menuentry "Slot A (OK=$A_OK TRY=$A_TRY)" {
|
||||
linux (${boothd},gpt2)/bzImage root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd $default_cmdline $cmdline rauc.slot=A
|
||||
}
|
||||
|
||||
menuentry "Slot B (OK=$B_OK TRY=$B_TRY)" {
|
||||
linux (${boothd},gpt4)/bzImage root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 $default_cmdline $cmdline rauc.slot=B
|
||||
}
|
@ -3,13 +3,15 @@
|
||||
|
||||
function hassos_pre_image() {
|
||||
local BOOT_DATA="$(path_boot_dir)"
|
||||
local EFIPART_DATA="${BINARIES_DIR}/efi-part"
|
||||
|
||||
mkdir -p "${BOOT_DATA}/EFI/BOOT"
|
||||
mkdir -p "${BOOT_DATA}/EFI/barebox"
|
||||
|
||||
cp "${BINARIES_DIR}/barebox.bin" "${BOOT_DATA}/EFI/BOOT/BOOTx64.EFI"
|
||||
cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi.dtb" "${BOOT_DATA}/EFI/barebox/state.dtb"
|
||||
cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt"
|
||||
cp "${BOARD_DIR}/../grub.cfg" "${EFIPART_DATA}/EFI/BOOT/grub.cfg"
|
||||
cp "${BOARD_DIR}/cmdline.txt" "${EFIPART_DATA}/cmdline.txt"
|
||||
grub-editenv "${EFIPART_DATA}/EFI/BOOT/grubenv" create
|
||||
|
||||
cp -r "${EFIPART_DATA}/"* "${BOOT_DATA}/"
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
BOARD_ID=ova
|
||||
BOARD_NAME="Open Virtual Appliance"
|
||||
CHASSIS=vm
|
||||
BOOTLOADER=barebox
|
||||
BOOTLOADER=grub
|
||||
KERNEL_FILE=bzImage
|
||||
BOOT_SYS=efi
|
||||
BOOT_SPL=false
|
||||
|
@ -1,36 +0,0 @@
|
||||
From c9d56ea8fccf72e1c5d1f224f965e1a8e84d1b7f Mon Sep 17 00:00:00 2001
|
||||
From: Pascal Vizeli <pvizeli@syshack.ch>
|
||||
Date: Wed, 9 May 2018 21:54:58 +0200
|
||||
Subject: [PATCH 1/1] add -i argument to barebox-state call
|
||||
|
||||
---
|
||||
src/bootchooser.c | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/src/bootchooser.c b/src/bootchooser.c
|
||||
index d5efc0c..c57c2f7 100644
|
||||
--- a/src/bootchooser.c
|
||||
+++ b/src/bootchooser.c
|
||||
@@ -77,6 +77,9 @@ static gboolean barebox_state_get(const gchar* bootname, BareboxSlotState *bb_st
|
||||
g_ptr_array_add(args, g_strdup_printf(BOOTSTATE_PREFIX ".%s.priority", bootname));
|
||||
g_ptr_array_add(args, g_strdup("-g"));
|
||||
g_ptr_array_add(args, g_strdup_printf(BOOTSTATE_PREFIX ".%s.remaining_attempts", bootname));
|
||||
+
|
||||
+ g_ptr_array_add(args, g_strdup("-i"));
|
||||
+ g_ptr_array_add(args, g_strdup("/etc/barebox-state.dtb"));
|
||||
g_ptr_array_add(args, NULL);
|
||||
|
||||
sub = g_subprocess_newv((const gchar * const *)args->pdata,
|
||||
@@ -170,6 +173,9 @@ static gboolean barebox_state_set(GPtrArray *pairs, GError **error)
|
||||
g_ptr_array_add(args, g_strdup("-s"));
|
||||
g_ptr_array_add(args, g_strdup(pairs->pdata[i]));
|
||||
}
|
||||
+
|
||||
+ g_ptr_array_add(args, g_strdup("-i"));
|
||||
+ g_ptr_array_add(args, g_strdup("/etc/barebox-state.dtb"));
|
||||
g_ptr_array_add(args, NULL);
|
||||
|
||||
sub = g_subprocess_newv((const gchar * const *)args->pdata,
|
||||
--
|
||||
2.7.4
|
||||
|
Binary file not shown.
@ -1,76 +0,0 @@
|
||||
/dts-v1/;
|
||||
/ {
|
||||
|
||||
aliases {
|
||||
state = &state;
|
||||
};
|
||||
|
||||
state: state {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
magic = <0xef98423f>;
|
||||
compatible = "barebox,state";
|
||||
backend = <&backend_state>;
|
||||
backend-type = "raw";
|
||||
backend-stridesize = <4048>;
|
||||
|
||||
bootstate {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
A {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
remaining_attempts@0 {
|
||||
reg = <0x0 0x4>;
|
||||
type = "uint32";
|
||||
default = <3>;
|
||||
};
|
||||
priority@4 {
|
||||
reg = <0x4 0x4>;
|
||||
type = "uint32";
|
||||
default = <20>;
|
||||
};
|
||||
};
|
||||
|
||||
B {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
remaining_attempts@8 {
|
||||
reg = <0x8 0x4>;
|
||||
type = "uint32";
|
||||
default = <0>;
|
||||
};
|
||||
priority@c {
|
||||
reg = <0xc 0x4>;
|
||||
type = "uint32";
|
||||
default = <10>;
|
||||
};
|
||||
};
|
||||
|
||||
last_chosen@10 {
|
||||
reg = <0x10 0x4>;
|
||||
type = "uint32";
|
||||
};
|
||||
};
|
||||
|
||||
machine_id@14 {
|
||||
reg = <0x14 0x24>;
|
||||
type = "string";
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
|
||||
partitions {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
compatible = "fixed-partitions";
|
||||
|
||||
backend_state: state {
|
||||
partuuid = "33236519-7f32-4dff-8002-3390b62c309d";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -1,54 +0,0 @@
|
||||
# CONFIG_LOCALVERSION_AUTO is not set
|
||||
# CONFIG_CMD_VERSION is not set
|
||||
# CONFIG_TIMESTAMP is not set
|
||||
|
||||
CONFIG_PROMPT="HAOS-boot:"
|
||||
CONFIG_CMDLINE_EDITING=y
|
||||
CONFIG_AUTO_COMPLETE=y
|
||||
CONFIG_MENU=y
|
||||
CONFIG_BOOTM_SHOW_TYPE=y
|
||||
CONFIG_BOOTM_OFTREE=y
|
||||
CONFIG_FLEXIBLE_BOOTARGS=y
|
||||
CONFIG_DEFAULT_COMPRESSION_LZ4=y
|
||||
|
||||
# CONFIG_PARTITION_DISK_DOS is not set
|
||||
CONFIG_PARTITION_DISK_EFI=y
|
||||
# CONFIG_PARTITION_DISK_EFI_GPT_NO_FORCE is not set
|
||||
# CONFIG_PARTITION_DISK_EFI_GPT_COMPARE is not set
|
||||
|
||||
CONFIG_STATE=y
|
||||
CONFIG_STATE_DRV=y
|
||||
CONFIG_BOOTCHOOSER=y
|
||||
CONFIG_RESET_SOURCE=y
|
||||
CONFIG_CMD_BOOT=y
|
||||
CONFIG_CMD_RESET=y
|
||||
CONFIG_CMD_BOOTCHOOSER=y
|
||||
CONFIG_CMD_NV=y
|
||||
CONFIG_CMD_EXPORT=y
|
||||
CONFIG_CMD_GLOBAL=y
|
||||
CONFIG_CMD_BASENAME=y
|
||||
CONFIG_CMD_DIRNAME=y
|
||||
CONFIG_CMD_READLINK=y
|
||||
CONFIG_CMD_GETOPT=y
|
||||
CONFIG_CMD_READF=y
|
||||
CONFIG_CMD_ECHO_E=y
|
||||
CONFIG_CMD_EDIT=y
|
||||
CONFIG_CMD_MENUTREE=y
|
||||
CONFIG_CMD_TIMEOUT=y
|
||||
CONFIG_CMD_OFTREE=y
|
||||
CONFIG_CMD_STATE=y
|
||||
|
||||
CONFIG_OFTREE=y
|
||||
CONFIG_OFTREE_OVERLAY=y
|
||||
|
||||
CONFIG_DISK=y
|
||||
CONFIG_DISK_WRITE=y
|
||||
CONFIG_FS_EXT4=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_FAT_WRITE=y
|
||||
CONFIG_FS_FAT_LFN=y
|
||||
CONFIG_FS_SQUASHFS=y
|
||||
CONFIG_SQUASHFS_LZ4=y
|
||||
CONFIG_SQUASHFS_LZO=y
|
||||
CONFIG_LZ4_DECOMPRESS=y
|
||||
CONFIG_LZO_DECOMPRESS=y
|
@ -1,18 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
export PATH=/env/bin
|
||||
|
||||
# Autostart
|
||||
for i in /env/init/*; do
|
||||
. $i
|
||||
done
|
||||
|
||||
echo "- Hit m for menu or wait for autoboot -"
|
||||
timeout -a 1 -s -v key
|
||||
|
||||
# Run menu
|
||||
if [ "${key}" != "m" ]; then
|
||||
boot
|
||||
fi
|
||||
|
||||
menutree
|
@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.dyn.root="root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd rootfstype=squashfs ro"
|
||||
|
||||
mkdir -p /mnt/system
|
||||
mount /dev/*disk*.hassos-kernel0 /mnt/system
|
||||
|
||||
global bootm.image="/mnt/system/bzImage"
|
@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.dyn.root="root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 rootfstype=squashfs ro"
|
||||
|
||||
mkdir -p /mnt/system
|
||||
mount /dev/*disk*.hassos-kernel1 /mnt/system
|
||||
|
||||
global bootm.image="/mnt/system/bzImage"
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global bootchooser.targets
|
||||
global bootchooser.system0.boot
|
||||
global bootchooser.system1.boot
|
||||
|
||||
[ -z "${global.bootchooser.targets}" ] && global.bootchooser.targets="system0 system1"
|
||||
[ -z "${global.bootchooser.system0.boot}" ] && global.bootchooser.system0.boot="system0"
|
||||
[ -z "${global.bootchooser.system1.boot}" ] && global.bootchooser.system1.boot="system1"
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.base=""
|
||||
if [ -f /boot/cmdline.txt ]; then
|
||||
readf /boot/cmdline.txt global.linux.bootargs.base
|
||||
fi
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.zram="zram.enabled=1 zram.num_devices=3"
|
||||
global linux.bootargs.apparmor="apparmor=1 security=apparmor"
|
||||
global linux.bootargs.misc="rootwait"
|
||||
global linux.bootargs.systemd="systemd.machine_id=${state.machine_id}"
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
boot
|
@ -1 +0,0 @@
|
||||
Autoboot
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.bootchooser="bootchooser.active=A"
|
||||
|
||||
boot system0
|
@ -1 +0,0 @@
|
||||
Boot System 0
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
global linux.bootargs.bootchooser="bootchooser.active=B"
|
||||
|
||||
boot system1
|
@ -1 +0,0 @@
|
||||
Boot System 1
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Enter 'exit' to get back to the menu"
|
||||
|
||||
sh
|
@ -1 +0,0 @@
|
||||
Shell
|
@ -1 +0,0 @@
|
||||
Home Assistant OS boot menu:
|
@ -1 +0,0 @@
|
||||
bootchooser
|
@ -1 +0,0 @@
|
||||
system0
|
@ -1 +0,0 @@
|
||||
system1
|
@ -1 +0,0 @@
|
||||
state.bootstate
|
@ -1 +0,0 @@
|
||||
A B
|
@ -1 +0,0 @@
|
||||
sedit
|
@ -137,4 +137,5 @@ BR2_TARGET_GRUB2_INSTALL_TOOLS=y
|
||||
|
||||
# Filesystem image
|
||||
BR2_TARGET_ROOTFS_SQUASHFS=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS4_LZ4=y
|
||||
# BR2_TARGET_ROOTFS_TAR is not set
|
||||
|
@ -104,13 +104,6 @@ BR2_PACKAGE_USB_MODESWITCH_DATA=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS4_LZ4=y
|
||||
# BR2_TARGET_ROOTFS_TAR is not set
|
||||
BR2_TARGET_BAREBOX=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_VERSION=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_VERSION_VALUE="2021.05.0"
|
||||
BR2_TARGET_BAREBOX_USE_CUSTOM_CONFIG=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_HASSOS_PATH)/board/pc/barebox.config"
|
||||
BR2_TARGET_BAREBOX_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/barebox.config"
|
||||
BR2_TARGET_BAREBOX_CUSTOM_EMBEDDED_ENV_PATH="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/barebox"
|
||||
BR2_PACKAGE_HOST_DOSFSTOOLS=y
|
||||
BR2_PACKAGE_HOST_E2FSPROGS=y
|
||||
BR2_PACKAGE_HOST_GPTFDISK=y
|
||||
@ -127,3 +120,9 @@ BR2_PACKAGE_DOSFSTOOLS=y
|
||||
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
|
||||
BR2_PACKAGE_RPI_RF_MOD=y
|
||||
BR2_PACKAGE_RTL88X2BU=y
|
||||
|
||||
# Bootloader
|
||||
BR2_TARGET_GRUB2=y
|
||||
BR2_TARGET_GRUB2_X86_64_EFI=y
|
||||
BR2_TARGET_GRUB2_BUILTIN_MODULES="boot linux ext2 fat squash4 part_msdos part_gpt normal efi_gop regexp loadenv echo cat test configfile"
|
||||
BR2_TARGET_GRUB2_INSTALL_TOOLS=y
|
||||
|
@ -107,13 +107,6 @@ BR2_PACKAGE_USB_MODESWITCH_DATA=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS4_LZ4=y
|
||||
# BR2_TARGET_ROOTFS_TAR is not set
|
||||
BR2_TARGET_BAREBOX=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_VERSION=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_VERSION_VALUE="2021.05.0"
|
||||
BR2_TARGET_BAREBOX_USE_CUSTOM_CONFIG=y
|
||||
BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_HASSOS_PATH)/board/pc/barebox.config"
|
||||
BR2_TARGET_BAREBOX_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/barebox.config"
|
||||
BR2_TARGET_BAREBOX_CUSTOM_EMBEDDED_ENV_PATH="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/barebox"
|
||||
BR2_PACKAGE_HOST_DOSFSTOOLS=y
|
||||
BR2_PACKAGE_HOST_E2FSPROGS=y
|
||||
BR2_PACKAGE_HOST_GPTFDISK=y
|
||||
@ -128,3 +121,9 @@ BR2_PACKAGE_LIBCURL_CURL=y
|
||||
BR2_PACKAGE_DOSFSTOOLS=y
|
||||
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
|
||||
BR2_PACKAGE_RPI_RF_MOD=y
|
||||
|
||||
# Bootloader
|
||||
BR2_TARGET_GRUB2=y
|
||||
BR2_TARGET_GRUB2_X86_64_EFI=y
|
||||
BR2_TARGET_GRUB2_BUILTIN_MODULES="boot linux ext2 fat squash4 part_msdos part_gpt normal efi_gop regexp loadenv echo cat test configfile"
|
||||
BR2_TARGET_GRUB2_INSTALL_TOOLS=y
|
||||
|
@ -0,0 +1,119 @@
|
||||
From ee4adaa04e3ac1a5d20ad713a0133382c35da5a1 Mon Sep 17 00:00:00 2001
|
||||
Message-Id: <ee4adaa04e3ac1a5d20ad713a0133382c35da5a1.1645704230.git.stefan@agner.ch>
|
||||
From: Stefan Agner <stefan@agner.ch>
|
||||
Date: Thu, 24 Feb 2022 12:38:48 +0100
|
||||
Subject: [PATCH] loadenv: add file_env to load var from file
|
||||
|
||||
Introduce file_env which allows to load the value of a variable from a
|
||||
file. The variable value is terminated at the first non-printable
|
||||
character.
|
||||
---
|
||||
grub-core/commands/loadenv.c | 73 +++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 72 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c
|
||||
index 3fd664aac..7e7b18139 100644
|
||||
--- a/grub-core/commands/loadenv.c
|
||||
+++ b/grub-core/commands/loadenv.c
|
||||
@@ -40,6 +40,14 @@ static const struct grub_arg_option options[] =
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
+static const struct grub_arg_option options_file_env[] =
|
||||
+ {
|
||||
+ /* TRANSLATORS: This option is used to override default filename
|
||||
+ for loading and storing environment. */
|
||||
+ {"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME},
|
||||
+ {0, 0, 0, 0, 0, 0}
|
||||
+ };
|
||||
+
|
||||
/* Opens 'filename' with compression filters disabled. Optionally disables the
|
||||
PUBKEY filter (that insists upon properly signed files) as well. PUBKEY
|
||||
filter is restored before the function returns. */
|
||||
@@ -442,7 +450,64 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
-static grub_extcmd_t cmd_load, cmd_list, cmd_save;
|
||||
+static grub_err_t
|
||||
+grub_cmd_file_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
+{
|
||||
+ grub_off_t offset = 0;
|
||||
+ struct grub_arg_list *state = ctxt->state;
|
||||
+ grub_file_t file;
|
||||
+ grub_size_t size;
|
||||
+ char *buf;
|
||||
+
|
||||
+ if (argc != 1)
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name expected"));
|
||||
+
|
||||
+ /* state[0] is the -f flag; state[1] is the --skip-sig flag */
|
||||
+ file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
+ GRUB_FILE_TYPE_CAT);
|
||||
+ if (! file)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ size = grub_file_size (file);
|
||||
+ buf = grub_malloc (size + 1);
|
||||
+ if (! buf)
|
||||
+ goto fail;
|
||||
+
|
||||
+ /* make sure buffer is terminated in any case */
|
||||
+ buf[size] = '\0';
|
||||
+ while (size > 0)
|
||||
+ {
|
||||
+ grub_ssize_t ret;
|
||||
+
|
||||
+ ret = grub_file_read (file, buf + offset, size);
|
||||
+ if (ret <= 0)
|
||||
+ goto fail;
|
||||
+
|
||||
+ /* terminate at the first non-printable character */
|
||||
+ while (ret)
|
||||
+ {
|
||||
+ if (!grub_isprint(buf[offset]))
|
||||
+ {
|
||||
+ buf[offset] = '\0';
|
||||
+ size = 0;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ ret--;
|
||||
+ size--;
|
||||
+ offset++;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ grub_env_set (args[0], buf);
|
||||
+
|
||||
+ fail:
|
||||
+ grub_free (buf);
|
||||
+ grub_file_close (file);
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+static grub_extcmd_t cmd_load, cmd_list, cmd_save, cmd_file;
|
||||
|
||||
GRUB_MOD_INIT(loadenv)
|
||||
{
|
||||
@@ -460,6 +525,11 @@ GRUB_MOD_INIT(loadenv)
|
||||
N_("[-f FILE] variable_name [...]"),
|
||||
N_("Save variables to environment block file."),
|
||||
options);
|
||||
+ cmd_file =
|
||||
+ grub_register_extcmd ("file_env", grub_cmd_file_env, 0,
|
||||
+ N_("[-f FILE] variable_name"),
|
||||
+ N_("Set variable to content of a file."),
|
||||
+ options_file_env);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(loadenv)
|
||||
@@ -467,4 +537,5 @@ GRUB_MOD_FINI(loadenv)
|
||||
grub_unregister_extcmd (cmd_load);
|
||||
grub_unregister_extcmd (cmd_list);
|
||||
grub_unregister_extcmd (cmd_save);
|
||||
+ grub_unregister_extcmd (cmd_file);
|
||||
}
|
||||
--
|
||||
2.35.1
|
||||
|
@ -27,16 +27,4 @@ elif [ -e /usr/bin/grub-editenv ]; then
|
||||
echo "[INFO] machine-id is okay"
|
||||
fi
|
||||
|
||||
###
|
||||
# Barebox
|
||||
else
|
||||
|
||||
# machine-id
|
||||
if [ "$(barebox-state -g state.machine_id -i /etc/barebox-state.dtb)" != "${MACHINE_ID}" ]; then
|
||||
echo "[INFO] set machine-id to ${MACHINE_ID}"
|
||||
barebox-state -s "state.machine_id=${MACHINE_ID}" -i /etc/barebox-state.dtb
|
||||
else
|
||||
echo "[INFO] machine-id is okay"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
@ -84,8 +84,6 @@ function install_bootloader_config() {
|
||||
if [ "${BOOTLOADER}" == "uboot" ]; then
|
||||
# shellcheck disable=SC1117
|
||||
echo -e "/dev/disk/by-partlabel/hassos-bootstate\t0x0000\t${BOOT_ENV_SIZE}" > "${TARGET_DIR}/etc/fw_env.config"
|
||||
elif [ "${BOOTLOADER}" == "barebox" ]; then
|
||||
cp -f "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi.dtb" "${TARGET_DIR}/etc/barebox-state.dtb"
|
||||
fi
|
||||
|
||||
# Fix MBR
|
||||
|
Loading…
x
Reference in New Issue
Block a user