diff mbox series

[meta-arago,scarthgap,RFC,3/4] swupdate: add bootloader support

Message ID 20251202111603.1616989-4-anshuld@ti.com
State New
Headers show
Series Add support for SWUpdate | expand

Commit Message

Anshul Dalal Dec. 2, 2025, 11:16 a.m. UTC
U-Boot uses the 'bootpart' env variable to configure the rootfs for the
kernel at boot. The BACKUP_REG0 MMR is also used to store bootcount as
per U-Boot requirements[1].

After each reset, U-Boot increments the bootcount and it's reset to 0 by
the swupdate service indicating a successful boot. If the kernel panics
however (eg. if the update failed), the bootcount is never reset and
keeps on getting incremented by U-Boot until it reaches certain
threshold after which U-Boot switches to the other non-updated partition
to ensure a successful boot.

This patch adds support for the same to the final .swu image generated
by the update-image recipe.

[1]: https://docs.u-boot.org/en/latest/api/bootcount.html

Signed-off-by: Anshul Dalal <anshuld@ti.com>
---
 .../recipes-swupdate/images/files/sw-description     | 12 ++++++++++++
 .../recipes-swupdate/libubootenv/files/fw_env.config |  5 +++++
 .../libubootenv/libubootenv_%.bbappend               | 10 ++++++++++
 .../recipes-swupdate/swupdate/files/defconfig        |  2 ++
 .../recipes-swupdate/swupdate/files/swupdate.sh      |  4 ++++
 .../recipes-swupdate/swupdate/swupdate_%.bbappend    |  2 ++
 6 files changed, 35 insertions(+)
 create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
 create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend

Comments

Andrew Davis Dec. 2, 2025, 7:23 p.m. UTC | #1
On 12/2/25 5:16 AM, Anshul Dalal via lists.yoctoproject.org wrote:
> U-Boot uses the 'bootpart' env variable to configure the rootfs for the
> kernel at boot. The BACKUP_REG0 MMR is also used to store bootcount as
> per U-Boot requirements[1].
> 
> After each reset, U-Boot increments the bootcount and it's reset to 0 by
> the swupdate service indicating a successful boot. If the kernel panics
> however (eg. if the update failed), the bootcount is never reset and
> keeps on getting incremented by U-Boot until it reaches certain
> threshold after which U-Boot switches to the other non-updated partition
> to ensure a successful boot.
> 
> This patch adds support for the same to the final .swu image generated
> by the update-image recipe.
> 
> [1]: https://docs.u-boot.org/en/latest/api/bootcount.html
> 
> Signed-off-by: Anshul Dalal <anshuld@ti.com>
> ---
>   .../recipes-swupdate/images/files/sw-description     | 12 ++++++++++++
>   .../recipes-swupdate/libubootenv/files/fw_env.config |  5 +++++
>   .../libubootenv/libubootenv_%.bbappend               | 10 ++++++++++
>   .../recipes-swupdate/swupdate/files/defconfig        |  2 ++
>   .../recipes-swupdate/swupdate/files/swupdate.sh      |  4 ++++
>   .../recipes-swupdate/swupdate/swupdate_%.bbappend    |  2 ++
>   6 files changed, 35 insertions(+)
>   create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>   create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> 
> diff --git a/meta-arago-distro/recipes-swupdate/images/files/sw-description b/meta-arago-distro/recipes-swupdate/images/files/sw-description
> index 8dc4e2b2..241bc95c 100644
> --- a/meta-arago-distro/recipes-swupdate/images/files/sw-description
> +++ b/meta-arago-distro/recipes-swupdate/images/files/sw-description
> @@ -15,6 +15,12 @@ software =
>   						compressed = "zlib";
>   					},
>   				);
> +				uboot: (
> +					{
> +						name = "bootpart";
> +						value = "0:1";
> +					},
> +				);
>   			};
>   
>   			copy2 : {
> @@ -26,6 +32,12 @@ software =
>   						compressed = "zlib";
>   					},
>   				);
> +				uboot: (
> +					{
> +						name = "bootpart";
> +						value = "0:2";
> +					},
> +				);
>   			};
>   		};
>   	}
> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
> new file mode 100644
> index 00000000..57eec5fc
> --- /dev/null
> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
> @@ -0,0 +1,5 @@
> +# Describes the env location for U-Boot in the hw partition
> +# Second entry indicates redundant env
> +# Boot dev			Offset		Size
> +/dev/mmcblk0boot0	0x680000	0x20000
> +/dev/mmcblk0boot0	0x6a0000	0x20000
> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> new file mode 100644
> index 00000000..e3d142f2
> --- /dev/null
> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> @@ -0,0 +1,10 @@
> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
> +
> +SRC_URI:append = " file://fw_env.config"
> +
> +do_install:append() {
> +	install -d ${D}${sysconfdir}
> +	install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}
> +}
> +
> +FILES:${PN}:append = " ${sysconfdir}"
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> index b1362eaa..4a2d78c0 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> @@ -1,8 +1,10 @@
>   CONFIG_HW_COMPATIBILITY=y
>   # CONFIG_LUA is not set
>   # CONFIG_BOOTLOADER_NONE is not set
> +CONFIG_UBOOT=y
>   CONFIG_SYSTEMD=y
>   CONFIG_WEBSERVER=y
> +CONFIG_BOOTLOADERHANDLER=y
>   CONFIG_CFI=y
>   CONFIG_EMMC_HANDLER=y
>   CONFIG_RAW=y
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> index bb3a3593..2083062e 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> @@ -8,4 +8,8 @@ else
>   	SELECTION="-e stable,copy2"
>   fi
>   
> +# BACKUP_REG0 MMR on AM62x
> +UBOOT_BOOTCOUNT_ADDR=0x4301c100
> +
> +devmem2 $UBOOT_BOOTCOUNT_ADDR w 0

Yuck, magic memory locations and /dev/mem, I'm trying to get
rid of our dependence on /dev/mem in general so let's not add
to the problem. How about CONFIG_BOOTCOUNT_FS?

Or maybe store it in an EFI variable, look into efivarfs and
see if we can do something with that to allow usersapce access
to this count.

Andrew

>   swupdate -H @MACHINE@:1.0 ${SELECTION} -p 'reboot' -f /etc/swupdate.cfg -w "-r /www -p 8080"
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> index 0ce763f9..20f87435 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> @@ -2,6 +2,8 @@ inherit swupdate-lib
>   
>   FILESEXTRAPATHS:append := "${THISDIR}/files:"
>   
> +RDEPENDS:${PN} += "devmem2"
> +
>   FILES:${PN} += " \
>     ${SWUPDATE_HW_COMPATIBILITY_FILE} \
>   "
Yogesh Hegde Dec. 3, 2025, 5:58 a.m. UTC | #2
On 16:46-20251202, Anshul Dalal via lists.yoctoproject.org wrote:
> U-Boot uses the 'bootpart' env variable to configure the rootfs for the
> kernel at boot. The BACKUP_REG0 MMR is also used to store bootcount as
> per U-Boot requirements[1].
> 
> After each reset, U-Boot increments the bootcount and it's reset to 0 by
> the swupdate service indicating a successful boot. If the kernel panics
> however (eg. if the update failed), the bootcount is never reset and
> keeps on getting incremented by U-Boot until it reaches certain
> threshold after which U-Boot switches to the other non-updated partition
> to ensure a successful boot.
> 
> This patch adds support for the same to the final .swu image generated
> by the update-image recipe.
> 
> [1]: https://docs.u-boot.org/en/latest/api/bootcount.html
> 
> Signed-off-by: Anshul Dalal <anshuld@ti.com>
> ---
>  .../recipes-swupdate/images/files/sw-description     | 12 ++++++++++++
>  .../recipes-swupdate/libubootenv/files/fw_env.config |  5 +++++
>  .../libubootenv/libubootenv_%.bbappend               | 10 ++++++++++
>  .../recipes-swupdate/swupdate/files/defconfig        |  2 ++
>  .../recipes-swupdate/swupdate/files/swupdate.sh      |  4 ++++
>  .../recipes-swupdate/swupdate/swupdate_%.bbappend    |  2 ++
>  6 files changed, 35 insertions(+)
>  create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>  create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> 
> diff --git a/meta-arago-distro/recipes-swupdate/images/files/sw-description b/meta-arago-distro/recipes-swupdate/images/files/sw-description
> index 8dc4e2b2..241bc95c 100644
> --- a/meta-arago-distro/recipes-swupdate/images/files/sw-description
> +++ b/meta-arago-distro/recipes-swupdate/images/files/sw-description
> @@ -15,6 +15,12 @@ software =
>  						compressed = "zlib";
>  					},
>  				);
> +				uboot: (
> +					{
> +						name = "bootpart";
> +						value = "0:1";
> +					},
> +				);
>  			};
>  
>  			copy2 : {
> @@ -26,6 +32,12 @@ software =
>  						compressed = "zlib";
>  					},
>  				);
> +				uboot: (
> +					{
> +						name = "bootpart";
> +						value = "0:2";
> +					},
> +				);
>  			};
>  		};
>  	}
> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
> new file mode 100644
> index 00000000..57eec5fc
> --- /dev/null
> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
> @@ -0,0 +1,5 @@
> +# Describes the env location for U-Boot in the hw partition
> +# Second entry indicates redundant env
> +# Boot dev			Offset		Size
> +/dev/mmcblk0boot0	0x680000	0x20000
> +/dev/mmcblk0boot0	0x6a0000	0x20000

