linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* MTD partitioning & firmware installation on Broadcom devices
@ 2021-03-08 17:37 Rafał Miłecki
  2021-03-22 18:23 ` Rafał Miłecki
  0 siblings, 1 reply; 2+ messages in thread
From: Rafał Miłecki @ 2021-03-08 17:37 UTC (permalink / raw)
  To: linux-mtd; +Cc: Álvaro Fernández Rojas

Hi,

I'm trying to implement firmware installation on BCM4908 platform.
It's related to MTD and partitioning.

BCM4908 firmware image consists of:
1. "bootfs" JFFS2 partition with: 94908.dtb, cferam.000 and vmlinux.lz
2. "ubi" UBI partition appended to the "bootfs"

The problem is that when flashing firmware image then cferam.000 file
in the "bootfs" JFFS2 partition has to be renamed. "000" part has to
be changed to the last used number + 1.

Example:
Let's say device is running firmware with "bootfs" JFFS2 partition
containing cferam.007.
After flashing new firmware "bootfs" JFFS2 partition should contain
cferam.008 (instead of cferam.000 as provided in the firmware image).

I'm trying to find a way for handling that.


Solution #1
Renaming cferam.000 before flashing (mtd write) image.
I don't see any clean way of doing that. I could extract bootfs.jffs2
out of firmware image but:
1. There is no tool for modifying JFFS2 images
2. The only tool for extracting JFFS2 image content is Python script.
Python seems too heavy solution for firmware upgrade task.
3. I can't mount boofs.jffs2. I'd need some virtual mtd device. Also a
bit overkill it seems.


Solution #2
Flashing firmware image as is (with cferam.000) and adjusting it.
This should be nicer as mounting JFFS2 MTD partition is simple. The
problem is partitioning.
I'd need to remove MTD partitions and trigger re-partitioning of
"firmware" partition. Only once I have Linux create "bootfs" and "ubi"
partitions again for me I could mount "bootfs" and rename the file.
There is no support for such repartitioning at this point AFAIK.


Can you see any other solution I didn't think about?
Or should I proceed with one of above solutions? Like writing a tool
for modifying JFFS2 images. Or patching MTD to support repartitioning?

-- 
Rafał

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: MTD partitioning & firmware installation on Broadcom devices
  2021-03-08 17:37 MTD partitioning & firmware installation on Broadcom devices Rafał Miłecki
@ 2021-03-22 18:23 ` Rafał Miłecki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafał Miłecki @ 2021-03-22 18:23 UTC (permalink / raw)
  To: linux-mtd; +Cc: Álvaro Fernández Rojas

On 08.03.2021 18:37, Rafał Miłecki wrote:
> Solution #2
> Flashing firmware image as is (with cferam.000) and adjusting it.
> This should be nicer as mounting JFFS2 MTD partition is simple. The
> problem is partitioning.
> I'd need to remove MTD partitions and trigger re-partitioning of
> "firmware" partition. Only once I have Linux create "bootfs" and "ubi"
> partitions again for me I could mount "bootfs" and rename the file.
> There is no support for such repartitioning at this point AFAIK.

I've implemented that solution. Kernel part was trivial actually, I just
wired up BLKRRPART ioctl.

The problem is it doesn't work. Doing "mv cferam.000 cferam.123" results
in marking cferam.000 node as deleted and adding a new cferam.123 node
hardlinking to the original content. Sounds good but CFE bootloader is
too stupid for that. It doesn't recognize deleted files (nodes) and
believes cferam.000 is still there.

I don't want to implement JFFS2 hacks changing its rename support
implementation. So I've to proceed with Solution #1 and just write
tool modifying JFFS2 image before flashing it to the MTD.

--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1015,8 +1015,11 @@ static int mtdchar_ioctl(struct file *fi

  	case BLKRRPART:
  	{
-		/* No reread partition feature. Just return ok */
-		ret = 0;
+		int nr_parts;
+
+		del_mtd_partitions(mtd);
+		nr_parts = parse_mtd_partitions(mtd, NULL, NULL);
+		ret = nr_parts < 0 ? nr_parts : 0;
  		break;
  	}
  	}

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-22 18:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 17:37 MTD partitioning & firmware installation on Broadcom devices Rafał Miłecki
2021-03-22 18:23 ` Rafał Miłecki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).