Skip to contentSkip to conversation

errors copying UBI volumes

DISCUSSION [email protected] 2 participants 3 messages Sep 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi Sascha,

thanks for the answer,

Quoted 32 lines

Hi Giorgio,

Quoted 7 lines · On Wed, Sep 14, 2016 at 05:52:32PM +0200, [email protected] wrote:

Hi,

I'm working on an embedded board with an iMX25 arm CPU and a nand flash.

The board runs a linux kernel/userland.

When the user updates the firmware, the running userland/kernel creates

some

Quoted 2 lines

new ubi volumes on the nand, let's say 'kernel_next' and 'userland_next'. On the next system reboot barebox looks if it finds, lets say, the

'kernel_next' volume

Quoted 1 line

and, in this case, it removes the old one ('kernel'), creates a new, empty

one ('kernel'),

Quoted 1 line

copies 'kernel_next' to the just created 'kernel' and finally removes the

'kernel_next'

Quoted 1 line

to complete the update.

While this should work, why so complicated? Since this commit:

| commit 892abde56c1c5a62d49d8b70c73e5d388e74345d
| Author: Richard Weinberger <[email protected]>
| Date:   Mon Nov 24 22:30:10 2014 +0100
|
|    UBI: rename_volumes: Use UBI_METAONLY
|    
|    By using UBI_METAONLY in rename_volumes() it is now possible to rename
|    an UBI volume atomically while it is open for writing.
|    This is useful for firmware upgrades.
Quoted 3 lines

It should be possible to just remove 'kernel' and rename 'kernel_next' to 'kernel'
without bootloader intervention.

This is a very good news for me, I already wanted to ask for a UBI rename feature. Could you please elaborate a bit on this point: I looked for a shell command like the 'ubirename', present in the 'mtd-utils' package, but could not find it. Maybe we just need a new command implemented in '<barebox_root>/commands/ubi.c'.

Quoted 9 lines