Does this fw_env.config work for all machines?  

> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> new file mode 100644
> index 00000000..e3d142f2
> --- /dev/null
> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
> @@ -0,0 +1,10 @@
> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
> +
> +SRC_URI:append = " file://fw_env.config"

If this config is not tested on all boards, it would be best to only append it
to the machines that are tested.

> +
> +do_install:append() {
> +	install -d ${D}${sysconfdir}
> +	install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}
> +}
> +
> +FILES:${PN}:append = " ${sysconfdir}"
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> index b1362eaa..4a2d78c0 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
> @@ -1,8 +1,10 @@
>  CONFIG_HW_COMPATIBILITY=y
>  # CONFIG_LUA is not set
>  # CONFIG_BOOTLOADER_NONE is not set
> +CONFIG_UBOOT=y
>  CONFIG_SYSTEMD=y
>  CONFIG_WEBSERVER=y
> +CONFIG_BOOTLOADERHANDLER=y
>  CONFIG_CFI=y
>  CONFIG_EMMC_HANDLER=y
>  CONFIG_RAW=y
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> index bb3a3593..2083062e 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
> @@ -8,4 +8,8 @@ else
>  	SELECTION="-e stable,copy2"
>  fi
>  
> +# BACKUP_REG0 MMR on AM62x
> +UBOOT_BOOTCOUNT_ADDR=0x4301c100
> +
> +devmem2 $UBOOT_BOOTCOUNT_ADDR w 0

Using devmem2 might be a bad idea. Consider using fw_setenv [1] to set
the bootcount to 0. 

[1] https://manpages.debian.org/testing/libubootenv-tool/fw_setenv.8.en.html

-- Yogesh 

