Hello Stefano,
Thank you for clarifying how machine can be overridden. I'm not that yet experienced as I'd wish with the Yocto project. Please see my updated patch file bellow. Check the do_swuimage:prepend part mainly. This is how I'd solve the search for machine specific image name. But you're sure more experienced and will think about a better solution.
Regarding the partitions part inside the description file, I'll need more guidance. Right now the A and B partitions are being dynamically created via ts-raspberrypi.wks, depending on the size of the rootfs. Why is there need for swupdate to change these partitions? Ususally user will add IMAGE_ROOTFS_EXTRA_SPACE so there there will be more space in case some new binaries/files will come with the update. How does the backup system works, if you reformat the old partition? For example when someone updates form A to B and B proves to be faulty, how can they switch back to A, when the A was changed?
commit 7c07ff30934997832f1859310957f5cec19d679d
Author: Jakub Maly <
mal...@proton.me>
Date: Wed May 24 12:32:50 2023 +0200
Switched to one common machine for rpi
diff --git a/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/files/
boot.cmd.in b/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/files/
boot.cmd.in
index 04cbd7b..8855f43 100644
--- a/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/files/
boot.cmd.in
+++ b/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/files/
boot.cmd.in
@@ -2,5 +2,5 @@ saveenv
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
if env exists rpipart;then echo Booting from mmcblk0p${rpipart};else setenv rpipart 2;echo rpipart not set, default to ${rpipart};fi
load mmc 0:${rpipart} ${kernel_addr_r} boot/@@KERNEL_IMAGETYPE@@
-setenv bootargs ${bootargs} root=/dev/mmcblk0p${rpipart}
+setenv bootargs "${bootargs} root=/dev/mmcblk0p${rpipart}"
@@KERNEL_BOOTCMD@@ ${kernel_addr_r} - ${fdt_addr}
diff --git a/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/rpi-u-boot-scr.bbappend b/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/rpi-u-boot-scr.bbappend
index ff7b487..cd1615f 100644
--- a/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/rpi-u-boot-scr.bbappend
+++ b/dynamic-layers/raspberrypi/recipes-bsp/rpi-uboot-scr/rpi-u-boot-scr.bbappend
@@ -1,3 +1,3 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
-COMPATIBLE = "raspberrypi3"
+COMPATIBLE = "raspberrypi3 raspberrypi4 raspberrypi4-64"
diff --git a/recipes-bsp/libubootenv/files/raspberrypi3/fw_env.config b/recipes-bsp/libubootenv/files/rpi/fw_env.config
similarity index 100%
rename from recipes-bsp/libubootenv/files/raspberrypi3/fw_env.config
rename to recipes-bsp/libubootenv/files/rpi/fw_env.config
diff --git a/recipes-core/base-files/base-files/raspberrypi3/fstab b/recipes-core/base-files/base-files/rpi/fstab
similarity index 87%
rename from recipes-core/base-files/base-files/raspberrypi3/fstab
rename to recipes-core/base-files/base-files/rpi/fstab
index 4f23935..7988617 100644
--- a/recipes-core/base-files/base-files/raspberrypi3/fstab
+++ b/recipes-core/base-files/base-files/rpi/fstab
@@ -1,4 +1,4 @@
-# stock fstab - you probably want to override this with a machine specific one
+# default fstab for rpi boards
/dev/root / auto defaults 1 1
proc /proc proc defaults 0 0
diff --git a/recipes-extended/images/
update-image.bb b/recipes-extended/images/
update-image.bb
index 1636ba6..d4dd8bd 100644
--- a/recipes-extended/images/
update-image.bb
+++ b/recipes-extended/images/
update-image.bb
@@ -17,3 +17,9 @@ IMAGE_DEPENDS = "core-image-full-cmdline"
SWUPDATE_IMAGES = "core-image-full-cmdline"
SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext4.gz"
+
+do_swuimage:prepend () {
+ machine = d.getVar("MACHINE", True)
+ workdir = d.getVar('WORKDIR', True)
+ os.system(f'sed -i "s#@MACHINE@#{machine}#g" {workdir}/sw-description')
+}
diff --git a/recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua b/recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua
deleted file mode 100644
index 09d1fb7..0000000
--- a/recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua
+++ /dev/null
@@ -1,85 +0,0 @@
-function os.capture(cmd)
- local f = assert(io.popen(cmd, 'r'))
- local s = assert(f:read('*a'))
- f:close()
- return s
-end
-
-function file_exists(name)
- local f=io.open(name,"r")
- if f~=nil then io.close(f) return true else return false end
-end
-
-function cmdexec(cmd)
- local ret, s, status = os.execute(cmd)
- if (status ~= 0) then
- return false, cmd .. " return with error"
- end
-
- return true,""
-end
-
-function preinst()
- local out
- local s1
- local ret
-
- local log = os.tmpname()
-
- local eMMC = "/dev/mmcblk0"
- ret = file_exists("/dev/mmcblk0")
-
- if (ret == false) then
- return false, "Cannot fine eMMC"
- end
-
- cmdexec("/usr/sbin/sfdisk -d " .. eMMC .. "> /tmp/dumppartitions")
-
- -- check if there are two identical partitions
- -- and create the second one if no available
- f = io.input("/tmp/dumppartitions")
- fo = io.output("/tmp/partitions")
- t = f:read()
- found = false
- while (t ~= nil) do
- j=0
- j=string.find(t, "/dev/mmcblk0p3")
- fo:write(t .. "\n")
- if (j == 1) then
- found=true
- break
- end
- j=string.find(t, "/dev/mmcblk0p2")
- if (j == 1) then
- start, size = string.match(t, "%a+%s*=%s*(%d+), size=%s*(%d+)")
- end
- t = f:read()
- end
-
- if (found) then
- f:close()
- fo:close()
- return true, out
- end
-
- start=start+size
- partitions = eMMC .. "p3 : start= " .. string.format("%d", start) .. ", size= " .. size .. ", type=83\n"
-
- fo:write(partitions)
- fo:close()
- f:close()
-
- out = os.capture("/usr/sbin/sfdisk --force " .. eMMC .. " < /tmp/partitions")
-
- -- use partprobe to inform the kernel of the new partitions
-
- cmdexec("/usr/sbin/partprobe " .. eMMC)
-
- return true, out
-end
-
-function postinst()
- local out = "Post installed script called"
-
- return true, out
-end
diff --git a/recipes-extended/images/update-image/raspberrypi3/sw-description b/recipes-extended/images/update-image/raspberrypi3/sw-description
deleted file mode 100644
index f279d1a..0000000
--- a/recipes-extended/images/update-image/raspberrypi3/sw-description
+++ /dev/null
@@ -1,55 +0,0 @@
-software =
-{
- version = "0.1.0";
-
- raspberrypi3 = {
- hardware-compatibility: [ "1.0"];
- stable : {
- copy1 : {
- images: (
- {
- filename = "core-image-full-cmdline-raspberrypi3.ext4.gz";
- type = "raw";
- compressed = "zlib";
- device = "/dev/mmcblk0p2";
- }
- );
- scripts: (
- {
- filename = "emmcsetup.lua";
- type = "lua";
- }
- );
- uboot: (
- {
- name = "rpipart";
- value = "2";
- }
- );
-
- };
- copy2 : {
- images: (
- {
- filename = "core-image-full-cmdline-raspberrypi3.ext4.gz";
- type = "raw";
- compressed = "zlib";
- device = "/dev/mmcblk0p3";
- }
- );
- scripts: (
- {
- filename = "emmcsetup.lua";
- type = "lua";
- }
- );
- uboot: (
- {
- name = "rpipart";
- value = "3";
- }
- );
- };
- };
- }
-}
diff --git a/recipes-extended/images/update-image/raspberrypi3/sw-description.embscript b/recipes-extended/images/update-image/raspberrypi3/sw-description.embscript
deleted file mode 100644
index 7cf781f..0000000
--- a/recipes-extended/images/update-image/raspberrypi3/sw-description.embscript
+++ /dev/null
@@ -1,145 +0,0 @@
-software =
-{
- version = "0.1.0";
-
- raspberrypi3 = {
-
- embedded-script ="
---[[
- SWUpdate Embedded Script Example
- Copyright (C) 2017, Stefano Babic
- Description:
- This is just an example how to integrate an embedded script in sw-description
- The script is first parsed, be sure to escape double quotes
- and use double quotes just when they are strictly required.
- The script simply reads from a GPIO, and returns false if this GPIO
- is set. That means:
- GPIO(x)=0 ==> SWUpdate installs the SWU
- GPIO(x)=1 ==> SWUpdate stops returning an error
-]]
--- Include swupdate library to use TRACE / ERROR
-require (\"swupdate\")
-
-INPUT = 1
-OUTPUT = 0
-
---[[
- Some functions are simply retrieved from LUA examples
- see book 'Programming in Lua' or some snipset from internet.
-]]
-
-function file_exists(filename)
- local file=io.open(filename,'r')
- if file~=nil then io.close(file) return true else return false end
-end
-
-function writeToFile (filename, data)
- local file=io.open(filename, 'w')
- file:write(data)
- file:close()
-end
-
-function readFromFile (filename)
- if file_exists(filename) then
- local file=io.open(filename, 'r')
- local data = file:read(1)
- file:close()
- return data
- else
- return \"\"
- end
-end
-
-function pinMode(pin, mode)
- local gpio_path = '/sys/class/gpio/'
- local gpio_direction = gpio_path..'gpio'..pin..'/direction'
- local gpio_export = gpio_path..'export'
-
- if not file_exists(gpio_direction) then
- writeToFile(gpio_export,pin)
- end
-
- if mode==INPUT then
- writeToFile(gpio_direction, 'in')
- else
- writeToFile(gpio_direction, 'out')
- end
-end
-
-function digitalRead(pin)
- value = readFromFile('/sys/class/gpio/gpio'..pin..'/value')
- return tonumber(value)
-end
-
-function allowInstall(image)
-
- -- Completely unuseful, but it is to show how to get values from image
-
- for k,l in pairs(image) do
- swupdate.trace(\"image[\" .. tostring(k) .. \"] = \" .. tostring(l))
- end
-
- -- Read GPIO21, that means pin 40 on the Header
- pinMode(21,INPUT)
- val=digitalRead(21)
- if (val == 0) then
- swupdate.trace(\"Updated allowed: go on !\")
- return true, image
- else
- swupdate.trace(\"Updated forbidden: STOP !\")
- return false, image
- end
-end ";
-
- hardware-compatibility: [ "1.0"];
- stable : {
- copy1 : {
- images: (
- {
- filename = "core-image-full-cmdline-raspberrypi3.ext4.gz";
- type = "raw";
- compressed = "zlib";
- device = "/dev/mmcblk0p2";
- hook = "allowInstall";
- }
- );
- scripts: (
- {
- filename = "emmcsetup.lua";
- type = "lua";
- }
- );
- uboot: (
- {
- name = "rpipart";
- value = "2";
- }
- );
-
- };
- copy2 : {
- images: (
- {
- filename = "core-image-full-cmdline-raspberrypi3.ext4.gz";
- type = "raw";
- compressed = "zlib";
- device = "/dev/mmcblk0p3";
- hook = "allowInstall";
- }
- );
- scripts: (
- {
- filename = "emmcsetup.lua";
- type = "lua";
- }
- );
- uboot: (
- {
- name = "rpipart";
- value = "3";
- }
- );
- };
- };
- }
-}
diff --git a/recipes-extended/images/update-image/rpi/emmcsetup.lua b/recipes-extended/images/update-image/rpi/emmcsetup.lua
new file mode 100644
index 0000000..e69de29
diff --git a/recipes-extended/images/update-image/rpi/sw-description b/recipes-extended/images/update-image/rpi/sw-description
new file mode 100644
index 0000000..c28ed3d
--- /dev/null
+++ b/recipes-extended/images/update-image/rpi/sw-description
@@ -0,0 +1,52 @@
+software =
+{
+ version = "0.1.0";
+
+ raspberrypi = {
+ hardware-compatibility: [ "1.0"];
+ stable : {
+ copy1 : {
+ images: (
+ {
+ filename = "core-image-full-cmdline-@MACHINE@.ext4.gz";
+ type = "raw";
+ compressed = "zlib";
+ device = "/dev/mmcblk0p2";
+ sha256 = "$swupdate_get_sha256(core-image-full-cmdline-@MACHINE@.ext4.gz)";
+ }
+ );
+ bootenv: (
+ {
+ name = "rpipart";
+ value = "2";
+ },
+ {
+ name = "ustate";
+ value = "1";
+ }
+ );
+ };
+ copy2 : {
+ images: (
+ {
+ filename = "core-image-full-cmdline-@MACHINE@.ext4.gz";
+ type = "raw";
+ compressed = "zlib";
+ device = "/dev/mmcblk0p3";
+ sha256 = "$swupdate_get_sha256(core-image-full-cmdline-@MACHINE@.ext4.gz)";
+ }
+ );
+ bootenv: (
+ {
+ name = "rpipart";
+ value = "3";
+ },
+ {
+ name = "ustate";
+ value = "1";
+ }
+ );
+ };
+ };
+ }
+}
diff --git a/recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg b/recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg
deleted file mode 100644
index 5671fe3..0000000
--- a/recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg
+++ /dev/null
@@ -1,47 +0,0 @@
-globals :
-{
-
- verbose = true;
- loglevel = 5;
- syslog = true;
- /* public-key-file = "test.pem";*/
-};
-
-download :
-{
- retries = 3;
- timeout = 1800;
-};
-
-identify : (
- { name = "raspberryPI3"; value = "1.0"; }
-);
-
-suricatta :
-{
-
- tenant = "default";
- id = "raspberrypi3";
- confirm = 0;
- url = "
http://paperina2:8280";
- polldelay = 60;
- nocheckcert = true;
- retry = 4;
- retrywait = 200;
- loglevel = 10;
- userid = 0;
- groupid = 0;
- max_artifacts = 1;
-/*
- cafile = "/etc/ssl/cafile";
- sslkey = "/etc/ssl/sslkey";
- sslcert = "/etc/ssl/sslcert";
-*/
-};
-
-webserver :
-{
- document_root = "/www";
- userid = 0;
- groupid = 0;
-};
diff --git a/recipes-support/swupdate/swupdate/raspberrypi3/09-swupdate-args b/recipes-support/swupdate/swupdate/rpi/09-swupdate-args
similarity index 69%
rename from recipes-support/swupdate/swupdate/raspberrypi3/09-swupdate-args
rename to recipes-support/swupdate/swupdate/rpi/09-swupdate-args
index 243aded..2f9c2ef 100644
--- a/recipes-support/swupdate/swupdate/raspberrypi3/09-swupdate-args
+++ b/recipes-support/swupdate/swupdate/rpi/09-swupdate-args
@@ -7,6 +7,10 @@ else
fi
state=`fw_printenv ustate | cut -f 2 -d'='`
+if [ -z "$state" ];then
+ fw_setenv ustate 1
+ state=`fw_printenv ustate | cut -f 2 -d'='`
+fi
if [ $state == 1 ];then
SWUPDATE_SURICATTA_ARGS="-c 2"
else
@@ -19,4 +23,4 @@ else
CFGFILE="/etc/swupdate.cfg"
fi
-SWUPDATE_ARGS="-H raspberrypi3:1.0 ${selection} -f ${CFGFILE}"
+SWUPDATE_ARGS="-H raspberrypi:1.0 ${selection} -p 'reboot' -f ${CFGFILE}"
diff --git a/recipes-support/swupdate/swupdate/raspberrypi3/defconfig b/recipes-support/swupdate/swupdate/rpi/defconfig
similarity index 98%
rename from recipes-support/swupdate/swupdate/raspberrypi3/defconfig
rename to recipes-support/swupdate/swupdate/rpi/defconfig
index fd8ce63..03cfd7e 100644
--- a/recipes-support/swupdate/swupdate/raspberrypi3/defconfig
+++ b/recipes-support/swupdate/swupdate/rpi/defconfig
@@ -59,7 +59,7 @@ CONFIG_DOWNLOAD=y
# CONFIG_DOWNLOAD_SSL is not set
CONFIG_CHANNEL_CURL=y
CONFIG_HASH_VERIFY=y
-# CONFIG_SIGNED_IMAGES is not set
+CONFIG_SIGNED_IMAGES=y
CONFIG_ENCRYPTED_IMAGES=y
CONFIG_SURICATTA=y
diff --git a/recipes-support/swupdate/swupdate/rpi/swupdate.cfg b/recipes-support/swupdate/swupdate/rpi/swupdate.cfg
new file mode 100644
index 0000000..4b8a582
--- /dev/null
+++ b/recipes-support/swupdate/swupdate/rpi/swupdate.cfg
@@ -0,0 +1,41 @@
+globals :
+{
+ verbose = true;
+ loglevel = 5;
+ syslog = true;
+ public-key-file = "@PUBKEY@";
+};
+
+download :
+{
+ retries = 3;
+ timeout = 1800;
+};
+
+identify : (
+ { name = "raspberryPI"; value = "1.0"; }
Best,
Jakub
Sent with Proton Mail secure email.
------- Original Message -------