diff mbox series

[meta-swupdate-boards,V2] Switched to one common machine for rpi

Message ID 20230525122023.8944-1-jakub.maly@tietoevry.com
State Accepted
Headers show
Series [meta-swupdate-boards,V2] Switched to one common machine for rpi | expand

Commit Message

Jakub Maly May 25, 2023, 12:20 p.m. UTC
From: Jakub Maly <maly.smtp@gmail.com>

Signed-off-by: Jakub Maly <jakub.maly@tietoevry.com>
---
 .../rpi-uboot-scr/files/boot.cmd.in           |   2 +-
 .../rpi-uboot-scr/rpi-u-boot-scr.bbappend     |   2 +-
 .../files/{raspberrypi3 => rpi}/fw_env.config |   0
 .../base-files/{raspberrypi3 => rpi}/fstab    |   2 +-
 .../update-image/raspberrypi3/emmcsetup.lua   |  85 ----------
 .../update-image/raspberrypi3/sw-description  |  55 -------
 .../raspberrypi3/sw-description.embscript     | 145 ------------------
 .../images/update-image/rpi/emmcsetup.lua     |   0
 .../images/update-image/rpi/sw-description    |  52 +++++++
 .../swupdate/raspberrypi3/swupdate.cfg        |  47 ------
 .../{raspberrypi3 => rpi}/09-swupdate-args    |   6 +-
 .../swupdate/{raspberrypi3 => rpi}/defconfig  |   2 +-
 .../swupdate/swupdate/rpi/swupdate.cfg        |  41 +++++
 recipes-support/swupdate/swupdate_%.bbappend  |   1 +
 14 files changed, 103 insertions(+), 337 deletions(-)
 rename recipes-bsp/libubootenv/files/{raspberrypi3 => rpi}/fw_env.config (100%)
 rename recipes-core/base-files/base-files/{raspberrypi3 => rpi}/fstab (87%)
 delete mode 100644 recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua
 delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description
 delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description.embscript
 create mode 100644 recipes-extended/images/update-image/rpi/emmcsetup.lua
 create mode 100644 recipes-extended/images/update-image/rpi/sw-description
 delete mode 100644 recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg
 rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/09-swupdate-args (69%)
 rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/defconfig (98%)
 create mode 100644 recipes-support/swupdate/swupdate/rpi/swupdate.cfg

Comments

Stefano Babic May 25, 2023, 12:29 p.m. UTC | #1
Hi Jakub,

look good ! I will apply it.

Best regards,
Stefano

