[meta-swupdate,RFC] bsp: extract initial environment from U-Boot binary
diff mbox series

Message ID 20190304153224.27788-1-kas@example.com
State New
Headers show
Series
  • [meta-swupdate,RFC] bsp: extract initial environment from U-Boot binary
Related show

Commit Message

Kas User March 4, 2019, 3:32 p.m. UTC
From: Stefano Babic <sbabic@denx.de>

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 ...1-Add-target-for-initial-environment.patch | 28 +++++++++++
 recipes-bsp/u-boot/u-boot%.bbappend           | 50 +++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 recipes-bsp/u-boot/files/0001-Add-target-for-initial-environment.patch
 create mode 100644 recipes-bsp/u-boot/u-boot%.bbappend

This is currently to show how to extract the environment from the
bootloader binary. The patch should first be posted to U-Boot ML.

Patch
diff mbox series

diff --git a/recipes-bsp/u-boot/files/0001-Add-target-for-initial-environment.patch b/recipes-bsp/u-boot/files/0001-Add-target-for-initial-environment.patch
new file mode 100644
index 0000000..8116eda
--- /dev/null
+++ b/recipes-bsp/u-boot/files/0001-Add-target-for-initial-environment.patch
@@ -0,0 +1,28 @@ 
+From 24611410d020c77547575ff9daaec601fdc25620 Mon Sep 17 00:00:00 2001
+From: Kas User <kas@example.com>
+Date: Tue, 19 Feb 2019 16:21:25 +0000
+Subject: [PATCH] Add target for initial environment
+
+Signed-off-by: Kas User <kas@example.com>
+---
+ Makefile | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/Makefile b/Makefile
+index 65cc49fa1f..6888deeab0 100644
+--- a/Makefile
++++ b/Makefile
+@@ -1718,6 +1718,10 @@ endif
+ 	$(build)=$(build-dir) $(@:.ko=.o)
+ 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
+ 
++u-boot-initial-env: u-boot.bin
++	$(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o 
++	sed --in-place -e 's/\x00/\x0A/g' $@
++
+ # Consistency checks
+ # ---------------------------------------------------------------------------
+ 
+-- 
+2.17.1
+
diff --git a/recipes-bsp/u-boot/u-boot%.bbappend b/recipes-bsp/u-boot/u-boot%.bbappend
new file mode 100644
index 0000000..ca8cbea
--- /dev/null
+++ b/recipes-bsp/u-boot/u-boot%.bbappend
@@ -0,0 +1,50 @@ 
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+SRC_URI_append = " file://0001-Add-target-for-initial-environment.patch"
+
+UBOOT_MAKE_TARGET_append = " u-boot-initial-env"
+PACKAGES += "${PN}-initial-env"
+FILES_${PN}-initial-env = "${sysconfdir}/u-boot-initial-env"
+
+do_install_append () {
+    if [ -n "${UBOOT_CONFIG}" ]
+    then
+        for config in ${UBOOT_MACHINE}; do
+            i=$(expr $i + 1);
+            for type in ${UBOOT_CONFIG}; do
+                j=$(expr $j + 1);
+                if [ $j -eq $i ]
+                then
+                    install -d ${D}/${sysconfdir}
+                    install -m 644 ${B}/${config}/u-boot-initial-env ${D}/${sysconfdir}/u-boot-initial-env
+                fi
+            done
+            unset  j
+        done
+        unset  i
+    else
+        install -d ${D}/${sysconfdir}
+        install -m 644 ${B}/u-boot-initial-env ${D}/${sysconfdir}/u-boot-initial-env
+    fi
+}
+
+do_deploy_append () {
+    if [ -n "${UBOOT_CONFIG}" ]
+    then
+        for config in ${UBOOT_MACHINE}; do
+            i=$(expr $i + 1);
+            for type in ${UBOOT_CONFIG}; do
+                j=$(expr $j + 1);
+                if [ $j -eq $i ]
+                then
+                    install -d ${DEPLOYDIR}
+                    install -m 644 ${B}/${config}/u-boot-initial-env ${DEPLOYDIR}/u-boot-initial-env-${type}
+                fi
+            done
+            unset  j
+        done
+        unset  i
+    else
+        install -d ${DEPLOYDIR}
+        install -m 644 ${B}/${config}/u-boot-initial-env ${DEPLOYDIR}/u-boot-initial-env
+   fi
+}