[OpenWrt-Devel] [PATCH v2] fstools: Add support to read-only MTD partitions (eg. recovery images)

Steve Brown sbrown at ewol.com
Tue Jan 21 05:55:09 EST 2020


Hi Bruno,

The device is a TPLink Archer A7V5 
(MIPS Qualcomm Atheros QCA956X ver 1 rev 0)

The flash layout is:

[    0.403133] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    0.408045] 7 fixed-partitions partitions found on MTD device spi0.0
[    0.414637] Creating 7 MTD partitions on "spi0.0":
[    0.419613] 0x000000000000-0x000000020000 : "factory-uboot"
[    0.426045] 0x000000020000-0x000000040000 : "u-boot"
[    0.431864] 0x000000040000-0x000000f00000 : "firmware"
[    0.439731] 2 uimage-fw partitions found on MTD device firmware
[    0.445848] Creating 2 MTD partitions on "firmware":
[    0.451022] 0x000000000000-0x0000001a38de : "kernel"
[    0.456798] 0x0000001a38de-0x000000ec0000 : "rootfs"
[    0.462602] mtd: device 4 (rootfs) set to be root filesystem
[    0.469713] 1 squashfs-split partitions found on MTD device rootfs
[    0.476108] 0x0000004d0000-0x000000ec0000 : "rootfs_data"
[    0.482403] 0x000000f40000-0x000000f60000 : "info"
[    0.488005] 0x000000f60000-0x000000fb0000 : "config"
[    0.493837] 0x000000fc0000-0x000000fd0000 : "partition-table"
[    0.500477] 0x000000ff0000-0x000001000000 : "art"

The problem partition seems to be rootfs_data
The mount says "/dev/mtdblock5 on /overlay type jffs2 (rw,noatime)"

Interestingly rootfs and rootfs_data overlap. The former is mounted
R/O.
[    1.912343] VFS: Mounted root (squashfs filesystem) readonly on device 31:4.

Thanks,

Steve

On Tue, 2020-01-21 at 11:01 +0100, Bruno Pena wrote:
> Hi Steve,
> 
> These patches should only impact partitions that are marked as read
> only.
> Can you please provide more details about your configuration?
> (architecture, device profile, mtd layout, the mtd partition
> generating the error)
> 
> Best regards,
> Bruno Pena
> 
> On Tue, Jan 21, 2020, 10:51 Steve Brown <sbrown at ewol.com> wrote:
> > Hi Bruno,
> > 
> > On Sat, 2020-01-04 at 12:52 +0100, Bruno Pena wrote:
> > > This patch enables fstools to open read-only MTD partitions,
> > which in
> > > turn also enables OpenWrt to boot from read-only partitions.
> > > 
> > > The use of read-only partitions is of special importance for
> > WiFi-
> > > only
> > > devices, where a protected read-only recovery image can be used
> > in
> > > case
> > > something goes wrong with the main firmware (eg. user gets locked
> > out
> > > due to bad settings, flash of an unbootable dev firmware, etc).
> > > 
> > > Signed-off-by: Bruno Pena <brunompena at gmail.com>
> > > ---
> > >  libfstools/mtd.c | 19 +++++++++++++++----
> > >  1 file changed, 15 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/libfstools/mtd.c b/libfstools/mtd.c
> > > index 77c71ee..aae633e 100644
> > > --- a/libfstools/mtd.c
> > > +++ b/libfstools/mtd.c
> > > @@ -36,20 +36,31 @@ struct mtd_volume {
> > >  
> > >  static struct driver mtd_driver;
> > >  
> > > +static int mtd_open_device(const char *dev)
> > > +{
> > > +     int ret;
> > > +
> > > +     ret = open(dev, O_RDWR | O_SYNC);
> > > +     if (ret < 0)
> > > +             ret = open(dev, O_RDONLY);
> > > +
> > > +     return ret;
> > > +}
> > > +
> > >  static int mtd_open(const char *mtd, int block)
> > >  {
> > >       FILE *fp;
> > >       char dev[PATH_MAX];
> > > -     int i, ret, flags = O_RDWR | O_SYNC;
> > > +     int i, ret;
> > >  
> > >       if ((fp = fopen("/proc/mtd", "r"))) {
> > >               while (fgets(dev, sizeof(dev), fp)) {
> > >                       if (sscanf(dev, "mtd%d:", &i) &&
> > strstr(dev,
> > > mtd)) {
> > >                               snprintf(dev, sizeof(dev),
> > > "/dev/mtd%s/%d", (block ? "block" : ""), i);
> > > -                             ret = open(dev, flags);
> > > +                             ret = mtd_open_device(dev);
> > >                               if (ret < 0) {
> > >                                       snprintf(dev, sizeof(dev),
> > > "/dev/mtd%s%d", (block ? "block" : ""), i);
> > > -                                     ret = open(dev, flags);
> > > +                                     ret = mtd_open_device(dev);
> > >                               }
> > >                               fclose(fp);
> > >                               return ret;
> > > @@ -58,7 +69,7 @@ static int mtd_open(const char *mtd, int block)
> > >               fclose(fp);
> > >       }
> > >  
> > > -     return open(mtd, flags);
> > > +     return mtd_open_device(mtd);
> > >  }
> > >  
> > >  static void mtd_volume_close(struct mtd_volume *p)
> > 
> > 
> > This patch and related commit
> > de80424f706682e8bba27c60bcd2a9c1b4a5e875
> > break the jffs erase on my Archer a7 v5.
> > 
> >     [   11.787856] jffs2_scan_eraseblock(): End of filesystem
> > marker found at 0x10000
> >     [   11.795357] jffs2_build_filesystem(): unlocking the mtd
> > device...
> >     [   11.795390] done.
> >     [   11.803771] jffs2_build_filesystem(): erasing all blocks
> > after the end marker...
> >     [   11.803781] jffs2: Erase at 0x009e0000 failed immediately:
> > -EROFS. Is the sector locked?
> >          -------------
> >     [   13.138841] jffs2: Erase at 0x00010000 failed immediately:
> > -EROFS. Is the sector locked?
> >     [   13.147188] done.
> >     [   13.149202] jffs2: notice: (487)
> > jffs2_build_xattr_subsystem: complete building xattr subsystem, 0
> > of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 .
> >     [   13.165896] mount_root: unable to set filesystem state
> >     [   13.171443] mount_root: switching to jffs2 overlay
> >     [   13.201867] overlayfs: failed to resolve '/overlay/upper':
> > -2
> >     [   13.223939] mount_root: mount failed:
> > lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work, options
> > No such device
> >     [   13.235145] mount_root: switching to jffs2 failed - fallback
> > to ramoverlay
> > 
> > Verified by reverting de80424f7. 
> > 
> > Steve
> > 
> > 


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list