>  swupdate -H @MACHINE@:1.0 ${SELECTION} -p 'reboot' -f /etc/swupdate.cfg -w "-r /www -p 8080"
> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> index 0ce763f9..20f87435 100644
> --- a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> +++ b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
> @@ -2,6 +2,8 @@ inherit swupdate-lib
>  
>  FILESEXTRAPATHS:append := "${THISDIR}/files:"
>  
> +RDEPENDS:${PN} += "devmem2"
> +
>  FILES:${PN} += " \
>    ${SWUPDATE_HW_COMPATIBILITY_FILE} \
>  "
> -- 
> 2.52.0
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#16850): https://lists.yoctoproject.org/g/meta-arago/message/16850
> Mute This Topic: https://lists.yoctoproject.org/mt/116574476/9980049
> Group Owner: meta-arago+owner@lists.yoctoproject.org
> Unsubscribe: https://lists.yoctoproject.org/g/meta-arago/unsub [y-hegde@ti.com]
> -=-=-=-=-=-=-=-=-=-=-=-
> 
>
Anshul Dalal Dec. 3, 2025, 10:16 a.m. UTC | #3
On Wed Dec 3, 2025 at 12:53 AM IST, Andrew Davis wrote:
> On 12/2/25 5:16 AM, Anshul Dalal via lists.yoctoproject.org wrote:
>> U-Boot uses the 'bootpart' env variable to configure the rootfs for the
>> kernel at boot. The BACKUP_REG0 MMR is also used to store bootcount as
>> per U-Boot requirements[1].
>> 
>> After each reset, U-Boot increments the bootcount and it's reset to 0 by
>> the swupdate service indicating a successful boot. If the kernel panics
>> however (eg. if the update failed), the bootcount is never reset and
>> keeps on getting incremented by U-Boot until it reaches certain
>> threshold after which U-Boot switches to the other non-updated partition
>> to ensure a successful boot.
>> 
>> This patch adds support for the same to the final .swu image generated
>> by the update-image recipe.
>> 
>> [1]: https://docs.u-boot.org/en/latest/api/bootcount.html
>> 
>> Signed-off-by: Anshul Dalal <anshuld@ti.com>
>> ---
>>   .../recipes-swupdate/images/files/sw-description     | 12 ++++++++++++
>>   .../recipes-swupdate/libubootenv/files/fw_env.config |  5 +++++
>>   .../libubootenv/libubootenv_%.bbappend               | 10 ++++++++++
>>   .../recipes-swupdate/swupdate/files/defconfig        |  2 ++
>>   .../recipes-swupdate/swupdate/files/swupdate.sh      |  4 ++++
>>   .../recipes-swupdate/swupdate/swupdate_%.bbappend    |  2 ++
>>   6 files changed, 35 insertions(+)
>>   create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>>   create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> 
>> diff --git a/meta-arago-distro/recipes-swupdate/images/files/sw-description b/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> index 8dc4e2b2..241bc95c 100644
>> --- a/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> +++ b/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> @@ -15,6 +15,12 @@ software =
>>   						compressed = "zlib";
>>   					},
>>   				);
>> +				uboot: (
>> +					{
>> +						name = "bootpart";
>> +						value = "0:1";
>> +					},
>> +				);
>>   			};
>>   
>>   			copy2 : {
>> @@ -26,6 +32,12 @@ software =
>>   						compressed = "zlib";
>>   					},
>>   				);
>> +				uboot: (
>> +					{
>> +						name = "bootpart";
>> +						value = "0:2";
>> +					},
>> +				);
>>   			};
>>   		};
>>   	}
>> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>> new file mode 100644
>> index 00000000..57eec5fc
>> --- /dev/null
>> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>> @@ -0,0 +1,5 @@
>> +# Describes the env location for U-Boot in the hw partition
>> +# Second entry indicates redundant env
>> +# Boot dev			Offset		Size
>> +/dev/mmcblk0boot0	0x680000	0x20000
>> +/dev/mmcblk0boot0	0x6a0000	0x20000
>> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> new file mode 100644
>> index 00000000..e3d142f2
>> --- /dev/null
>> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> @@ -0,0 +1,10 @@
>> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
>> +
>> +SRC_URI:append = " file://fw_env.config"
>> +
>> +do_install:append() {
>> +	install -d ${D}${sysconfdir}
>> +	install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}
>> +}
>> +
>> +FILES:${PN}:append = " ${sysconfdir}"
>> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> index b1362eaa..4a2d78c0 100644
>> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> @@ -1,8 +1,10 @@
>>   CONFIG_HW_COMPATIBILITY=y
>>   # CONFIG_LUA is not set
>>   # CONFIG_BOOTLOADER_NONE is not set
>> +CONFIG_UBOOT=y
>>   CONFIG_SYSTEMD=y
>>   CONFIG_WEBSERVER=y
>> +CONFIG_BOOTLOADERHANDLER=y
>>   CONFIG_CFI=y
>>   CONFIG_EMMC_HANDLER=y
>>   CONFIG_RAW=y
>> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> index bb3a3593..2083062e 100644
>> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> @@ -8,4 +8,8 @@ else
>>   	SELECTION="-e stable,copy2"
>>   fi
>>   
>> +# BACKUP_REG0 MMR on AM62x
>> +UBOOT_BOOTCOUNT_ADDR=0x4301c100
>> +
>> +devmem2 $UBOOT_BOOTCOUNT_ADDR w 0
>
> Yuck, magic memory locations and /dev/mem, I'm trying to get
> rid of our dependence on /dev/mem in general so let's not add
> to the problem. How about CONFIG_BOOTCOUNT_FS?
>

