mbox series

[v3,0/4] Fix the SPL loading of a FIT image from NAND

Message ID 20200527115621.1062-1-dariobin@libero.it
Headers show
Series Fix the SPL loading of a FIT image from NAND | expand

Message

Dario Binacchi May 27, 2020, 11:56 a.m. UTC
Loading u-boot and its fdt from a NAND memory area with bad blocks led
to the creation of these patches.

Next, the output generated by the script used to flash the NAND of the
SOC that caused the issue.

....
 ** Rewriting /dev/mtd0 with /mnt/MLO
Erasing 128 Kibyte @ 0 -- 100 % complete
Writing data to block 0 at offset 0x0
 ** Rewriting /dev/mtd1 with /mnt/MLO
Erasing 128 Kibyte @ 0 -- 100 % complete
Writing data to block 0 at offset 0x0
 ** Rewriting /dev/mtd2 with /mnt/MLO
Erasing 128 Kibyte @ 0 -- 100 % complete
Writing data to block 0 at offset 0x0
 ** Rewriting /dev/mtd3 with /mnt/MLO
Erasing 128 Kibyte @ 0 -- 100 % complete
Writing data to block 0 at offset 0x0
 ** Rewriting /dev/mtd4 with /mnt/u-boot.itb
Skipping bad block at 00020000
Erasing 128 Kibyte @ e0000 -- 100 % complete
Bad block at 20000, 1 block(s) will be skipped
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
Writing data to block 5 at offset 0xa0000
 ** Rewriting /dev/mtd5 with /mnt/u-boot.itb
Erasing 128 Kibyte @ e0000 -- 100 % complete
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
...

- The bad block of the mtd4 partition at address 0x20000 is skipped
  during the writing of u-boot.itb.
- A redundant copy of u-boot.itb is written on mtd5 partition. In this
  partition there are no bad blocks.
- Every data written on mtd5 partition at address <addr> greater than
  or equal to 0x20000, has been written on partition mtd4 at address
  0x40000 + <addr> - 0x20000. The current version of u-boot correctly
  manages bad blocks only if they are at addresses that follow the
  address from which to start reading data. If the starting address of
  the device tree, which can be taken from the itb header, is higher
  than the address of any bad block of the same partition, the address
  is no longer valid and it must be changed.

Changes in v3:
The previous versions were buggy for devices others than NAND. This
because the 'adjust_offset' helper was properly set only for the NAND
case but called even for devices like MMC, RAM, and so on, crashing the
boot up by that devices. Continuing to use the adjust_offset helper
would mean checking the helper before calling it and patching too many
files to set it properly before calling the spl_load_simple_fit routine.
For this reason, the adjust_offset helper has been removed from the
spl_image_info structure and the offset fixed inside the read helper for
the NAND device only. This solution fixes the problem for the NAND device
without side effects for other types of devices.

Changes in v2:
 - Replace CONFIG_IS_ENABLED(OF_EMBED) with IS_ENABLED(CONFIG_OF_EMBED))

Dario Binacchi (4):
  spl: fix format of function documentation
  spl: fit: fail fit loading in case of FDT appending error
  spl: fit: nand: fix fit loading in case of bad blocks
  spl: fit: improve spl_nand_fit_read(...) readability

 common/spl/spl_fit.c                    |  9 +++++---
 common/spl/spl_nand.c                   | 15 +++++++------
 drivers/mtd/nand/raw/nand_spl_loaders.c | 28 +++++++++++++++++++++++++
 include/nand.h                          |  1 +
 include/spl.h                           |  2 +-
 5 files changed, 45 insertions(+), 10 deletions(-)