mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: AM335x MLO failed to boot
Date: Tue, 19 Apr 2022 12:07:54 +0300	[thread overview]
Message-ID: <CAP1tNvRTfyvxk3xHwSXMe=_vH7xxNKXmXt0=fpB0rRHwQA=Wrg@mail.gmail.com> (raw)
In-Reply-To: <20220419082738.GO4012@pengutronix.de>

Hello Sascha.

Patch works as expexted!

Thanks!
----

booting from NAND

barebox 2022.03.0-00482-g13b17212e0f6-dirty #82 Tue Apr 19 12:01:45 MSK 2022
Board: Mega-Milas Informer/Spider AM335x
cpsw-mdio 4a101000.mdio@1000.of: detected phy mask 0x10
mdio_bus: miibus0: probed
eth0: got preset MAC address: d0:03:eb:ef:c2:a6
i2c-omap 44e0b000.i2c@0.of: bus 0 rev0.11 at 400 kHz
omap-hsmmc 48060000.mmc@0.of: registered as mmc0
omap_wdt 44e35000.wdt@0.of: OMAP Watchdog Timer Rev 0x01
nand_base: device found, Manufacturer ID: 0x2c, Chip ID: 0xda
nand_base: Micron MT29F2G08ABAEAWP
nand_base: 256 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
malloc space: 0x87efe000 -> 0x8fdfbfff (size 127 MiB)
am335x-phy-driver 47401b00.usb-phy@1b00.of: am_usbphy 87f5e19c enabled
am335x-phy-driver 47401300.usb-phy@1300.of: am_usbphy 87f5e23c enabled
musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, bulk
split, HB-ISO Rx, HB-ISO Tx, SoftConn)
musb-hdrc: MHDRC RTL version 2.0
musb-hdrc: setup fifo_mode 4
musb-hdrc: 28/31 max ep, 16384/16384 memory
musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, bulk
split, HB-ISO Rx, HB-ISO Tx, SoftConn)
musb-hdrc: MHDRC RTL version 2.0
musb-hdrc: setup fifo_mode 4
musb-hdrc: 28/31 max ep, 16384/16384 memory
ERROR: vdd_3v3mute_reg.of: probe permanently deferred
NOTICE: No support for persistent environment. Using default environment
NOTICE: ubi0: scanning is finished
NOTICE: ubi0: registering /dev/nand0.system.ubi
NOTICE: ubi0: registering kernel as /dev/nand0.system.ubi.kernel
NOTICE: ubi0: registering root as /dev/nand0.system.ubi.root
NOTICE: ubi0: registering bbox as /dev/nand0.system.ubi.bbox
NOTICE: ubi0: attached mtd0 (name "nand0.system", size 255 MiB) to ubi0
NOTICE: ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
NOTICE: ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
NOTICE: ubi0: VID header offset: 512 (aligned 512), data offset: 2048
NOTICE: ubi0: good PEBs: 2041, bad PEBs: 0, corrupted PEBs: 0
NOTICE: ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
NOTICE: ubi0: max/mean erase counter: 3/1, WL threshold: 65536, image
sequence number: 712287420
NOTICE: ubi0: available PEBs: 521, total reserved PEBs: 1520, PEBs
reserved for bad PEB handling: 40

Hit any to stop autoboot:    2
barebox@Mega-Milas Informer/Spider AM335x:/