As Yogesh suggested, it might be better to go with env since it's more
commonly used.

This would eliminate the need for devmem as well.

> Or maybe store it in an EFI variable, look into efivarfs and
> see if we can do something with that to allow usersapce access
> to this count.
>

The A/B rollback is already well supported with EFI (that's how CIP does
it for example), what we want to provide is redundancy for the entire
software stack including the bootloader. This RFC doesn't implement it
yet but this will be added in a later revision.

Regards,
Anshul

[snip]
Anshul Dalal Dec. 3, 2025, 10:23 a.m. UTC | #4
On Wed Dec 3, 2025 at 11:28 AM IST, Yogesh Hegde wrote:
> On 16:46-20251202, Anshul Dalal via lists.yoctoproject.org wrote:
>> U-Boot uses the 'bootpart' env variable to configure the rootfs for the
>> kernel at boot. The BACKUP_REG0 MMR is also used to store bootcount as
>> per U-Boot requirements[1].
>> 
>> After each reset, U-Boot increments the bootcount and it's reset to 0 by
>> the swupdate service indicating a successful boot. If the kernel panics
>> however (eg. if the update failed), the bootcount is never reset and
>> keeps on getting incremented by U-Boot until it reaches certain
>> threshold after which U-Boot switches to the other non-updated partition
>> to ensure a successful boot.
>> 
>> This patch adds support for the same to the final .swu image generated
>> by the update-image recipe.
>> 
>> [1]: https://docs.u-boot.org/en/latest/api/bootcount.html
>> 
>> Signed-off-by: Anshul Dalal <anshuld@ti.com>
>> ---
>>  .../recipes-swupdate/images/files/sw-description     | 12 ++++++++++++
>>  .../recipes-swupdate/libubootenv/files/fw_env.config |  5 +++++
>>  .../libubootenv/libubootenv_%.bbappend               | 10 ++++++++++
>>  .../recipes-swupdate/swupdate/files/defconfig        |  2 ++
>>  .../recipes-swupdate/swupdate/files/swupdate.sh      |  4 ++++
>>  .../recipes-swupdate/swupdate/swupdate_%.bbappend    |  2 ++
>>  6 files changed, 35 insertions(+)
>>  create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>>  create mode 100644 meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> 
>> diff --git a/meta-arago-distro/recipes-swupdate/images/files/sw-description b/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> index 8dc4e2b2..241bc95c 100644
>> --- a/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> +++ b/meta-arago-distro/recipes-swupdate/images/files/sw-description
>> @@ -15,6 +15,12 @@ software =
>>  						compressed = "zlib";
>>  					},
>>  				);
>> +				uboot: (
>> +					{
>> +						name = "bootpart";
>> +						value = "0:1";
>> +					},
>> +				);
>>  			};
>>  
>>  			copy2 : {
>> @@ -26,6 +32,12 @@ software =
>>  						compressed = "zlib";
>>  					},
>>  				);
>> +				uboot: (
>> +					{
>> +						name = "bootpart";
>> +						value = "0:2";
>> +					},
>> +				);
>>  			};
>>  		};
>>  	}
>> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>> new file mode 100644
>> index 00000000..57eec5fc
>> --- /dev/null
>> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
>> @@ -0,0 +1,5 @@
>> +# Describes the env location for U-Boot in the hw partition
>> +# Second entry indicates redundant env
>> +# Boot dev			Offset		Size
>> +/dev/mmcblk0boot0	0x680000	0x20000
>> +/dev/mmcblk0boot0	0x6a0000	0x20000
>
> Does this fw_env.config work for all machines?  
>

