diff mbox series

base-files: fix nand_upgrade_ubinized()

Message ID 20230410170135.13986-1-zajec5@gmail.com
State Accepted
Delegated to: Daniel Golle
Headers show
Series base-files: fix nand_upgrade_ubinized() | expand

Commit Message

Rafał Miłecki April 10, 2023, 5:01 p.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

When using "ubiformat" with stdin it requires passing image size using
the -S argument. Provide it just like we do for "ubiupdatevol".

This fixes:
ubiformat: error!: must use '-S' with non-zero value when reading from stdin

This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
possibly some other targets too.

Cc: Rodrigo Balerdi <lanchon@gmail.com>
Cc: Daniel Golle <daniel@makrotopia.org>
Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 package/base-files/files/lib/upgrade/nand.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Daniel Golle April 10, 2023, 6:38 p.m. UTC | #1
On Mon, Apr 10, 2023 at 07:01:35PM +0200, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> When using "ubiformat" with stdin it requires passing image size using
> the -S argument. Provide it just like we do for "ubiupdatevol".
> 
> This fixes:
> ubiformat: error!: must use '-S' with non-zero value when reading from stdin
> 
> This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
> possibly some other targets too.
> 
> Cc: Rodrigo Balerdi <lanchon@gmail.com>
> Cc: Daniel Golle <daniel@makrotopia.org>
> Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Acked-by: Daniel Golle <daniel@makrotopia.org>

Please apply asap.

> ---
>  package/base-files/files/lib/upgrade/nand.sh | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
> index 907945b349..fa29d575a8 100644
> --- a/package/base-files/files/lib/upgrade/nand.sh
> +++ b/package/base-files/files/lib/upgrade/nand.sh
> @@ -261,10 +261,12 @@ nand_upgrade_ubinized() {
>  	local ubi_file="$1"
>  	local gz="$2"
>  
> +	local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
> +
>  	nand_detach_ubi "$CI_UBIPART" || return 1
>  
>  	local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
> -	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
> +	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
>  }
>  
>  # Write the UBIFS image to UBI rootfs volume
> -- 
> 2.34.1
>
Lanchon April 10, 2023, 11:33 p.m. UTC | #2
On 4/10/23 15:38, Daniel Golle wrote:
> On Mon, Apr 10, 2023 at 07:01:35PM +0200, Rafał Miłecki wrote:
>> From: Rafał Miłecki <rafal@milecki.pl>
>>
>> When using "ubiformat" with stdin it requires passing image size using
>> the -S argument. Provide it just like we do for "ubiupdatevol".
>>
>> This fixes:
>> ubiformat: error!: must use '-S' with non-zero value when reading from stdin
>>
>> This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
>> possibly some other targets too.
>>
>> Cc: Rodrigo Balerdi <lanchon@gmail.com>
>> Cc: Daniel Golle <daniel@makrotopia.org>
>> Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
>> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> Acked-by: Daniel Golle <daniel@makrotopia.org>
>
> Please apply asap.

(Dan, do you want me to PR?)

hi Rafa, thanks!

i wonder how it is possible that the code as is worked for me; i tested 
many times with compressed ubinized image.


