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

Bruno Pena brunompena at gmail.com
Tue Jan 21 08:53:54 EST 2020


Hi Daniel,

Based on the last comment from Steve (fstools patch was not reverted), I'm
not sure if that's the root cause.
The kernel patch (which when reverted makes rootfs_data writable again)
only enforces the parent mtd access mode on the sub-partitions.
When I look at the DTS file for this device I see that "firmware" is
read-write, so I wonder if there's something else marking these as
read-only.

Best regards,
Bruno Pena


On Tue, Jan 21, 2020, 11:55 Daniel Golle <daniel at makrotopia.org> wrote:

> Hi Bruno,
> Hi Steve,
>
> On Tue, Jan 21, 2020 at 11:24:28AM +0100, Bruno Pena wrote:
> > Please also include the contents of "dmesg" and of the files
> > "/proc/cmdline" and "/proc/mtd".
> >
> > Best regards,
> > Bruno Pena
> >
> > On Tue, Jan 21, 2020, 11:01 Bruno Pena <brunompena at gmail.com> 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)
>
> I think this is because opening /dev/mtdX will fail as read-write
> but will succeed in read-only mode. Hence /dev/mtdblockX is not even
> considered which is a change from the previous behaviour.
>
> > >
> > > 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20200121/99b60eba/attachment.htm>
-------------- next part --------------
_______________________________________________
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