No, AM64x and J7200 make use of different offsets. Though it might make
sense to move the libubootenv configuration to meta-ti altogether with
the config under libubootenv/files/<SOC_OVERRIDE>/fw_env.config.

Since this config is not only useful for SWUpdate with arago but anybody
trying to make use fw_* tools on our platforms.

>> diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> new file mode 100644
>> index 00000000..e3d142f2
>> --- /dev/null
>> +++ b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
>> @@ -0,0 +1,10 @@
>> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
>> +
>> +SRC_URI:append = " file://fw_env.config"
>
> If this config is not tested on all boards, it would be best to only append it
> to the machines that are tested.
>

That's fair, perhaps we should error out on builds with untested
platforms with 'ti-swupdate' active.

>> +
>> +do_install:append() {
>> +	install -d ${D}${sysconfdir}
>> +	install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}
>> +}
>> +
>> +FILES:${PN}:append = " ${sysconfdir}"
>> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> index b1362eaa..4a2d78c0 100644
>> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
>> @@ -1,8 +1,10 @@
>>  CONFIG_HW_COMPATIBILITY=y
>>  # CONFIG_LUA is not set
>>  # CONFIG_BOOTLOADER_NONE is not set
>> +CONFIG_UBOOT=y
>>  CONFIG_SYSTEMD=y
>>  CONFIG_WEBSERVER=y
>> +CONFIG_BOOTLOADERHANDLER=y
>>  CONFIG_CFI=y
>>  CONFIG_EMMC_HANDLER=y
>>  CONFIG_RAW=y
>> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> index bb3a3593..2083062e 100644
>> --- a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> +++ b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
>> @@ -8,4 +8,8 @@ else
>>  	SELECTION="-e stable,copy2"
>>  fi
>>  
>> +# BACKUP_REG0 MMR on AM62x
>> +UBOOT_BOOTCOUNT_ADDR=0x4301c100
>> +
>> +devmem2 $UBOOT_BOOTCOUNT_ADDR w 0
>
> Using devmem2 might be a bad idea. Consider using fw_setenv [1] to set
> the bootcount to 0. 
>

Yeah, this should be trivial to support with libubootenv-bin added to
IMAGE_INSTALL.

Regards,
Anshul

>
>>  swupdate -H @MACHINE@:1.0 ${SELECTION} -p 'reboot' -f /etc/swupdate.cfg -w "-r /www -p 8080"
>> diff --git a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
>> index 0ce763f9..20f87435 100644
>> --- a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
>> +++ b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
>> @@ -2,6 +2,8 @@ inherit swupdate-lib
>>  
>>  FILESEXTRAPATHS:append := "${THISDIR}/files:"
>>  
>> +RDEPENDS:${PN} += "devmem2"
>> +
>>  FILES:${PN} += " \
>>    ${SWUPDATE_HW_COMPATIBILITY_FILE} \
>>  "
>> -- 
>> 2.52.0
>> 
>> 
>> 
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#16850): https://lists.yoctoproject.org/g/meta-arago/message/16850
>> Mute This Topic: https://lists.yoctoproject.org/mt/116574476/9980049
>> Group Owner: meta-arago+owner@lists.yoctoproject.org
>> Unsubscribe: https://lists.yoctoproject.org/g/meta-arago/unsub [y-hegde@ti.com]
>> -=-=-=-=-=-=-=-=-=-=-=-
>> 
>>
diff mbox series