On 25.05.23 14:20, Jakub Maly wrote:
> From: Jakub Maly <maly.smtp@gmail.com>
> 
> Signed-off-by: Jakub Maly <jakub.maly@tietoevry.com>
> ---
>   .../rpi-uboot-scr/files/boot.cmd.in           |   2 +-
>   .../rpi-uboot-scr/rpi-u-boot-scr.bbappend     |   2 +-
>   .../files/{raspberrypi3 => rpi}/fw_env.config |   0
>   .../base-files/{raspberrypi3 => rpi}/fstab    |   2 +-
>   .../update-image/raspberrypi3/emmcsetup.lua   |  85 ----------
>   .../update-image/raspberrypi3/sw-description  |  55 -------
>   .../raspberrypi3/sw-description.embscript     | 145 ------------------
>   .../images/update-image/rpi/emmcsetup.lua     |   0
>   .../images/update-image/rpi/sw-description    |  52 +++++++
>   .../swupdate/raspberrypi3/swupdate.cfg        |  47 ------
>   .../{raspberrypi3 => rpi}/09-swupdate-args    |   6 +-
>   .../swupdate/{raspberrypi3 => rpi}/defconfig  |   2 +-
>   .../swupdate/swupdate/rpi/swupdate.cfg        |  41 +++++
>   recipes-support/swupdate/swupdate_%.bbappend  |   1 +
>   14 files changed, 103 insertions(+), 337 deletions(-)
>   rename recipes-bsp/libubootenv/files/{raspberrypi3 => rpi}/fw_env.config (100%)
>   rename recipes-core/base-files/base-files/{raspberrypi3 => rpi}/fstab (87%)
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description.embscript
>   create mode 100644 recipes-extended/images/update-image/rpi/emmcsetup.lua
>   create mode 100644 recipes-extended/images/update-image/rpi/sw-description
>   delete mode 100644 recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg
>   rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/09-swupdate-args (69%)
>   rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/defconfig (98%)
>   create mode 100644 recipes-support/swupdate/swupdate/rpi/swupdate.cfg
> 
> 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/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..e584344
> --- /dev/null
> +++ b/recipes-extended/images/update-image/rpi/sw-description
> @@ -0,0 +1,52 @@
> +software =
> +{
> +	version = "0.1.0";
> +
> +	@@MACHINE@@ = {
> +		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..253de4c 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 @MACHINE@: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"; }
> +);
> +
> +suricatta :
> +{
> +	enable			= true;
> +	tenant			= "default";
> +	id				= "@TARGETID@";
> +	url 			= "@PROTOCOL@://@HOSTNAME@:@PORT@";
> +	polldelay		= 60;
> +	nocheckcert		= true;
> +	retry			= 4;
> +	retrywait		= 200;
> +	loglevel		= 10;
> +	userid			= 0;
> +	groupid			= 0;
> +	targettoken		= "@TARGETTOKEN@";
> +};
> +
> +webserver :
> +{
> +	document_root	= "/www";
> +	userid			= 0;
> +	groupid			= 0;
> +	timeout			= 20;
> +};
> diff --git a/recipes-support/swupdate/swupdate_%.bbappend b/recipes-support/swupdate/swupdate_%.bbappend
> index b6d09c5..be4bbd8 100644
> --- a/recipes-support/swupdate/swupdate_%.bbappend
> +++ b/recipes-support/swupdate/swupdate_%.bbappend
> @@ -11,6 +11,7 @@ SRC_URI:append:beaglebone-yocto = " file://10-remove-force-ro"
>   
>   do_install:append() {
>       install -m 0644 ${WORKDIR}/09-swupdate-args ${D}${libdir}/swupdate/conf.d/
> +    sed -i "s#@MACHINE@#${MACHINE}#g" ${D}${libdir}/swupdate/conf.d/09-swupdate-args
>   
>       install -d ${D}${sysconfdir}
>       install -m 644 ${WORKDIR}/swupdate.cfg ${D}${sysconfdir}
Stefano Babic May 25, 2023, 7:29 p.m. UTC | #2
Applied, thanks !

Best regards,
Stefano Babic

On 25.05.23 14:20, Jakub Maly wrote:
> From: Jakub Maly <maly.smtp@gmail.com>
> 
> Signed-off-by: Jakub Maly <jakub.maly@tietoevry.com>
> ---
>   .../rpi-uboot-scr/files/boot.cmd.in           |   2 +-
>   .../rpi-uboot-scr/rpi-u-boot-scr.bbappend     |   2 +-
>   .../files/{raspberrypi3 => rpi}/fw_env.config |   0
>   .../base-files/{raspberrypi3 => rpi}/fstab    |   2 +-
>   .../update-image/raspberrypi3/emmcsetup.lua   |  85 ----------
>   .../update-image/raspberrypi3/sw-description  |  55 -------
>   .../raspberrypi3/sw-description.embscript     | 145 ------------------
>   .../images/update-image/rpi/emmcsetup.lua     |   0
>   .../images/update-image/rpi/sw-description    |  52 +++++++
>   .../swupdate/raspberrypi3/swupdate.cfg        |  47 ------
>   .../{raspberrypi3 => rpi}/09-swupdate-args    |   6 +-
>   .../swupdate/{raspberrypi3 => rpi}/defconfig  |   2 +-
>   .../swupdate/swupdate/rpi/swupdate.cfg        |  41 +++++
>   recipes-support/swupdate/swupdate_%.bbappend  |   1 +
>   14 files changed, 103 insertions(+), 337 deletions(-)
>   rename recipes-bsp/libubootenv/files/{raspberrypi3 => rpi}/fw_env.config (100%)
>   rename recipes-core/base-files/base-files/{raspberrypi3 => rpi}/fstab (87%)
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/emmcsetup.lua
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description
>   delete mode 100644 recipes-extended/images/update-image/raspberrypi3/sw-description.embscript
>   create mode 100644 recipes-extended/images/update-image/rpi/emmcsetup.lua
>   create mode 100644 recipes-extended/images/update-image/rpi/sw-description
>   delete mode 100644 recipes-support/swupdate/swupdate/raspberrypi3/swupdate.cfg
>   rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/09-swupdate-args (69%)
>   rename recipes-support/swupdate/swupdate/{raspberrypi3 => rpi}/defconfig (98%)
>   create mode 100644 recipes-support/swupdate/swupdate/rpi/swupdate.cfg
> 
> 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/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..e584344
> --- /dev/null
> +++ b/recipes-extended/images/update-image/rpi/sw-description
> @@ -0,0 +1,52 @@
> +software =
> +{
> +	version = "0.1.0";
> +
> +	@@MACHINE@@ = {
> +		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..253de4c 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 @MACHINE@: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"; }
> +);
> +
> +suricatta :
> +{
> +	enable			= true;
> +	tenant			= "default";
> +	id				= "@TARGETID@";
> +	url 			= "@PROTOCOL@://@HOSTNAME@:@PORT@";
> +	polldelay		= 60;
> +	nocheckcert		= true;
> +	retry			= 4;
> +	retrywait		= 200;
> +	loglevel		= 10;
> +	userid			= 0;
> +	groupid			= 0;
> +	targettoken		= "@TARGETTOKEN@";
> +};
> +
> +webserver :
> +{
> +	document_root	= "/www";
> +	userid			= 0;
> +	groupid			= 0;
> +	timeout			= 20;
> +};
> diff --git a/recipes-support/swupdate/swupdate_%.bbappend b/recipes-support/swupdate/swupdate_%.bbappend
> index b6d09c5..be4bbd8 100644
> --- a/recipes-support/swupdate/swupdate_%.bbappend
> +++ b/recipes-support/swupdate/swupdate_%.bbappend
> @@ -11,6 +11,7 @@ SRC_URI:append:beaglebone-yocto = " file://10-remove-force-ro"
>   
>   do_install:append() {
>       install -m 0644 ${WORKDIR}/09-swupdate-args ${D}${libdir}/swupdate/conf.d/
> +    sed -i "s#@MACHINE@#${MACHINE}#g" ${D}${libdir}/swupdate/conf.d/09-swupdate-args
>   
>       install -d ${D}${sysconfdir}
>       install -m 644 ${WORKDIR}/swupdate.cfg ${D}${sysconfdir}
diff mbox series

Patch

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/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..e584344
--- /dev/null
+++ b/recipes-extended/images/update-image/rpi/sw-description
@@ -0,0 +1,52 @@ 
+software =
+{
+	version = "0.1.0";
+
+	@@MACHINE@@ = {
+		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..253de4c 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 @MACHINE@: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"; }
+);
+
+suricatta :
+{
+	enable			= true;
+	tenant			= "default";
+	id				= "@TARGETID@";
+	url 			= "@PROTOCOL@://@HOSTNAME@:@PORT@";
+	polldelay		= 60;
+	nocheckcert		= true;
+	retry			= 4;
+	retrywait		= 200;
+	loglevel		= 10;
+	userid			= 0;
+	groupid			= 0;
+	targettoken		= "@TARGETTOKEN@";
+};
+
+webserver :
+{
+	document_root	= "/www";
+	userid			= 0;
+	groupid			= 0;
+	timeout			= 20;
+};
diff --git a/recipes-support/swupdate/swupdate_%.bbappend b/recipes-support/swupdate/swupdate_%.bbappend
index b6d09c5..be4bbd8 100644
--- a/recipes-support/swupdate/swupdate_%.bbappend
+++ b/recipes-support/swupdate/swupdate_%.bbappend
@@ -11,6 +11,7 @@  SRC_URI:append:beaglebone-yocto = " file://10-remove-force-ro"
 
 do_install:append() {
     install -m 0644 ${WORKDIR}/09-swupdate-args ${D}${libdir}/swupdate/conf.d/
+    sed -i "s#@MACHINE@#${MACHINE}#g" ${D}${libdir}/swupdate/conf.d/09-swupdate-args
 
     install -d ${D}${sysconfdir}
     install -m 644 ${WORKDIR}/swupdate.cfg ${D}${sysconfdir}