summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2016-08-23 14:32:35 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2016-08-27 13:11:22 +0000
commitb6ec7526b58fa6d42792c460f3eedff410cb2c60 (patch)
treed0c20db49fed38432d95f6f3fb3825b1dfa3c6c8
parent47b0b4120a9bb3d68318b7e479b1314183857868 (diff)
downloadostree-b6ec7526b58fa6d42792c460f3eedff410cb2c60.tar.gz
u-boot: Merge ostree's and systems uEnv.txt
This is a proper fix for: https://bugzilla.gnome.org/show_bug.cgi?id=755787 With this patch, an admin (system builder) can now: 1) Edit /usr/lib/ostree-boot/uEnv.txt 2) Deploy the new tree. OSTree will append system's uEnv.txt to the OSTree's managed uEnv.txt (loader/uEnv.txt). It is common for u-boot systems to read in an extra env from external /uEnv.txt. The same file OSTree uses to pass in its env. With this patch /uEnv.txt now contains OSTree's env + custom env added by system builders. Closes: #466 Approved by: cgwalters
-rw-r--r--src/libostree/ostree-bootloader-uboot.c40
-rwxr-xr-xtests/admin-test.sh2
-rwxr-xr-xtests/test-admin-deploy-grub2.sh2
-rwxr-xr-xtests/test-admin-deploy-syslinux.sh2
-rwxr-xr-xtests/test-admin-deploy-uboot.sh18
5 files changed, 61 insertions, 3 deletions
diff --git a/src/libostree/ostree-bootloader-uboot.c b/src/libostree/ostree-bootloader-uboot.c
index f95ea843..81ea95a6 100644
--- a/src/libostree/ostree-bootloader-uboot.c
+++ b/src/libostree/ostree-bootloader-uboot.c
@@ -95,7 +95,45 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
val = ostree_bootconfig_parser_get (config, "options");
if (val)
- g_ptr_array_add (new_lines, g_strdup_printf ("bootargs=%s", val));
+ {
+ glnx_fd_close int uenv_fd = -1;
+ __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL;
+ const char *uenv_path = NULL;
+ const char *ostree_arg = NULL;
+
+ g_ptr_array_add (new_lines, g_strdup_printf ("bootargs=%s", val));
+
+ /* Append system's uEnv.txt, if it exists in $deployment/usr/lib/ostree-boot/ */
+ kargs = _ostree_kernel_args_from_string (val);
+ ostree_arg = _ostree_kernel_args_get_last_value (kargs, "ostree");
+ if (!ostree_arg)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "No ostree= kernel argument found in boot loader configuration file");
+ return FALSE;
+ }
+ ostree_arg += 1;
+ uenv_path = glnx_strjoina (ostree_arg, "/usr/lib/ostree-boot/uEnv.txt");
+ uenv_fd = openat (self->sysroot->sysroot_fd, uenv_path, O_CLOEXEC | O_RDONLY);
+ if (uenv_fd != -1)
+ {
+ char *uenv = glnx_fd_readall_utf8 (uenv_fd, NULL, cancellable, error);
+ if (!uenv)
+ {
+ g_prefix_error (error, "Reading %s: ", uenv_path);
+ return FALSE;
+ }
+ g_ptr_array_add (new_lines, uenv);
+ }
+ else
+ {
+ if (errno != ENOENT)
+ {
+ g_prefix_error (error, "openat %s: ", uenv_path);
+ return FALSE;
+ }
+ }
+ }
return TRUE;
}
diff --git a/tests/admin-test.sh b/tests/admin-test.sh
index dcc34068..76fc8b85 100755
--- a/tests/admin-test.sh
+++ b/tests/admin-test.sh
@@ -18,8 +18,6 @@
set -euo pipefail
-echo "1..16"
-
function validate_bootloader() {
cd ${test_tmpdir};
bootloader=""
diff --git a/tests/test-admin-deploy-grub2.sh b/tests/test-admin-deploy-grub2.sh
index 6109a950..2b90c286 100755
--- a/tests/test-admin-deploy-grub2.sh
+++ b/tests/test-admin-deploy-grub2.sh
@@ -19,6 +19,8 @@
set -euo pipefail
+echo "1..16"
+
. $(dirname $0)/libtest.sh
# Exports OSTREE_SYSROOT so --sysroot not needed.
diff --git a/tests/test-admin-deploy-syslinux.sh b/tests/test-admin-deploy-syslinux.sh
index 419df2ba..70b3b4d3 100755
--- a/tests/test-admin-deploy-syslinux.sh
+++ b/tests/test-admin-deploy-syslinux.sh
@@ -19,6 +19,8 @@
set -euo pipefail
+echo "1..16"
+
. $(dirname $0)/libtest.sh
# Exports OSTREE_SYSROOT so --sysroot not needed.
diff --git a/tests/test-admin-deploy-uboot.sh b/tests/test-admin-deploy-uboot.sh
index b998e082..d4c3a0db 100755
--- a/tests/test-admin-deploy-uboot.sh
+++ b/tests/test-admin-deploy-uboot.sh
@@ -20,9 +20,27 @@
set -euo pipefail
+echo "1..17"
+
. $(dirname $0)/libtest.sh
# Exports OSTREE_SYSROOT so --sysroot not needed.
setup_os_repository "archive-z2" "uboot"
. $(dirname $0)/admin-test.sh
+
+cd ${test_tmpdir}
+ln -s ../../boot/ osdata/usr/lib/ostree-boot
+cat << 'EOF' > osdata/boot/uEnv.txt
+loaduimage=load mmc ${bootpart} ${loadaddr} ${kernel_image}
+loadfdt=load mmc ${bootpart} ${fdtaddr} ${bootdir}${fdtfile}
+loadramdisk=load mmc ${bootpart} ${rdaddr} ${ramdisk_image}
+mmcargs=setenv bootargs $bootargs console=${console} ${optargs} root=${mmcroot} rootfstype=${mmcrootfstype}
+mmcboot=run loadramdisk; echo Booting from mmc ....; run mmcargs; bootz ${loadaddr} ${rdaddr} ${fdtaddr}
+EOF
+${CMD_PREFIX} ostree --repo=testos-repo commit --tree=dir=osdata/ -b testos/buildmaster/x86_64-runtime
+${CMD_PREFIX} ostree admin upgrade --os=testos
+assert_file_has_content sysroot/boot/uEnv.txt "loadfdt="
+assert_file_has_content sysroot/boot/uEnv.txt "kernel_image="
+
+echo "ok merging uEnv.txt files"