>
>> ---
>>   package/base-files/files/lib/upgrade/nand.sh | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
>> index 907945b349..fa29d575a8 100644
>> --- a/package/base-files/files/lib/upgrade/nand.sh
>> +++ b/package/base-files/files/lib/upgrade/nand.sh
>> @@ -261,10 +261,12 @@ nand_upgrade_ubinized() {
>>   	local ubi_file="$1"
>>   	local gz="$2"
>>   
>> +	local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
>> +
>>   	nand_detach_ubi "$CI_UBIPART" || return 1
>>   
>>   	local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
>> -	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
>> +	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
>>   }
>>   
>>   # Write the UBIFS image to UBI rootfs volume
>> -- 
>> 2.34.1
>>
Koen Vandeputte April 11, 2023, 8:33 a.m. UTC | #3
On Tue, Apr 11, 2023 at 1:36 AM Lanchon <lanchon@gmail.com> wrote:
>
>
>
> On 4/10/23 15:38, Daniel Golle wrote:
> > On Mon, Apr 10, 2023 at 07:01:35PM +0200, Rafał Miłecki wrote:
> >> From: Rafał Miłecki <rafal@milecki.pl>
> >>
> >> When using "ubiformat" with stdin it requires passing image size using
> >> the -S argument. Provide it just like we do for "ubiupdatevol".
> >>
> >> This fixes:
> >> ubiformat: error!: must use '-S' with non-zero value when reading from stdin
> >>
> >> This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
> >> possibly some other targets too.
> >>
> >> Cc: Rodrigo Balerdi <lanchon@gmail.com>
> >> Cc: Daniel Golle <daniel@makrotopia.org>
> >> Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
> >> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> > Acked-by: Daniel Golle <daniel@makrotopia.org>
> >
> > Please apply asap.
>
> (Dan, do you want me to PR?)
>
> hi Rafa, thanks!
>
> i wonder how it is possible that the code as is worked for me; i tested
> many times with compressed ubinized image.
>
>
> >
> >> ---
> >>   package/base-files/files/lib/upgrade/nand.sh | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
> >> index 907945b349..fa29d575a8 100644
> >> --- a/package/base-files/files/lib/upgrade/nand.sh
> >> +++ b/package/base-files/files/lib/upgrade/nand.sh
> >> @@ -261,10 +261,12 @@ nand_upgrade_ubinized() {
> >>      local ubi_file="$1"
> >>      local gz="$2"
> >>
> >> +    local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
> >> +
> >>      nand_detach_ubi "$CI_UBIPART" || return 1
> >>
> >>      local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
> >> -    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
> >> +    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
> >>   }
> >>
> >>   # Write the UBIFS image to UBI rootfs volume
> >> --
> >> 2.34.1
> >>

I wonder if this also fixes the sysupgrade issues I reported on imx6 ..
Will test today
Koen Vandeputte April 11, 2023, 12:31 p.m. UTC | #4
On Tue, Apr 11, 2023 at 10:33 AM Koen Vandeputte
<koen.vandeputte@citymesh.com> wrote:
>
> On Tue, Apr 11, 2023 at 1:36 AM Lanchon <lanchon@gmail.com> wrote:
> >
> >
> >
> > On 4/10/23 15:38, Daniel Golle wrote:
> > > On Mon, Apr 10, 2023 at 07:01:35PM +0200, Rafał Miłecki wrote:
> > >> From: Rafał Miłecki <rafal@milecki.pl>
> > >>
> > >> When using "ubiformat" with stdin it requires passing image size using
> > >> the -S argument. Provide it just like we do for "ubiupdatevol".
> > >>
> > >> This fixes:
> > >> ubiformat: error!: must use '-S' with non-zero value when reading from stdin
> > >>
> > >> This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
> > >> possibly some other targets too.
> > >>
> > >> Cc: Rodrigo Balerdi <lanchon@gmail.com>
> > >> Cc: Daniel Golle <daniel@makrotopia.org>
> > >> Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
> > >> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> > > Acked-by: Daniel Golle <daniel@makrotopia.org>
> > >
> > > Please apply asap.
> >
> > (Dan, do you want me to PR?)
> >
> > hi Rafa, thanks!
> >
> > i wonder how it is possible that the code as is worked for me; i tested
> > many times with compressed ubinized image.
> >
> >
> > >
> > >> ---
> > >>   package/base-files/files/lib/upgrade/nand.sh | 4 +++-
> > >>   1 file changed, 3 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
> > >> index 907945b349..fa29d575a8 100644
> > >> --- a/package/base-files/files/lib/upgrade/nand.sh
> > >> +++ b/package/base-files/files/lib/upgrade/nand.sh
> > >> @@ -261,10 +261,12 @@ nand_upgrade_ubinized() {
> > >>      local ubi_file="$1"
> > >>      local gz="$2"
> > >>
> > >> +    local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
> > >> +
> > >>      nand_detach_ubi "$CI_UBIPART" || return 1
> > >>
> > >>      local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
> > >> -    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
> > >> +    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
> > >>   }
> > >>
> > >>   # Write the UBIFS image to UBI rootfs volume
> > >> --
> > >> 2.34.1
> > >>
>
> I wonder if this also fixes the sysupgrade issues I reported on imx6 ..
> Will test today

Yep .. it also fixes the upgrade issue on imx6 boards.
Thanks!

Tested-by: Koen Vandeputte <koen.vandeputte@citymesh.com>
Daniel Golle April 11, 2023, 12:44 p.m. UTC | #5
On Tue, Apr 11, 2023 at 02:31:55PM +0200, Koen Vandeputte wrote:
> On Tue, Apr 11, 2023 at 10:33 AM Koen Vandeputte
> <koen.vandeputte@citymesh.com> wrote:
> >
> > On Tue, Apr 11, 2023 at 1:36 AM Lanchon <lanchon@gmail.com> wrote:
> > >
> > >
> > >
> > > On 4/10/23 15:38, Daniel Golle wrote:
> > > > On Mon, Apr 10, 2023 at 07:01:35PM +0200, Rafał Miłecki wrote:
> > > >> From: Rafał Miłecki <rafal@milecki.pl>
> > > >>
> > > >> When using "ubiformat" with stdin it requires passing image size using
> > > >> the -S argument. Provide it just like we do for "ubiupdatevol".
> > > >>
> > > >> This fixes:
> > > >> ubiformat: error!: must use '-S' with non-zero value when reading from stdin
> > > >>
> > > >> This change fixes sysupgrade for bcm53xx and bcm4908 NAND devices
> > > >> possibly some other targets too.
> > > >>
> > > >> Cc: Rodrigo Balerdi <lanchon@gmail.com>
> > > >> Cc: Daniel Golle <daniel@makrotopia.org>
> > > >> Fixes: 971071212052 ("base-files: accept gzipped nand sysupgrade images")
> > > >> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> > > > Acked-by: Daniel Golle <daniel@makrotopia.org>
> > > >
> > > > Please apply asap.
> > >
> > > (Dan, do you want me to PR?)
> > >
> > > hi Rafa, thanks!
> > >
> > > i wonder how it is possible that the code as is worked for me; i tested
> > > many times with compressed ubinized image.
> > >
> > >
> > > >
> > > >> ---
> > > >>   package/base-files/files/lib/upgrade/nand.sh | 4 +++-
> > > >>   1 file changed, 3 insertions(+), 1 deletion(-)
> > > >>
> > > >> diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
> > > >> index 907945b349..fa29d575a8 100644
> > > >> --- a/package/base-files/files/lib/upgrade/nand.sh
> > > >> +++ b/package/base-files/files/lib/upgrade/nand.sh
> > > >> @@ -261,10 +261,12 @@ nand_upgrade_ubinized() {
> > > >>      local ubi_file="$1"
> > > >>      local gz="$2"
> > > >>
> > > >> +    local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
> > > >> +
> > > >>      nand_detach_ubi "$CI_UBIPART" || return 1
> > > >>
> > > >>      local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
> > > >> -    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
> > > >> +    ${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
> > > >>   }
> > > >>
> > > >>   # Write the UBIFS image to UBI rootfs volume
> > > >> --
> > > >> 2.34.1
> > > >>
> >
> > I wonder if this also fixes the sysupgrade issues I reported on imx6 ..
> > Will test today
> 
> Yep .. it also fixes the upgrade issue on imx6 boards.
> Thanks!
> 
> Tested-by: Koen Vandeputte <koen.vandeputte@citymesh.com>

Thank you for testing.

I've now applied the patch.
diff mbox series

Patch

diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
index 907945b349..fa29d575a8 100644
--- a/package/base-files/files/lib/upgrade/nand.sh
+++ b/package/base-files/files/lib/upgrade/nand.sh
@@ -261,10 +261,12 @@  nand_upgrade_ubinized() {
 	local ubi_file="$1"
 	local gz="$2"
 
+	local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
+
 	nand_detach_ubi "$CI_UBIPART" || return 1
 
 	local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
-	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
+	${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
 }
 
 # Write the UBIFS image to UBI rootfs volume