[PATCH] UBI: support EOF block marking end of ubinized image

Rafał Miłecki zajec5 at gmail.com
Fri Mar 18 08:58:17 PDT 2022


On 18.03.2022 16:53, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal at milecki.pl>
> 
> On home routers UBI is often used with UBI unaware bootloaders. In such
> case an ubinized image needs to be created & flashed.
> 
> The problem is many such bootloaders are poorly written and they don't
> erase whole flash (partition) before writing an image. Only part of
> flash required to fit new image gets erased. It results in UBI
> complaining about flash garbage content, e.g.:
> 
> ubi0: attaching mtd2
> ubi0 error: ubi_attach: bad image sequence number 1646161998 in PEB 119, expected 524503983
> Erase counter header dump:
>           magic          0x55424923
>           version        1
>           ec             1
>           vid_hdr_offset 2048
>           data_offset    4096
>           image_seq      1646161998
>           hdr_crc        0x1eb28994
> erase counter header hexdump:
> ubi0 error: ubi_attach_mtd_dev: failed to attach mtd2, error -22
> UBI error: cannot attach mtd2
> 
> To fix up such flashed images it's required to identify the end of
> ubinized image on flash and erase remaining blocks.
> 
> Idea of extending on-disk UBI format to mark end of ubinized image was
> rejected, see:
> [PATCH RFC 2/2] ubi: add support for UBI_EC_FLAG_ERASE_FROM_HERE
> https://patchwork.ozlabs.org/project/linux-mtd/patch/20161230171151.13448-2-zajec5@gmail.com/
> 
> This patch implements support for a simple "EOF" text content (block)
> appended to the ubinized image instead. It doesn't require changing
> on-disk format and still allows simple integration into ubi code.
> 
> Signed-off-by: Rafał Miłecki <rafal at milecki.pl>

While I personally think that UBI should provide *any* solution for such
poor bootloaders it has been stated upstream won't accept this hack.
There is no idea for any other / cleaner solution neither.

For details see e-mail thread:
Handling ubinized image flashed on not erased flash space
http://lists.infradead.org/pipermail/linux-mtd/2022-March/091993.html
http://lists.infradead.org/pipermail/linux-mtd/2022-March/092081.html

This patch is meant for downstream usage in projects like OpenWrt /
Buildroot / Yocto / foo.



More information about the linux-mtd mailing list