Patch

diff --git a/meta-arago-distro/recipes-swupdate/images/files/sw-description b/meta-arago-distro/recipes-swupdate/images/files/sw-description
index 8dc4e2b2..241bc95c 100644
--- a/meta-arago-distro/recipes-swupdate/images/files/sw-description
+++ b/meta-arago-distro/recipes-swupdate/images/files/sw-description
@@ -15,6 +15,12 @@  software =
 						compressed = "zlib";
 					},
 				);
+				uboot: (
+					{
+						name = "bootpart";
+						value = "0:1";
+					},
+				);
 			};
 
 			copy2 : {
@@ -26,6 +32,12 @@  software =
 						compressed = "zlib";
 					},
 				);
+				uboot: (
+					{
+						name = "bootpart";
+						value = "0:2";
+					},
+				);
 			};
 		};
 	}
diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
new file mode 100644
index 00000000..57eec5fc
--- /dev/null
+++ b/meta-arago-distro/recipes-swupdate/libubootenv/files/fw_env.config
@@ -0,0 +1,5 @@ 
+# Describes the env location for U-Boot in the hw partition
+# Second entry indicates redundant env
+# Boot dev			Offset		Size
+/dev/mmcblk0boot0	0x680000	0x20000
+/dev/mmcblk0boot0	0x6a0000	0x20000
diff --git a/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
new file mode 100644
index 00000000..e3d142f2
--- /dev/null
+++ b/meta-arago-distro/recipes-swupdate/libubootenv/libubootenv_%.bbappend
@@ -0,0 +1,10 @@ 
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI:append = " file://fw_env.config"
+
+do_install:append() {
+	install -d ${D}${sysconfdir}
+	install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}
+}
+
+FILES:${PN}:append = " ${sysconfdir}"
diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
index b1362eaa..4a2d78c0 100644
--- a/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
+++ b/meta-arago-distro/recipes-swupdate/swupdate/files/defconfig
@@ -1,8 +1,10 @@ 
 CONFIG_HW_COMPATIBILITY=y
 # CONFIG_LUA is not set
 # CONFIG_BOOTLOADER_NONE is not set
+CONFIG_UBOOT=y
 CONFIG_SYSTEMD=y
 CONFIG_WEBSERVER=y
+CONFIG_BOOTLOADERHANDLER=y
 CONFIG_CFI=y
 CONFIG_EMMC_HANDLER=y
 CONFIG_RAW=y
diff --git a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
index bb3a3593..2083062e 100644
--- a/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
+++ b/meta-arago-distro/recipes-swupdate/swupdate/files/swupdate.sh
@@ -8,4 +8,8 @@  else
 	SELECTION="-e stable,copy2"
 fi
 
+# BACKUP_REG0 MMR on AM62x
+UBOOT_BOOTCOUNT_ADDR=0x4301c100
+
+devmem2 $UBOOT_BOOTCOUNT_ADDR w 0
 swupdate -H @MACHINE@:1.0 ${SELECTION} -p 'reboot' -f /etc/swupdate.cfg -w "-r /www -p 8080"
diff --git a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
index 0ce763f9..20f87435 100644
--- a/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
+++ b/meta-arago-distro/recipes-swupdate/swupdate/swupdate_%.bbappend
@@ -2,6 +2,8 @@  inherit swupdate-lib
 
 FILESEXTRAPATHS:append := "${THISDIR}/files:"
 
+RDEPENDS:${PN} += "devmem2"
+
 FILES:${PN} += " \
   ${SWUPDATE_HW_COMPATIBILITY_FILE} \
 "