вт, 19 апр. 2022 г. в 11:27, Sascha Hauer <sha@pengutronix.de>:
>
> Hi,
>
> On Thu, Apr 14, 2022 at 05:07:38PM +0300, Alexander Shiyan wrote:
> > Hello.
> >
> > I can't start the custom AM335x board after updating to version 2021.12.0.
> > Perhaps this is a consequence of the "devfs: Do not create overlapping
> > partitions" commit.
> >
> > Here is a debug output:
> > Add partition nand0.MLO, device nand0 (0x00000000-0x00020000)
> > Add partition nand0.boot, device nand0 (0x00020000-0x00080000)
> > Add partition nand0.env, device nand0 (0x000a0000-0x00040000)
> > Add partition nand0.system, device nand0 (0x000e0000-0x0ff20000)
> > booting from NAND
> > Add partition x, device nand0 (0x00020000-0x00080000)
> > New partition x (0x00020000-0x0009ffff) on nand0.boot overlaps with
> > partition nand0.boot (0x00000000-0x0007ffff), not creating it
> > failed to open bbx
> > booting failed
> >
> > What is the partition "x" in this case?
> > How to fix this?
>
> The problem is here:
>
> > static void *omap_xload_boot_nand(struct omap_barebox_part *part)
> > {
> >       void *to;
> >
> >       devfs_add_partition("nand0", part->nand_offset, part->nand_size,
> >                                       DEVFS_PARTITION_FIXED, "x");
>
> This adds a partition in order to read the barebox image from it. You already
> have a partitioned device, so we can't create any conflicting partitions.
> We could read from that partition instead of re-creating it, but likely the
> partitions do not exist in all cases. You could try the following patch. It's
> completely untested, but the idea is to read from the raw device
> instead.
>
> Sascha
>
> --------------------------8<--------------------------------
> From 2e9bd9d1a193aa8671e75ef3e9b31c6bccd8e309 Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Tue, 19 Apr 2022 10:22:09 +0200
> Subject: [PATCH] ARM: omap: xload: Do not create partitions
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/mach-omap/xload.c | 86 +++++++++++++++-----------------------
>  drivers/mtd/peb.c          | 32 ++++++++++++++
>  include/mtd/mtd-peb.h      |  2 +
>  3 files changed, 67 insertions(+), 53 deletions(-)
>
> diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
> index af9abf38b5..d786e6ceb2 100644
> --- a/arch/arm/mach-omap/xload.c
> +++ b/arch/arm/mach-omap/xload.c
> @@ -20,6 +20,7 @@
>  #include <net.h>
>  #include <environment.h>
>  #include <dhcp.h>
> +#include <mtd/mtd-peb.h>
>
>  struct omap_barebox_part *barebox_part;
>
> @@ -32,29 +33,6 @@ static struct omap_barebox_part default_part = {
>         .nor_size = SZ_1M,
>  };
>
> -static void *read_image_head(const char *name)
> -{
> -       void *header = xmalloc(ARM_HEAD_SIZE);
> -       struct cdev *cdev;
> -       int ret;
> -
> -       cdev = cdev_open_by_name(name, O_RDONLY);
> -       if (!cdev) {
> -               printf("failed to open %s\n", name);
> -               return NULL;
> -       }
> -
> -       ret = cdev_read(cdev, header, ARM_HEAD_SIZE, 0, 0);
> -       cdev_close(cdev);
> -
> -       if (ret != ARM_HEAD_SIZE) {
> -               printf("failed to read from %s\n", name);
> -               return NULL;
> -       }
> -
> -       return header;
> -}
> -
>  static unsigned int get_image_size(void *head)
>  {
>         unsigned int ret = 0;
> @@ -67,57 +45,62 @@ static unsigned int get_image_size(void *head)
>         return ret;
>  }
>
> -static void *read_mtd_barebox(const char *partition)
> +static void *read_mtd_barebox(const char *part, unsigned int start, unsigned int size)
>  {
>         int ret;
> -       int size;
> -       void *to, *header;
> +       void *to;
>         struct cdev *cdev;
> +       struct mtd_info *mtd;
> +       unsigned int ps, pe;
> +
> +       cdev = cdev_open_by_name(part, O_RDONLY);
> +       if (!cdev) {
> +               printf("failed to open partition\n");
> +               return NULL;
> +       }
>
> -       header = read_image_head(partition);
> -       if (header == NULL)
> +       mtd = cdev->mtd;
> +       if (!mtd)
>                 return NULL;
>
> -       size = get_image_size(header);
> -       if (!size) {
> -               printf("failed to get image size\n");
> +       if (mtd_mod_by_eb(start, mtd) != 0) {
> +               printf("Start must be eraseblock aligned\n");
>                 return NULL;
>         }
>
>         to = xmalloc(size);
>
> -       cdev = cdev_open_by_name(partition, O_RDONLY);
> -       if (!cdev) {
> -               printf("failed to open partition\n");
> -               return NULL;
> +       ps = mtd_div_by_eb(start, mtd);
> +       pe = mtd_div_by_eb(start + size, mtd);
> +       ret = mtd_peb_read_file(mtd, ps, pe, to, size);
> +       if (ret) {
> +               printf("Can't read image from %s: %d\n", part, ret);
> +               goto err;
>         }
>
> -       ret = cdev_read(cdev, to, size, 0, 0);
> -       if (ret != size) {
> -               printf("failed to read from partition\n");
> -               return NULL;
> +       size = get_image_size(to);
> +       if (!size) {
> +               printf("failed to get image size\n");
> +               goto err;
>         }
>
>         return to;
> +
> +err:
> +       free(to);
> +       return NULL;
>  }
>
>  static void *omap_xload_boot_nand(struct omap_barebox_part *part)
>  {
>         void *to;
>
> -       devfs_add_partition("nand0", part->nand_offset, part->nand_size,
> -                                       DEVFS_PARTITION_FIXED, "x");
> -       dev_add_bb_dev("x", "bbx");
> -
> -       to = read_mtd_barebox("bbx");
> +       to = read_mtd_barebox("nand0", part->nand_offset, part->nand_size);
>         if (to == NULL && part->nand_bkup_size != 0) {
>                 printf("trying to load image from backup partition.\n");
> -               devfs_add_partition("nand0", part->nand_bkup_offset,
> -                               part->nand_bkup_size,
> -                               DEVFS_PARTITION_FIXED, "x_bkup");
> -               dev_add_bb_dev("x_bkup", "bbx_bkup");
>
> -               to = read_mtd_barebox("bbx_bkup");
> +               to = read_mtd_barebox("nand0", part->nand_bkup_offset,
> +                               part->nand_bkup_size);
>         }
>
>         return to;
> @@ -162,10 +145,7 @@ static void *omap_xload_boot_mmc(void)
>
>  static void *omap_xload_boot_spi(struct omap_barebox_part *part)
>  {
> -       devfs_add_partition("m25p0", part->nor_offset, part->nor_size,
> -                                       DEVFS_PARTITION_FIXED, "x");
> -
> -       return read_mtd_barebox("x");
> +       return read_mtd_barebox("m25p0", part->nor_offset, part->nor_size);
>  }
>
>  static void *omap4_xload_boot_usb(void){
> diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
> index 6c61e0734c..ac6b232e37 100644
> --- a/drivers/mtd/peb.c
> +++ b/drivers/mtd/peb.c
> @@ -508,6 +508,38 @@ out:
>         return ret;
>  }
>
> +int mtd_peb_read_file(struct mtd_info *mtd, unsigned int peb_start,
> +                     unsigned int peb_last, void *buf, size_t len)
> +{
> +       int ret, pnum;
> +
> +       pnum = peb_start;
> +
> +       while (len) {
> +               size_t now = min_t(size_t, mtd->erasesize, len);
> +
> +               if (pnum > peb_last)
> +                       return -EIO;
> +
> +               if (mtd_peb_is_bad(mtd, pnum)) {
> +                       pnum++;
> +                       continue;
> +               }
> +
> +               ret = mtd_peb_read(mtd, buf, pnum, 0, now);
> +               if (ret)
> +                       goto out;
> +
> +               len -= now;
> +               pnum++;
> +               buf += now;
> +       }
> +
> +       ret = 0;
> +out:
> +       return ret;
> +}
> +
>  /**
>   * mtd_peb_erase - erase a physical eraseblock.
>   * @mtd: mtd device
> diff --git a/include/mtd/mtd-peb.h b/include/mtd/mtd-peb.h
> index cfcc0be611..cf8d8ff8da 100644
> --- a/include/mtd/mtd-peb.h
> +++ b/include/mtd/mtd-peb.h
> @@ -23,6 +23,8 @@ int mtd_num_pebs(struct mtd_info *mtd);
>  int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
>                                    int len, int num_bitflips, int random,
>                                    int info);
> +int mtd_peb_read_file(struct mtd_info *mtd, unsigned int peb_start,
> +                     unsigned int peb_last, void *buf, size_t len);
>  int mtd_peb_write_file(struct mtd_info *mtd, int peb_start, int max_pebs,
>                        const void *buf, size_t len);
>
> --
> 2.30.2
>
>
> --
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2022-04-19  9:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 14:07 Alexander Shiyan
2022-04-19  8:27 ` Sascha Hauer
2022-04-19  9:07   ` Alexander Shiyan [this message]
2022-04-20  6:39     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP1tNvRTfyvxk3xHwSXMe=_vH7xxNKXmXt0=fpB0rRHwQA=Wrg@mail.gmail.com' \
    --to=eagle.alexander923@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox