Handling ubinized image flashed on not erased flash space

Rafał Miłecki zajec5 at gmail.com
Fri Mar 18 07:46:34 PDT 2022


On 11.03.2022 13:04, Rafał Miłecki wrote:
> My question is: how to do that? I need to erase flash partition starting
> with some middle block (the first after ubinized image). I need to get
> that offset somehow.
> 
> I *can't* scan block after block looking for the first one without a
> matching EC magic. That wouldn't work with the same ubinized image
> flashed twice.
> 
> Reading volumes table, each volume size, trying to calculate ubinized
> image size on that data - sounds like overkill for user-space app.
> 
> Any suggestions, please?

I'd like to provide some summary for further researchers.


I had some discussion on this with Richard on #mtd on Wednesday and it
seems there isn't a reliable way for finding end of ubinized image on
flash.

I was suggested to use a custom flash block as an EOF (End Of UBI?)
marker. Then detect such a marker from either: user-space or kernel:

[2022-03-16] [12:54:39 CET] <derRichard> one more thing: i don't have a problem with in-kernel cleanup code. i have a problem with a changed ubi disk format.

Sadly it seems a kernel solution for the whole issue won't get accepted
as upstream code:

[2022-03-16] [14:27:05 CET] <rmilecki> derRichard: you wrote "i don't have a problem with in-kernel cleanup code"
[2022-03-16] [14:27:11 CET] <rmilecki> derRichard: did you mean downstream or upstream?
[2022-03-16] [14:27:19 CET] <derRichard> downstream
[2022-03-16] [14:27:33 CET] <derRichard> look, we cannot add such hacks upstream
[2022-03-16] [14:28:14 CET] <rmilecki> we also can't figure out any non-hack way to support those case
[2022-03-16] [14:28:16 CET] <rmilecki> *cases
[2022-03-16] [14:28:24 CET] <rmilecki> which is disappointing
[2022-03-16] [14:28:36 CET] <derRichard> since the bootloader hates you...


So basically we just circled back. The best solution seems to be the one
implemented & used in OpenWrt for decades.

Personally I'm a bit disappointed. I'll need to carry on a workaround
for those poor bootloaders in every project (OpenWrt / Buildroot / Yocto
/ whatever).

Few MTD guys kept nagging OpenWrt for its downstream mtd hacks but it
appears there is no idea or place for an upstream solution. Unless we
reverse engineer those poor bootloaders and replace them with U-Boot.



More information about the linux-mtd mailing list