BTW you should consider using Bootloader Spec entries
(http://www.barebox.org/doc/latest/user/booting-linux.html#bootloader-spec).

This makes the kernel volume unnecessary and the kernel will only be a file in UBIFS and thus updating is a matter of 'cp newkernel /boot/kernel'. Also booting in barebox becomes as simple as 'boot nand0.ubi.rootfs', no further configuration or scripting required.

thank you for the suggestion, I'll have a look at the method.

Quoted 80 lines
Quoted 19 lines

Here the relevant part of the init script:

...
if [ -e $kernel_next ]; then
echo "Update the kernel... "
ubirmvol $ubi_root kernel
ubimkvol $ubi_root kernel 8M
cp $kernel_next $kernel
if [ $? != 0 ]; then
echo "***Errors copying $kernel_next to $kernel" sleep 2
else
echo "Update OK."
ubirmvol $ubi_root kernel_next
fi
fi
...

Quoted 1 line

Now, after updating the barebox version to the current one, v2016.09.0,

the 'cp' command

Quoted 1 line

produces an almost endless sequence of failed assertions and stask

backtraces:

Quoted 17 lines

...
UBI assert failed in ubi_eba_read_leb at 359 Function entered at [<87053010>] from [<87018ce0>] Function entered at [<87018ce0>] from [<87017fb4>] Function entered at [<87017fb4>] from [<8703f100>] Function entered at [<8703f100>] from [<8703f2cc>] Function entered at [<8703f2cc>] from [<8703faf8>] Function entered at [<8703faf8>] from [<87039e78>] Function entered at [<87039e78>] from [<87029178>] Function entered at [<87029178>] from [<87003614>] Function entered at [<87003614>] from [<87008e0c>] Function entered at [<87008e0c>] from [<870083a0>] Function entered at [<870083a0>] from [<8700908c>] Function entered at [<8700908c>] from [<870011cc>] Function entered at [<870011cc>] from [<870515d4>] Function entered at [<870515d4>] from [<80052648>]

Quoted 8 lines

UBI assert failed in ubi_eba_read_leb at 359 Function entered at [<87053010>] from [<87018ce0>] Function entered at [<87018ce0>] from [<87017fb4>] Function entered at [<87017fb4>] from [<8703f100>] Function entered at [<8703f100>] from [<8703f2cc>] Function entered at [<8703f2cc>] from [<8703faf8>] Function entered at [<8703faf8>] from [<87039e78>]
...

Please enable KALLSYMS to make this readable.

Quoted 10 lines

After trying different things I realized that 'cp' has problems only with UBI volumes that were created by the kernel/userland during the firmware update process; if I create a volume within barebox it just work as expected.

Here is the source code snippet with the failing assertion:
(file <barebox_root>/drivers/mtd/ubi/eba.c)

int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int

lnum,

Quoted 17 lines

void *buf, int offset, int len, int check)
{
...

	pnum = vol->eba_tbl[lnum];
	if (pnum < 0) {
		/*
		 * The logical eraseblock is not mapped, fill the whole buffer
		 * with 0xFF bytes. The exception is static volumes for which
		 * it is an error to read unmapped logical eraseblocks.
		 */
		dbg_eba("read %d bytes from offset %d of LEB %d:%d (unmapped)",
			len, offset, vol_id, lnum);
		leb_read_unlock(ubi, vol_id, lnum);
		ubi_assert(vol->vol_type != UBI_STATIC_VOLUME);
		memset(buf, 0xFF, len);
		return 0;
	}
Quoted 9 lines

Have you created 'kernel_next' and/or 'userland_next' as static volume (-t=static)? The comment above states that in static volumes you cannot read unmapped logical eraseblocks. When wou do not completely fill 'kernel_next' with data then you can only read up to the point to which it is filled, the remaining LEBs are unmapped and thus unreadable. Note that when you hit the unmapped LEBs then you have already read all data; the errors only occur on the free space. This is the reason you can still boot the new system.

yes, this is the right explanation for what happens on my system. My userland creates static '*_next' volumes and their size is rounded up to the next Mb so at the end it will almost always remain some empty/unmapped LEBs.

The current barebox version just bark a bit louder about it and the 'cp' command returns with an error making my whole update process fail.

If I had an 'ubirename' command all my problems would be solved.

Quoted 13 lines

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

giorgio

Giorgio, [email protected]

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw
Quoted 36 lines · On Thu, Sep 15, 2016 at 01:13:14PM +0200, [email protected] wrote:

Hi Sascha,

thanks for the answer,

Quoted 32 lines

Hi Giorgio,

Quoted 7 lines · On Wed, Sep 14, 2016 at 05:52:32PM +0200, [email protected] wrote:

Hi,

I'm working on an embedded board with an iMX25 arm CPU and a nand flash.

The board runs a linux kernel/userland.

When the user updates the firmware, the running userland/kernel creates

some

Quoted 2 lines

new ubi volumes on the nand, let's say 'kernel_next' and 'userland_next'. On the next system reboot barebox looks if it finds, lets say, the

'kernel_next' volume

Quoted 1 line

and, in this case, it removes the old one ('kernel'), creates a new, empty

one ('kernel'),

Quoted 1 line

copies 'kernel_next' to the just created 'kernel' and finally removes the

'kernel_next'

Quoted 1 line

to complete the update.

While this should work, why so complicated? Since this commit:

| commit 892abde56c1c5a62d49d8b70c73e5d388e74345d
| Author: Richard Weinberger <[email protected]>
| Date:   Mon Nov 24 22:30:10 2014 +0100
|
|    UBI: rename_volumes: Use UBI_METAONLY
|    
|    By using UBI_METAONLY in rename_volumes() it is now possible to rename
|    an UBI volume atomically while it is open for writing.
|    This is useful for firmware upgrades.
Quoted 8 lines
Quoted 3 lines

It should be possible to just remove 'kernel' and rename 'kernel_next' to 'kernel'
without bootloader intervention.

This is a very good news for me, I already wanted to ask for a UBI rename feature. Could you please elaborate a bit on this point: I looked for a shell command like the 'ubirename', present in the 'mtd-utils' package, but could not find it. Maybe we just need a new command implemented in '<barebox_root>/commands/ubi.c'.

You can add a ubirename command, patches welcome. Anyway, I suggested to rename it under Linux since you write your new Kernel/rootfs under Linux aswell.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Hi,

Quoted 51 lines · On Thu, Sep 15, 2016 at 01:13:14PM +0200, [email protected] wrote:
Quoted 10 lines

Hi Sascha,

thanks for the answer,

Quoted 6 lines

Hi Giorgio,

Quoted 3 lines · On Wed, Sep 14, 2016 at 05:52:32PM +0200, [email protected] wrote:

Hi,

I'm working on an embedded board with an iMX25 arm CPU and a nand

flash.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The board runs a linux kernel/userland.

When the user updates the firmware, the running userland/kernel

creates

Quoted 2 lines
Quoted 2 lines

some

Quoted 1 line

new ubi volumes on the nand, let's say 'kernel_next' and

'userland_next'.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

On the next system reboot barebox looks if it finds, lets say, the

'kernel_next' volume

Quoted 1 line

and, in this case, it removes the old one ('kernel'), creates a new,

empty

Quoted 2 lines
Quoted 2 lines

one ('kernel'),

Quoted 1 line

copies 'kernel_next' to the just created 'kernel' and finally removes

the

Quoted 5 lines
Quoted 5 lines

'kernel_next'

Quoted 1 line

to complete the update.

While this should work, why so complicated? Since this commit:

Quoted 7 lines
Quoted 7 lines
| commit 892abde56c1c5a62d49d8b70c73e5d388e74345d
| Author: Richard Weinberger <[email protected]>
| Date:   Mon Nov 24 22:30:10 2014 +0100
|
|    UBI: rename_volumes: Use UBI_METAONLY
|    
|    By using UBI_METAONLY in rename_volumes() it is now possible to

rename

Quoted 4 lines
Quoted 4 lines
|    an UBI volume atomically while it is open for writing.
|    This is useful for firmware upgrades.

It should be possible to just remove 'kernel' and rename 'kernel_next'

to

Quoted 4 lines
Quoted 2 lines

'kernel'
without bootloader intervention.

This is a very good news for me, I already wanted to ask for a UBI rename

feature.

Quoted 1 line

Could you please elaborate a bit on this point: I looked for a shell

Quoted 9 lines

command like the

Quoted 1 line

'ubirename', present in the 'mtd-utils' package, but could not find it.

Maybe we just

Quoted 1 line

need a new command implemented in '<barebox_root>/commands/ubi.c'.

You can add a ubirename command, patches welcome. Anyway, I suggested to rename it under Linux since you write your new Kernel/rootfs under Linux aswell.

OK, I think I'll try to write a new command in commands/ubi.c and if it results in something usable I'll send a patch to be reviewed.

giorgio

Giorgio, [email protected]

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox