All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support
@ 2016-01-17  3:09 Ladislav Michl
  2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
                   ` (6 more replies)
  0 siblings, 7 replies; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:09 UTC (permalink / raw)
  To: u-boot

Hi,

yet another update of ubispl support. Please note, that igep00x0 specific
part depends on yet unapplied "[PATCHv2 0/5] igep00x0: Minor cleanup"
series

---
 README                             |    4
 arch/arm/lib/Makefile              |    2
 arch/arm/lib/bootm.c               |   32 -
 arch/arm/lib/zimage.c              |   40 +
 board/isee/igep00x0/igep00x0.c     |   12
 common/spl/Makefile                |    3
 common/spl/spl.c                   |   27 +
 common/spl/spl_ubi.c               |   68 ++
 doc/README.ubispl                  |  141 +++++
 drivers/Makefile                   |    5
 drivers/mtd/nand/nand_spl_simple.c |   62 ++
 drivers/mtd/ubispl/Makefile        |    1
 drivers/mtd/ubispl/ubi-wrapper.h   |  106 ++++
 drivers/mtd/ubispl/ubispl.c        |  926 +++++++++++++++++++++++++++++++++++++
 drivers/mtd/ubispl/ubispl.h        |  136 +++++
 include/configs/omap3_igep00x0.h   |   80 +--
 include/nand.h                     |    1
 include/spl.h                      |    4
 include/ubispl.h                   |   90 +++

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

* [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
@ 2016-01-17  3:11 ` Ladislav Michl
  2016-01-21  6:04   ` Heiko Schocher
  2016-01-17  3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:11 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
 drivers/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index 00da40b..1b9f8d6 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -18,14 +18,14 @@ obj-$(CONFIG_ARMADA_38X) += ddr/marvell/a38x/
 obj-$(CONFIG_ARMADA_XP) += ddr/marvell/axp/
 obj-$(CONFIG_ALTERA_SDRAM) += ddr/altera/
 obj-$(CONFIG_SPL_SERIAL_SUPPORT) += serial/
-obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
 obj-$(CONFIG_SPL_SPI_SUPPORT) += spi/
 obj-$(CONFIG_SPL_POWER_SUPPORT) += power/ power/pmic/
 obj-$(CONFIG_SPL_POWER_SUPPORT) += power/regulator/
+obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
 obj-$(CONFIG_SPL_MTD_SUPPORT) += mtd/
 obj-$(CONFIG_SPL_NAND_SUPPORT) += mtd/nand/
-obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
 obj-$(CONFIG_SPL_ONENAND_SUPPORT) += mtd/onenand/
+obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
 obj-$(CONFIG_SPL_DMA_SUPPORT) += dma/
 obj-$(CONFIG_SPL_ETH_SUPPORT) += net/
 obj-$(CONFIG_SPL_ETH_SUPPORT) += net/phy/
-- 
2.1.4

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

* [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
  2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
@ 2016-01-17  3:12 ` Ladislav Michl
  2016-01-21  6:05   ` Heiko Schocher
  2016-01-17  3:13 ` [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:12 UTC (permalink / raw)
  To: u-boot

From: Thomas Gleixner <tglx@linutronix.de>

To support UBI in SPL we need a simple NAND read function. Add one to
nand_spl_simple and keep it as simple as it goes.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Acked-by: Scott Wood <oss@buserror.net>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
Changes in v3:
- Rename nand_spl_read_flash to nand_spl_read_block and optimize it.

 drivers/mtd/nand/nand_spl_simple.c | 62 ++++++++++++++++++++++++++++++++++++++
 include/nand.h                     |  1 +
 2 files changed, 63 insertions(+)

diff --git a/drivers/mtd/nand/nand_spl_simple.c b/drivers/mtd/nand/nand_spl_simple.c
index e69f662..cf80903 100644
--- a/drivers/mtd/nand/nand_spl_simple.c
+++ b/drivers/mtd/nand/nand_spl_simple.c
@@ -209,6 +209,68 @@ static int nand_read_page(int block, int page, void *dst)
 }
 #endif
 
+#ifdef CONFIG_SPL_UBI
+/*
+ * Temporary storage for non NAND page aligned and non NAND page sized
+ * reads. Note: This does not support runtime detected FLASH yet, but
+ * that should be reasonably easy to fix by making the buffer large
+ * enough :)
+ */
+static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
+
+/**
+ * nand_spl_read_block - Read data from physical eraseblock into a buffer
+ * @block:	Number of the physical eraseblock
+ * @offset:	Data offset from the start of @peb
+ * @len:	Data size to read
+ * @dst:	Address of the destination buffer
+ *
+ * This could be further optimized if we'd have a subpage read
+ * function in the simple code. On NAND which allows subpage reads
+ * this would spare quite some time to readout e.g. the VID header of
+ * UBI.
+ *
+ * Notes:
+ *	@offset + @len are not allowed to be larger than a physical
+ *	erase block. No sanity check done for simplicity reasons.
+ *
+ * To support runtime detected flash this needs to be extended by
+ * information about the actual flash geometry, but thats beyond the
+ * scope of this effort and for most applications where fast boot is
+ * required it is not an issue anyway.
+ */
+int nand_spl_read_block(int block, int offset, int len, void *dst)
+{
+	int page, read;
+
+	/* Calculate the page number */
+	page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
+
+	/* Offset to the start of a flash page */
+	offset = offset % CONFIG_SYS_NAND_PAGE_SIZE;
+
+	while (len) {
+		/*
+		 * Non page aligned reads go to the scratch buffer.
+		 * Page aligned reads go directly to the destination.
+		 */
+		if (offset || len < CONFIG_SYS_NAND_PAGE_SIZE) {
+			nand_read_page(block, page, scratch_buf);
+			read = min(len, CONFIG_SYS_NAND_PAGE_SIZE - offset);
+			memcpy(dst, scratch_buf + offset, read);
+			offset = 0;
+		} else {
+			nand_read_page(block, page, dst);
+			read = CONFIG_SYS_NAND_PAGE_SIZE;
+		}
+		page++;
+		len -= read;
+		dst += read;
+	}
+	return 0;
+}
+#endif
+
 int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
 {
 	unsigned int block, lastblock;
diff --git a/include/nand.h b/include/nand.h
index d2a53ab..2f9a1ec 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -124,6 +124,7 @@ int nand_unlock(nand_info_t *meminfo, loff_t start, size_t length,
 int nand_get_lock_status(nand_info_t *meminfo, loff_t offset);
 
 int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
+int nand_spl_read_block(int block, int offset, int len, void *dst);
 void nand_deselect(void);
 
 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
-- 
2.1.4

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

* [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
  2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
  2016-01-17  3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
@ 2016-01-17  3:13 ` Ladislav Michl
  2016-01-17  3:13 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Ladislav Michl
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:13 UTC (permalink / raw)
  To: u-boot

From: Thomas Gleixner <tglx@linutronix.de>

Booting a payload out of NAND FLASH from the SPL is a crux today, as
it requires hard partioned FLASH. Not a brilliant idea with the
reliability of todays NAND FLASH chips.

The upstream UBI + UBI fastmap implementation which is about to
brought to u-boot is too heavy weight for SPLs as it provides way more
functionality than needed for a SPL and does not even fit into the
restricted SPL areas which are loaded from the SoC boot ROM.

So this provides a fast and lightweight implementation of UBI scanning
and UBI fastmap attach. The scan and logical to physical block mapping
code is developed from scratch, while the fastmap implementation is
lifted from the linux kernel source and stripped down to fit the SPL
needs.

The text foot print on the board which I used for development is:

6854	0	0	6854	1abd
drivers/mtd/ubispl/built-in.o

Attaching a NAND chip with 4096 physical eraseblocks (4 blocks are
reserved for the SPL) takes:

In full scan mode:      1172ms
In fastmap mode:          95ms

The code requires quite some storage. The largest and unknown part of
it is the number of fastmap blocks to read. Therefor the data
structure is not put into the BSS. The code requires a pointer to free
memory handed in which is initialized by the UBI attach code itself.

See doc/README.ubispl for further information on how to use it.

This shares the ubi-media.h and crc32 implementation of drivers/mtd/ubi
There is no way to share the fastmap code, as UBISPL only utilizes the
slightly modified functions ubi_attach_fastmap() and ubi_scan_fastmap()
from the original kernel ubi fastmap implementation.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Acked-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
Changes in v2:
  - fixes ubi_calc_fm_size to include also sizeof(struct ubi_fm_sb)
  - dropped private copy of ubi-media.h
  - ubi-wrapper.h now contains only needed definitions from ubi.h
    and ubi-user.h
  - used return values from errno.h

Changes in v3:
  - move vol_id check to ubi_scan_vid_hdr to verify it has meaningfull value
    before testing ubi->toload
  - fixed checkpatch errors except those present also in linux code

Changes in v4:
  - drop unused name field from ubispl_load structure
  - ipl_load returns lenght read

 README                           |   4 +
 doc/README.ubispl                | 141 ++++++
 drivers/Makefile                 |   1 +
 drivers/mtd/ubispl/Makefile      |   1 +
 drivers/mtd/ubispl/ubi-wrapper.h | 106 +++++
 drivers/mtd/ubispl/ubispl.c      | 926 +++++++++++++++++++++++++++++++++++++++
 drivers/mtd/ubispl/ubispl.h      | 136 ++++++
 include/ubispl.h                 |  90 ++++
 8 files changed, 1405 insertions(+)
 create mode 100644 doc/README.ubispl
 create mode 100644 drivers/mtd/ubispl/Makefile
 create mode 100644 drivers/mtd/ubispl/ubi-wrapper.h
 create mode 100644 drivers/mtd/ubispl/ubispl.c
 create mode 100644 drivers/mtd/ubispl/ubispl.h
 create mode 100644 include/ubispl.h

diff --git a/README b/README
index 9423c34..e3adbdc 100644
--- a/README
+++ b/README
@@ -3611,6 +3611,10 @@ FIT uImage format:
 		Support for NAND boot using simple NAND drivers that
 		expose the cmd_ctrl() interface.
 
+		CONFIG_SPL_UBI
+		Support for a lightweight UBI (fastmap) scanner and
+		loader
+
 		CONFIG_SPL_MTD_SUPPORT
 		Support for the MTD subsystem within SPL.  Useful for
 		environment on NAND support within SPL.
diff --git a/doc/README.ubispl b/doc/README.ubispl
new file mode 100644
index 0000000..ddb629d
--- /dev/null
+++ b/doc/README.ubispl
@@ -0,0 +1,141 @@
+Lightweight UBI and UBI fastmap support
+
+# Copyright (C) Thomas Gleixner <tglx@linutronix.de>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+
+Scans the UBI information and loads the requested static volumes into
+memory.
+
+Configuration Options:
+
+   CONFIG_SPL_UBI
+     Enables the SPL UBI support
+
+   CONFIG_SPL_UBI_MAX_VOL_LEBS
+     The maximum number of logical eraseblocks which a static volume
+     to load can contain. Used for sizing the scan data structure
+
+   CONFIG_SPL_UBI_MAX_PEB_SIZE
+     The maximum physical erase block size. Either a compile time
+     constant or runtime detection. Used for sizing the scan data
+     structure
+
+   CONFIG_SPL_UBI_MAX_PEBS
+     The maximum physical erase block count. Either a compile time
+     constant or runtime detection. Used for sizing the scan data
+     structure
+
+   CONFIG_SPL_UBI_VOL_IDS
+     The maximum volume ids which can be loaded. Used for sizing the
+     scan data structure.
+
+Usage notes:
+
+In the board config file define for example:
+
+#define CONFIG_SPL_UBI
+#define CONFIG_SPL_UBI_MAX_VOL_LEBS	256
+#define CONFIG_SPL_UBI_MAX_PEB_SIZE	(256*1024)
+#define CONFIG_SPL_UBI_MAX_PEBS		4096
+#define CONFIG_SPL_UBI_VOL_IDS		8
+
+The size requirement is roughly as follows:
+
+    2k for the basic data structure
+  + CONFIG_SPL_UBI_VOL_IDS * CONFIG_SPL_UBI_MAX_VOL_LEBS * 8
+  + CONFIG_SPL_UBI_MAX_PEBS * 64
+  + CONFIG_SPL_UBI_MAX_PEB_SIZE * UBI_FM_MAX_BLOCKS
+
+The last one is big, but I really don't care in that stage. Real world
+implementations only use the first couple of blocks, but the code
+handles up to UBI_FM_MAX_BLOCKS.
+
+Given the above configuration example the requirement is about 5M
+which is usually not a problem to reserve in the RAM along with the
+other areas like the kernel/dts load address.
+
+So something like this will do the trick:
+
+#define SPL_FINFO_ADDR			0x80800000
+#define SPL_DTB_LOAD_ADDR		0x81800000
+#define SPL_KERNEL_LOAD_ADDR		0x82000000
+
+In the board file, implement the following:
+
+static struct ubispl_load myvolumes[] = {
+	{
+		.vol_id		= 0,	/* kernel volume */
+		.load_addr	= (void *)SPL_KERNEL_LOAD_ADDR,
+	},
+	{
+		.vol_id		= 1,	/* DT blob */
+		.load_addr	= (void *)SPL_DTB_LOAD_ADDR,
+	}
+};
+
+int spl_start_uboot(void)
+{
+	struct ubispl_info info;
+
+	info.ubi = (struct ubi_scan_info *) SPL_FINFO_ADDR;
+	info.fastmap = 1;
+	info.read = nand_spl_read_flash;
+
+#if COMPILE_TIME_DEFINED
+	/*
+	 * MY_NAND_NR_SPL_PEBS is the number of physical erase blocks
+	 * in the FLASH which are reserved for the SPL. Think about
+	 * mtd partitions:
+	 *
+	 * part_spl { .start = 0, .end = 4 }
+	 * part_ubi { .start = 4, .end = NR_PEBS }
+	 */
+	info.peb_offset = MY_NAND_NR_SPL_PEBS;
+	info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
+	info.vid_offset = MY_NAND_UBI_VID_OFFS;
+	info.leb_start = MY_NAND_UBI_DATA_OFFS;
+	info.peb_count = MY_NAND_UBI_NUM_PEBS;
+#else
+	get_flash_info(&flash_info);
+	info.peb_offset = MY_NAND_NR_SPL_PEBS;
+	info.peb_size = flash_info.peb_size;
+
+	/*
+	 * The VID and Data offset depend on the capability of the
+	 * FLASH chip to do subpage writes.
+	 *
+	 * If the flash chip supports subpage writes, then the VID
+	 * header starts at the second subpage. So for 2k pages size
+	 * with 4 subpages the VID offset is 512. The DATA offset is 2k.
+	 *
+	 * If the flash chip does not support subpage writes then the
+	 * VID offset is FLASH_PAGE_SIZE and the DATA offset
+	 * 2 * FLASH_PAGE_SIZE
+	 */
+	info.vid_offset = flash_info.vid_offset;
+	info.leb_start = flash_info.data_offset;
+
+	/*
+	 * The flash reports the total number of erase blocks, so
+	 * we need to subtract the number of blocks which are reserved
+	 * for the SPL itself and not managed by UBI.
+	 */
+	info.peb_count = flash_info.peb_count - MY_NAND_NR_SPL_PEBS;
+#endif
+
+	ret = ubispl_load_volumes(&info, myvolumes, ARRAY_SIZE(myvolumes);
+
+	....
+
+}
+
+Note: you can load any payload that way. You can even load u-boot from
+UBI, so the only non UBI managed FLASH area is the one which is
+reserved for the SPL itself and read from the SoC ROM.
+
+And you can do fallback scenarios:
+
+    if (ubispl_load_volumes(&info, volumes0, ARRAY_SIZE(volumes0)))
+        if (ubispl_load_volumes(&info, volumes1, ARRAY_SIZE(volumes1)))
+	    ubispl_load_volumes(&info, vol_uboot, ARRAY_SIZE(vol_uboot));
diff --git a/drivers/Makefile b/drivers/Makefile
index 1b9f8d6..7b3a3c4 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_SPL_MTD_SUPPORT) += mtd/
 obj-$(CONFIG_SPL_NAND_SUPPORT) += mtd/nand/
 obj-$(CONFIG_SPL_ONENAND_SUPPORT) += mtd/onenand/
 obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
+obj-$(CONFIG_SPL_UBI) += mtd/ubispl/
 obj-$(CONFIG_SPL_DMA_SUPPORT) += dma/
 obj-$(CONFIG_SPL_ETH_SUPPORT) += net/
 obj-$(CONFIG_SPL_ETH_SUPPORT) += net/phy/
diff --git a/drivers/mtd/ubispl/Makefile b/drivers/mtd/ubispl/Makefile
new file mode 100644
index 0000000..740dbed
--- /dev/null
+++ b/drivers/mtd/ubispl/Makefile
@@ -0,0 +1 @@
+obj-y += ubispl.o ../ubi/crc32.o
diff --git a/drivers/mtd/ubispl/ubi-wrapper.h b/drivers/mtd/ubispl/ubi-wrapper.h
new file mode 100644
index 0000000..4e27c01
--- /dev/null
+++ b/drivers/mtd/ubispl/ubi-wrapper.h
@@ -0,0 +1,106 @@
+/*
+ * The parts taken from the kernel implementation are:
+ *
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * UBISPL specific defines:
+ *
+ * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/*
+ * Contains various defines copy&pasted from ubi.h and ubi-user.h to make
+ * the upstream fastboot code happy.
+ */
+#ifndef __UBOOT_UBI_WRAPPER_H
+#define __UBOOT_UBI_WRAPPER_H
+
+/*
+ * Error codes returned by the I/O sub-system.
+ *
+ * UBI_IO_FF: the read region of flash contains only 0xFFs
+ * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data
+ *                     integrity error reported by the MTD driver
+ *                     (uncorrectable ECC error in case of NAND)
+ * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
+ * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a
+ *                         data integrity error reported by the MTD driver
+ *                         (uncorrectable ECC error in case of NAND)
+ * UBI_IO_BITFLIPS: bit-flips were detected and corrected
+ *
+ * UBI_FASTMAP_ANCHOR:  u-boot SPL add on to tell the caller that the fastmap
+ *			anchor block has been found
+ *
+ * Note, it is probably better to have bit-flip and ebadmsg as flags which can
+ * be or'ed with other error code. But this is a big change because there are
+ * may callers, so it does not worth the risk of introducing a bug
+ */
+enum {
+	UBI_IO_FF = 1,
+	UBI_IO_FF_BITFLIPS,
+	UBI_IO_BAD_HDR,
+	UBI_IO_BAD_HDR_EBADMSG,
+	UBI_IO_BITFLIPS,
+	UBI_FASTMAP_ANCHOR,
+};
+
+/*
+ * UBI volume type constants.
+ *
+ * @UBI_DYNAMIC_VOLUME: dynamic volume
+ * @UBI_STATIC_VOLUME:  static volume
+ */
+enum {
+	UBI_DYNAMIC_VOLUME = 3,
+	UBI_STATIC_VOLUME  = 4,
+};
+
+/*
+ * Return codes of the fastmap sub-system
+ *
+ * UBI_NO_FASTMAP: No fastmap super block was found
+ * UBI_BAD_FASTMAP: A fastmap was found but it's unusable
+ */
+enum {
+	UBI_NO_FASTMAP = 1,
+	UBI_BAD_FASTMAP,
+};
+
+/**
+ * struct ubi_fastmap_layout - in-memory fastmap data structure.
+ * @e: PEBs used by the current fastmap
+ * @to_be_tortured: if non-zero tortured this PEB
+ * @used_blocks: number of used PEBs
+ * @max_pool_size: maximal size of the user pool
+ * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
+ */
+struct ubi_fastmap_layout {
+	struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS];
+	int to_be_tortured[UBI_FM_MAX_BLOCKS];
+	int used_blocks;
+	int max_pool_size;
+	int max_wl_pool_size;
+};
+
+/**
+ * struct ubi_fm_pool - in-memory fastmap pool
+ * @pebs: PEBs in this pool
+ * @used: number of used PEBs
+ * @size: total number of PEBs in this pool
+ * @max_size: maximal size of the pool
+ *
+ * A pool gets filled with up to max_size.
+ * If all PEBs within the pool are used a new fastmap will be written
+ * to the flash and the pool gets refilled with empty PEBs.
+ *
+ */
+struct ubi_fm_pool {
+	int pebs[UBI_FM_MAX_POOL_SIZE];
+	int used;
+	int size;
+	int max_size;
+};
+
+#endif
diff --git a/drivers/mtd/ubispl/ubispl.c b/drivers/mtd/ubispl/ubispl.c
new file mode 100644
index 0000000..b9c8543
--- /dev/null
+++ b/drivers/mtd/ubispl/ubispl.c
@@ -0,0 +1,926 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
+ *
+ * The parts taken from the kernel implementation are:
+ *
+ * Copyright (c) International Business Machines Corp., 2006
+
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <ubispl.h>
+
+#include <linux/crc32.h>
+
+#include "ubispl.h"
+
+/**
+ * ubi_calc_fm_size - calculates the fastmap size in bytes for an UBI device.
+ * @ubi: UBI device description object
+ */
+static size_t ubi_calc_fm_size(struct ubi_scan_info *ubi)
+{
+	size_t size;
+
+	size = sizeof(struct ubi_fm_sb) +
+		sizeof(struct ubi_fm_hdr) +
+		sizeof(struct ubi_fm_scan_pool) +
+		sizeof(struct ubi_fm_scan_pool) +
+		(ubi->peb_count * sizeof(struct ubi_fm_ec)) +
+		(sizeof(struct ubi_fm_eba) +
+		(ubi->peb_count * sizeof(__be32))) +
+		sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES;
+	return roundup(size, ubi->leb_size);
+}
+
+static int ubi_io_read(struct ubi_scan_info *ubi, void *buf, int pnum,
+		       unsigned long from, unsigned long len)
+{
+	return ubi->read(pnum + ubi->peb_offset, from, len, buf);
+}
+
+static int ubi_io_is_bad(struct ubi_scan_info *ubi, int peb)
+{
+	return peb >= ubi->peb_count || peb < 0;
+}
+
+static int ubi_io_read_vid_hdr(struct ubi_scan_info *ubi, int pnum,
+			       struct ubi_vid_hdr *vh, int unused)
+{
+	u32 magic;
+	int res;
+
+	/* No point in rescanning a corrupt block */
+	if (test_bit(pnum, ubi->corrupt))
+		return UBI_IO_BAD_HDR;
+	/*
+	 * If the block has been scanned already, no need to rescan
+	 */
+	if (test_and_set_bit(pnum, ubi->scanned))
+		return 0;
+
+	res = ubi_io_read(ubi, vh, pnum, ubi->vid_offset, sizeof(*vh));
+
+	/*
+	 * Bad block, unrecoverable ECC error, skip the block
+	 */
+	if (res) {
+		ubi_dbg("Skipping bad or unreadable block %d", pnum);
+		vh->magic = 0;
+		generic_set_bit(pnum, ubi->corrupt);
+		return res;
+	}
+
+	/* Magic number available ? */
+	magic = be32_to_cpu(vh->magic);
+	if (magic != UBI_VID_HDR_MAGIC) {
+		generic_set_bit(pnum, ubi->corrupt);
+		if (magic == 0xffffffff)
+			return UBI_IO_FF;
+		ubi_msg("Bad magic in block 0%d %08x", pnum, magic);
+		return UBI_IO_BAD_HDR;
+	}
+
+	/* Header CRC correct ? */
+	if (crc32(UBI_CRC32_INIT, vh, UBI_VID_HDR_SIZE_CRC) !=
+	    be32_to_cpu(vh->hdr_crc)) {
+		ubi_msg("Bad CRC in block 0%d", pnum);
+		generic_set_bit(pnum, ubi->corrupt);
+		return UBI_IO_BAD_HDR;
+	}
+
+	ubi_dbg("RV: pnum: %i sqnum %llu", pnum, be64_to_cpu(vh->sqnum));
+
+	return 0;
+}
+
+static int ubi_rescan_fm_vid_hdr(struct ubi_scan_info *ubi,
+				 struct ubi_vid_hdr *vh,
+				 u32 fm_pnum, u32 fm_vol_id, u32 fm_lnum)
+{
+	int res;
+
+	if (ubi_io_is_bad(ubi, fm_pnum))
+		return -EINVAL;
+
+	res = ubi_io_read_vid_hdr(ubi, fm_pnum, vh, 0);
+	if (!res) {
+		/* Check volume id, volume type and lnum */
+		if (be32_to_cpu(vh->vol_id) == fm_vol_id &&
+		    vh->vol_type == UBI_VID_STATIC &&
+		    be32_to_cpu(vh->lnum) == fm_lnum)
+			return 0;
+		ubi_dbg("RS: PEB %u vol: %u : %u typ %u lnum %u %u",
+			fm_pnum, fm_vol_id, vh->vol_type,
+			be32_to_cpu(vh->vol_id),
+			fm_lnum, be32_to_cpu(vh->lnum));
+	}
+	return res;
+}
+
+/* Insert the logic block into the volume info */
+static int ubi_add_peb_to_vol(struct ubi_scan_info *ubi,
+			      struct ubi_vid_hdr *vh, u32 vol_id,
+			      u32 pnum, u32 lnum)
+{
+	struct ubi_vol_info *vi = ubi->volinfo + vol_id;
+	u32 *ltp;
+
+	/*
+	 * If the volume is larger than expected, yell and give up :(
+	 */
+	if (lnum >= UBI_MAX_VOL_LEBS) {
+		ubi_warn("Vol: %u LEB %d > %d", vol_id, lnum, UBI_MAX_VOL_LEBS);
+		return -EINVAL;
+	}
+
+	ubi_dbg("SC: Add PEB %u to Vol %u as LEB %u fnd %d sc %d",
+		pnum, vol_id, lnum, !!test_bit(lnum, vi->found),
+		!!test_bit(pnum, ubi->scanned));
+
+	/* Points to the translation entry */
+	ltp = vi->lebs_to_pebs + lnum;
+
+	/* If the block is already assigned, check sqnum */
+	if (__test_and_set_bit(lnum, vi->found)) {
+		u32 cur_pnum = *ltp;
+		struct ubi_vid_hdr *cur = ubi->blockinfo + cur_pnum;
+
+		/*
+		 * If the current block hase not yet been scanned, we
+		 * need to do that. The other block might be stale or
+		 * the current block corrupted and the FM not yet
+		 * updated.
+		 */
+		if (!test_bit(cur_pnum, ubi->scanned)) {
+			/*
+			 * If the scan fails, we use the valid block
+			 */
+			if (ubi_rescan_fm_vid_hdr(ubi, cur, cur_pnum, vol_id,
+						  lnum)) {
+				*ltp = pnum;
+				return 0;
+			}
+		}
+
+		/*
+		 * Should not happen ....
+		 */
+		if (test_bit(cur_pnum, ubi->corrupt)) {
+			*ltp = pnum;
+			return 0;
+		}
+
+		ubi_dbg("Vol %u LEB %u PEB %u->sqnum %llu NPEB %u->sqnum %llu",
+			vol_id, lnum, cur_pnum, be64_to_cpu(cur->sqnum), pnum,
+			be64_to_cpu(vh->sqnum));
+
+		/*
+		 * Compare sqnum and take the newer one
+		 */
+		if (be64_to_cpu(cur->sqnum) < be64_to_cpu(vh->sqnum))
+			*ltp = pnum;
+	} else {
+		*ltp = pnum;
+		if (lnum > vi->last_block)
+			vi->last_block = lnum;
+	}
+
+	return 0;
+}
+
+static int ubi_scan_vid_hdr(struct ubi_scan_info *ubi, struct ubi_vid_hdr *vh,
+			    u32 pnum)
+{
+	u32 vol_id, lnum;
+	int res;
+
+	if (ubi_io_is_bad(ubi, pnum))
+		return -EINVAL;
+
+	res = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
+	if (res)
+		return res;
+
+	/* Get volume id */
+	vol_id = be32_to_cpu(vh->vol_id);
+
+	/* If this is the fastmap anchor, return right away */
+	if (vol_id == UBI_FM_SB_VOLUME_ID)
+		return ubi->fm_enabled ? UBI_FASTMAP_ANCHOR : 0;
+
+	/* We only care about static volumes with an id < UBI_SPL_VOL_IDS */
+	if (vol_id >= UBI_SPL_VOL_IDS || vh->vol_type != UBI_VID_STATIC)
+		return 0;
+
+	/* We are only interested in the volumes to load */
+	if (!test_bit(vol_id, ubi->toload))
+		return 0;
+
+	lnum = be32_to_cpu(vh->lnum);
+	return ubi_add_peb_to_vol(ubi, vh, vol_id, pnum, lnum);
+}
+
+static int assign_aeb_to_av(struct ubi_scan_info *ubi, u32 pnum, u32 lnum,
+			     u32 vol_id, u32 vol_type, u32 used)
+{
+	struct ubi_vid_hdr *vh;
+
+	if (ubi_io_is_bad(ubi, pnum))
+		return -EINVAL;
+
+	ubi->fastmap_pebs++;
+
+	if (vol_id >= UBI_SPL_VOL_IDS || vol_type != UBI_STATIC_VOLUME)
+		return 0;
+
+	/* We are only interested in the volumes to load */
+	if (!test_bit(vol_id, ubi->toload))
+		return 0;
+
+	vh = ubi->blockinfo + pnum;
+
+	return ubi_scan_vid_hdr(ubi, vh, pnum);
+}
+
+static int scan_pool(struct ubi_scan_info *ubi, __be32 *pebs, int pool_size)
+{
+	struct ubi_vid_hdr *vh;
+	u32 pnum;
+	int i;
+
+	ubi_dbg("Scanning pool size: %d", pool_size);
+
+	for (i = 0; i < pool_size; i++) {
+		pnum = be32_to_cpu(pebs[i]);
+
+		if (ubi_io_is_bad(ubi, pnum)) {
+			ubi_err("FM: Bad PEB in fastmap pool! %u", pnum);
+			return UBI_BAD_FASTMAP;
+		}
+
+		vh = ubi->blockinfo + pnum;
+		/*
+		 * We allow the scan to fail here. The loader will notice
+		 * and look for a replacement.
+		 */
+		ubi_scan_vid_hdr(ubi, vh, pnum);
+	}
+	return 0;
+}
+
+/*
+ * Fastmap code is stolen from Linux kernel and this stub structure is used
+ * to make it happy.
+ */
+struct ubi_attach_info {
+	int i;
+};
+
+static int ubi_attach_fastmap(struct ubi_scan_info *ubi,
+			      struct ubi_attach_info *ai,
+			      struct ubi_fastmap_layout *fm)
+{
+	struct ubi_fm_hdr *fmhdr;
+	struct ubi_fm_scan_pool *fmpl1, *fmpl2;
+	struct ubi_fm_ec *fmec;
+	struct ubi_fm_volhdr *fmvhdr;
+	struct ubi_fm_eba *fm_eba;
+	int ret, i, j, pool_size, wl_pool_size;
+	size_t fm_pos = 0, fm_size = ubi->fm_size;
+	void *fm_raw = ubi->fm_buf;
+
+	memset(ubi->fm_used, 0, sizeof(ubi->fm_used));
+
+	fm_pos += sizeof(struct ubi_fm_sb);
+	if (fm_pos >= fm_size)
+		goto fail_bad;
+
+	fmhdr = (struct ubi_fm_hdr *)(fm_raw + fm_pos);
+	fm_pos += sizeof(*fmhdr);
+	if (fm_pos >= fm_size)
+		goto fail_bad;
+
+	if (be32_to_cpu(fmhdr->magic) != UBI_FM_HDR_MAGIC) {
+		ubi_err("bad fastmap header magic: 0x%x, expected: 0x%x",
+			be32_to_cpu(fmhdr->magic), UBI_FM_HDR_MAGIC);
+		goto fail_bad;
+	}
+
+	fmpl1 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+	fm_pos += sizeof(*fmpl1);
+	if (fm_pos >= fm_size)
+		goto fail_bad;
+	if (be32_to_cpu(fmpl1->magic) != UBI_FM_POOL_MAGIC) {
+		ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x",
+			be32_to_cpu(fmpl1->magic), UBI_FM_POOL_MAGIC);
+		goto fail_bad;
+	}
+
+	fmpl2 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+	fm_pos += sizeof(*fmpl2);
+	if (fm_pos >= fm_size)
+		goto fail_bad;
+	if (be32_to_cpu(fmpl2->magic) != UBI_FM_POOL_MAGIC) {
+		ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x",
+			be32_to_cpu(fmpl2->magic), UBI_FM_POOL_MAGIC);
+		goto fail_bad;
+	}
+
+	pool_size = be16_to_cpu(fmpl1->size);
+	wl_pool_size = be16_to_cpu(fmpl2->size);
+	fm->max_pool_size = be16_to_cpu(fmpl1->max_size);
+	fm->max_wl_pool_size = be16_to_cpu(fmpl2->max_size);
+
+	if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) {
+		ubi_err("bad pool size: %i", pool_size);
+		goto fail_bad;
+	}
+
+	if (wl_pool_size > UBI_FM_MAX_POOL_SIZE || wl_pool_size < 0) {
+		ubi_err("bad WL pool size: %i", wl_pool_size);
+		goto fail_bad;
+	}
+
+	if (fm->max_pool_size > UBI_FM_MAX_POOL_SIZE ||
+	    fm->max_pool_size < 0) {
+		ubi_err("bad maximal pool size: %i", fm->max_pool_size);
+		goto fail_bad;
+	}
+
+	if (fm->max_wl_pool_size > UBI_FM_MAX_POOL_SIZE ||
+	    fm->max_wl_pool_size < 0) {
+		ubi_err("bad maximal WL pool size: %i", fm->max_wl_pool_size);
+		goto fail_bad;
+	}
+
+	/* read EC values from free list */
+	for (i = 0; i < be32_to_cpu(fmhdr->free_peb_count); i++) {
+		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fmec);
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+	}
+
+	/* read EC values from used list */
+	for (i = 0; i < be32_to_cpu(fmhdr->used_peb_count); i++) {
+		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fmec);
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+
+		generic_set_bit(be32_to_cpu(fmec->pnum), ubi->fm_used);
+	}
+
+	/* read EC values from scrub list */
+	for (i = 0; i < be32_to_cpu(fmhdr->scrub_peb_count); i++) {
+		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fmec);
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+	}
+
+	/* read EC values from erase list */
+	for (i = 0; i < be32_to_cpu(fmhdr->erase_peb_count); i++) {
+		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fmec);
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+	}
+
+	/* Iterate over all volumes and read their EBA table */
+	for (i = 0; i < be32_to_cpu(fmhdr->vol_count); i++) {
+		u32 vol_id, vol_type, used, reserved;
+
+		fmvhdr = (struct ubi_fm_volhdr *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fmvhdr);
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+
+		if (be32_to_cpu(fmvhdr->magic) != UBI_FM_VHDR_MAGIC) {
+			ubi_err("bad fastmap vol header magic: 0x%x, " \
+				"expected: 0x%x",
+				be32_to_cpu(fmvhdr->magic), UBI_FM_VHDR_MAGIC);
+			goto fail_bad;
+		}
+
+		vol_id = be32_to_cpu(fmvhdr->vol_id);
+		vol_type = fmvhdr->vol_type;
+		used = be32_to_cpu(fmvhdr->used_ebs);
+
+		fm_eba = (struct ubi_fm_eba *)(fm_raw + fm_pos);
+		fm_pos += sizeof(*fm_eba);
+		fm_pos += (sizeof(__be32) * be32_to_cpu(fm_eba->reserved_pebs));
+		if (fm_pos >= fm_size)
+			goto fail_bad;
+
+		if (be32_to_cpu(fm_eba->magic) != UBI_FM_EBA_MAGIC) {
+			ubi_err("bad fastmap EBA header magic: 0x%x, " \
+				"expected: 0x%x",
+				be32_to_cpu(fm_eba->magic), UBI_FM_EBA_MAGIC);
+			goto fail_bad;
+		}
+
+		reserved = be32_to_cpu(fm_eba->reserved_pebs);
+		ubi_dbg("FA: vol %u used %u res: %u", vol_id, used, reserved);
+		for (j = 0; j < reserved; j++) {
+			int pnum = be32_to_cpu(fm_eba->pnum[j]);
+
+			if ((int)be32_to_cpu(fm_eba->pnum[j]) < 0)
+				continue;
+
+			if (!__test_and_clear_bit(pnum, ubi->fm_used))
+				continue;
+
+			/*
+			 * We only handle static volumes so used_ebs
+			 * needs to be handed in. And we do not assign
+			 * the reserved blocks
+			 */
+			if (j >= used)
+				continue;
+
+			ret = assign_aeb_to_av(ubi, pnum, j, vol_id,
+					       vol_type, used);
+			if (!ret)
+				continue;
+
+			/*
+			 * Nasty: The fastmap claims that the volume
+			 * has one block more than it, but that block
+			 * is always empty and the other blocks have
+			 * the correct number of total LEBs in the
+			 * headers. Deal with it.
+			 */
+			if (ret != UBI_IO_FF && j != used - 1)
+				goto fail_bad;
+			ubi_dbg("FA: Vol: %u Ignoring empty LEB %d of %d",
+				vol_id, j, used);
+		}
+	}
+
+	ret = scan_pool(ubi, fmpl1->pebs, pool_size);
+	if (ret)
+		goto fail;
+
+	ret = scan_pool(ubi, fmpl2->pebs, wl_pool_size);
+	if (ret)
+		goto fail;
+
+#ifdef CHECKME
+	/*
+	 * If fastmap is leaking PEBs (must not happen), raise a
+	 * fat warning and fall back to scanning mode.
+	 * We do this here because in ubi_wl_init() it's too late
+	 * and we cannot fall back to scanning.
+	 */
+	if (WARN_ON(count_fastmap_pebs(ai) != ubi->peb_count -
+		    ai->bad_peb_count - fm->used_blocks))
+		goto fail_bad;
+#endif
+
+	return 0;
+
+fail_bad:
+	ret = UBI_BAD_FASTMAP;
+fail:
+	return ret;
+}
+
+static int ubi_scan_fastmap(struct ubi_scan_info *ubi,
+			    struct ubi_attach_info *ai,
+			    int fm_anchor)
+{
+	struct ubi_fm_sb *fmsb, *fmsb2;
+	struct ubi_vid_hdr *vh;
+	struct ubi_fastmap_layout *fm;
+	int i, used_blocks, pnum, ret = 0;
+	size_t fm_size;
+	__be32 crc, tmp_crc;
+	unsigned long long sqnum = 0;
+
+	fmsb = &ubi->fm_sb;
+	fm = &ubi->fm_layout;
+
+	ret = ubi_io_read(ubi, fmsb, fm_anchor, ubi->leb_start, sizeof(*fmsb));
+	if (ret && ret != UBI_IO_BITFLIPS)
+		goto free_fm_sb;
+	else if (ret == UBI_IO_BITFLIPS)
+		fm->to_be_tortured[0] = 1;
+
+	if (be32_to_cpu(fmsb->magic) != UBI_FM_SB_MAGIC) {
+		ubi_err("bad super block magic: 0x%x, expected: 0x%x",
+			be32_to_cpu(fmsb->magic), UBI_FM_SB_MAGIC);
+		ret = UBI_BAD_FASTMAP;
+		goto free_fm_sb;
+	}
+
+	if (fmsb->version != UBI_FM_FMT_VERSION) {
+		ubi_err("bad fastmap version: %i, expected: %i",
+			fmsb->version, UBI_FM_FMT_VERSION);
+		ret = UBI_BAD_FASTMAP;
+		goto free_fm_sb;
+	}
+
+	used_blocks = be32_to_cpu(fmsb->used_blocks);
+	if (used_blocks > UBI_FM_MAX_BLOCKS || used_blocks < 1) {
+		ubi_err("number of fastmap blocks is invalid: %i", used_blocks);
+		ret = UBI_BAD_FASTMAP;
+		goto free_fm_sb;
+	}
+
+	fm_size = ubi->leb_size * used_blocks;
+	if (fm_size != ubi->fm_size) {
+		ubi_err("bad fastmap size: %zi, expected: %zi", fm_size,
+			ubi->fm_size);
+		ret = UBI_BAD_FASTMAP;
+		goto free_fm_sb;
+	}
+
+	vh = &ubi->fm_vh;
+
+	for (i = 0; i < used_blocks; i++) {
+		pnum = be32_to_cpu(fmsb->block_loc[i]);
+
+		if (ubi_io_is_bad(ubi, pnum)) {
+			ret = UBI_BAD_FASTMAP;
+			goto free_hdr;
+		}
+
+#ifdef LATER
+		int image_seq;
+		ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
+		if (ret && ret != UBI_IO_BITFLIPS) {
+			ubi_err("unable to read fastmap block# %i EC (PEB: %i)",
+				i, pnum);
+			if (ret > 0)
+				ret = UBI_BAD_FASTMAP;
+			goto free_hdr;
+		} else if (ret == UBI_IO_BITFLIPS)
+			fm->to_be_tortured[i] = 1;
+
+		image_seq = be32_to_cpu(ech->image_seq);
+		if (!ubi->image_seq)
+			ubi->image_seq = image_seq;
+		/*
+		 * Older UBI implementations have image_seq set to zero, so
+		 * we shouldn't fail if image_seq == 0.
+		 */
+		if (image_seq && (image_seq != ubi->image_seq)) {
+			ubi_err("wrong image seq:%d instead of %d",
+				be32_to_cpu(ech->image_seq), ubi->image_seq);
+			ret = UBI_BAD_FASTMAP;
+			goto free_hdr;
+		}
+#endif
+		ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
+		if (ret && ret != UBI_IO_BITFLIPS) {
+			ubi_err("unable to read fastmap block# %i (PEB: %i)",
+				i, pnum);
+			goto free_hdr;
+		}
+
+		/*
+		 * Mainline code rescans the anchor header. We've done
+		 * that already so we merily copy it over.
+		 */
+		if (pnum == fm_anchor)
+			memcpy(vh, ubi->blockinfo + pnum, sizeof(*fm));
+
+		if (i == 0) {
+			if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) {
+				ubi_err("bad fastmap anchor vol_id: 0x%x," \
+					" expected: 0x%x",
+					be32_to_cpu(vh->vol_id),
+					UBI_FM_SB_VOLUME_ID);
+				ret = UBI_BAD_FASTMAP;
+				goto free_hdr;
+			}
+		} else {
+			if (be32_to_cpu(vh->vol_id) != UBI_FM_DATA_VOLUME_ID) {
+				ubi_err("bad fastmap data vol_id: 0x%x," \
+					" expected: 0x%x",
+					be32_to_cpu(vh->vol_id),
+					UBI_FM_DATA_VOLUME_ID);
+				ret = UBI_BAD_FASTMAP;
+				goto free_hdr;
+			}
+		}
+
+		if (sqnum < be64_to_cpu(vh->sqnum))
+			sqnum = be64_to_cpu(vh->sqnum);
+
+		ret = ubi_io_read(ubi, ubi->fm_buf + (ubi->leb_size * i), pnum,
+				  ubi->leb_start, ubi->leb_size);
+		if (ret && ret != UBI_IO_BITFLIPS) {
+			ubi_err("unable to read fastmap block# %i (PEB: %i, " \
+				"err: %i)", i, pnum, ret);
+			goto free_hdr;
+		}
+	}
+
+	fmsb2 = (struct ubi_fm_sb *)(ubi->fm_buf);
+	tmp_crc = be32_to_cpu(fmsb2->data_crc);
+	fmsb2->data_crc = 0;
+	crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size);
+	if (crc != tmp_crc) {
+		ubi_err("fastmap data CRC is invalid");
+		ubi_err("CRC should be: 0x%x, calc: 0x%x", tmp_crc, crc);
+		ret = UBI_BAD_FASTMAP;
+		goto free_hdr;
+	}
+
+	fmsb2->sqnum = sqnum;
+
+	fm->used_blocks = used_blocks;
+
+	ret = ubi_attach_fastmap(ubi, ai, fm);
+	if (ret) {
+		if (ret > 0)
+			ret = UBI_BAD_FASTMAP;
+		goto free_hdr;
+	}
+
+	ubi->fm = fm;
+	ubi->fm_pool.max_size = ubi->fm->max_pool_size;
+	ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
+	ubi_msg("attached by fastmap %uMB %u blocks",
+		ubi->fsize_mb, ubi->peb_count);
+	ubi_dbg("fastmap pool size: %d", ubi->fm_pool.max_size);
+	ubi_dbg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
+
+out:
+	if (ret)
+		ubi_err("Attach by fastmap failed, doing a full scan!");
+	return ret;
+
+free_hdr:
+free_fm_sb:
+	goto out;
+}
+
+/*
+ * Scan the flash and attempt to attach via fastmap
+ */
+static void ipl_scan(struct ubi_scan_info *ubi)
+{
+	unsigned int pnum;
+	int res;
+
+	/*
+	 * Scan first for the fastmap super block
+	 */
+	for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) {
+		res = ubi_scan_vid_hdr(ubi, ubi->blockinfo + pnum, pnum);
+		/*
+		 * We ignore errors here as we are meriliy scanning
+		 * the headers.
+		 */
+		if (res != UBI_FASTMAP_ANCHOR)
+			continue;
+
+		/*
+		 * If fastmap is disabled, continue scanning. This
+		 * might happen because the previous attempt failed or
+		 * the caller disabled it right away.
+		 */
+		if (!ubi->fm_enabled)
+			continue;
+
+		/*
+		 * Try to attach the fastmap, if that fails continue
+		 * scanning.
+		 */
+		if (!ubi_scan_fastmap(ubi, NULL, pnum))
+			return;
+		/*
+		 * Fastmap failed. Clear everything we have and start
+		 * over. We are paranoid and do not trust anything.
+		 */
+		memset(ubi->volinfo, 0, sizeof(ubi->volinfo));
+		pnum = 0;
+		break;
+	}
+
+	/*
+	 * Continue scanning, ignore errors, we might find what we are
+	 * looking for,
+	 */
+	for (; pnum < ubi->peb_count; pnum++)
+		ubi_scan_vid_hdr(ubi, ubi->blockinfo + pnum, pnum);
+}
+
+/*
+ * Load a logical block of a volume into memory
+ */
+static int ubi_load_block(struct ubi_scan_info *ubi, uint8_t *laddr,
+			  struct ubi_vol_info *vi, u32 vol_id, u32 lnum,
+			  u32 last)
+{
+	struct ubi_vid_hdr *vh, *vrepl;
+	u32 pnum, crc, dlen;
+
+retry:
+	/*
+	 * If this is a fastmap run, we try to rescan full, otherwise
+	 * we simply give up.
+	 */
+	if (!test_bit(lnum, vi->found)) {
+		ubi_warn("LEB %d of %d is missing", lnum, last);
+		return -EINVAL;
+	}
+
+	pnum = vi->lebs_to_pebs[lnum];
+
+	ubi_dbg("Load vol %u LEB %u PEB %u", vol_id, lnum, pnum);
+
+	if (ubi_io_is_bad(ubi, pnum)) {
+		ubi_warn("Corrupted mapping block %d PB %d\n", lnum, pnum);
+		return -EINVAL;
+	}
+
+	if (test_bit(pnum, ubi->corrupt))
+		goto find_other;
+
+	/*
+	 * Lets try to read that block
+	 */
+	vh = ubi->blockinfo + pnum;
+
+	if (!test_bit(pnum, ubi->scanned)) {
+		ubi_warn("Vol: %u LEB %u PEB %u not yet scanned", vol_id,
+			 lnum, pnum);
+		if (ubi_rescan_fm_vid_hdr(ubi, vh, pnum, vol_id, lnum))
+			goto find_other;
+	}
+
+	/*
+	 * Check, if the total number of blocks is correct
+	 */
+	if (be32_to_cpu(vh->used_ebs) != last) {
+		ubi_dbg("Block count missmatch.");
+		ubi_dbg("vh->used_ebs: %d nrblocks: %d",
+			be32_to_cpu(vh->used_ebs), last);
+		generic_set_bit(pnum, ubi->corrupt);
+		goto find_other;
+	}
+
+	/*
+	 * Get the data length of this block.
+	 */
+	dlen = be32_to_cpu(vh->data_size);
+
+	/*
+	 * Read the data into RAM. We ignore the return value
+	 * here as the only thing which might go wrong are
+	 * bitflips. Try nevertheless.
+	 */
+	ubi_io_read(ubi, laddr, pnum, ubi->leb_start, dlen);
+
+	/* Calculate CRC over the data */
+	crc = crc32(UBI_CRC32_INIT, laddr, dlen);
+
+	if (crc != be32_to_cpu(vh->data_crc)) {
+		ubi_warn("Vol: %u LEB %u PEB %u data CRC failure", vol_id,
+			 lnum, pnum);
+		generic_set_bit(pnum, ubi->corrupt);
+		goto find_other;
+	}
+
+	/* We are good. Return the data length we read */
+	return dlen;
+
+find_other:
+	ubi_dbg("Find replacement for LEB %u PEB %u", lnum, pnum);
+	generic_clear_bit(lnum, vi->found);
+	vrepl = NULL;
+
+	for (pnum = 0; pnum < ubi->peb_count; pnum++) {
+		struct ubi_vid_hdr *tmp = ubi->blockinfo + pnum;
+		u32 t_vol_id = be32_to_cpu(tmp->vol_id);
+		u32 t_lnum = be32_to_cpu(tmp->lnum);
+
+		if (test_bit(pnum, ubi->corrupt))
+			continue;
+
+		if (t_vol_id != vol_id || t_lnum != lnum)
+			continue;
+
+		if (!test_bit(pnum, ubi->scanned)) {
+			ubi_warn("Vol: %u LEB %u PEB %u not yet scanned",
+				 vol_id, lnum, pnum);
+			if (ubi_rescan_fm_vid_hdr(ubi, tmp, pnum, vol_id, lnum))
+				continue;
+		}
+
+		/*
+		 * We found one. If its the first, assign it otherwise
+		 * compare the sqnum
+		 */
+		generic_set_bit(lnum, vi->found);
+
+		if (!vrepl) {
+			vrepl = tmp;
+			continue;
+		}
+
+		if (be64_to_cpu(vrepl->sqnum) < be64_to_cpu(tmp->sqnum))
+			vrepl = tmp;
+	}
+
+	if (vrepl) {
+		/* Update the vi table */
+		pnum = vrepl - ubi->blockinfo;
+		vi->lebs_to_pebs[lnum] = pnum;
+		ubi_dbg("Trying PEB %u for LEB %u", pnum, lnum);
+		vh = vrepl;
+	}
+	goto retry;
+}
+
+/*
+ * Load a volume into RAM
+ */
+static int ipl_load(struct ubi_scan_info *ubi, const u32 vol_id, uint8_t *laddr)
+{
+	struct ubi_vol_info *vi;
+	u32 lnum, last, len;
+
+	if (vol_id >= UBI_SPL_VOL_IDS)
+		return -EINVAL;
+
+	len = 0;
+	vi = ubi->volinfo + vol_id;
+	last = vi->last_block + 1;
+
+	/* Read the blocks to RAM, check CRC */
+	for (lnum = 0 ; lnum < last; lnum++) {
+		int res = ubi_load_block(ubi, laddr, vi, vol_id, lnum, last);
+
+		if (res < 0) {
+			ubi_warn("Failed to load volume %u", vol_id);
+			return res;
+		}
+		/* res is the data length of the read block */
+		laddr += res;
+		len += res;
+	}
+	return len;
+}
+
+int ubispl_load_volumes(struct ubispl_info *info, struct ubispl_load *lvols,
+			int nrvols)
+{
+	struct ubi_scan_info *ubi = info->ubi;
+	int res, i, fastmap = info->fastmap;
+	u32 fsize;
+
+retry:
+	/*
+	 * We do a partial initializiation of @ubi. Cleaning fm_buf is
+	 * not necessary.
+	 */
+	memset(ubi, 0, offsetof(struct ubi_scan_info, fm_buf));
+
+	ubi->read = info->read;
+
+	/* Precalculate the offsets */
+	ubi->vid_offset = info->vid_offset;
+	ubi->leb_start = info->leb_start;
+	ubi->leb_size = info->peb_size - ubi->leb_start;
+	ubi->peb_count = info->peb_count;
+	ubi->peb_offset = info->peb_offset;
+
+	fsize = info->peb_size * info->peb_count;
+	ubi->fsize_mb = fsize >> 20;
+
+	/* Fastmap init */
+	ubi->fm_size = ubi_calc_fm_size(ubi);
+	ubi->fm_enabled = fastmap;
+
+	for (i = 0; i < nrvols; i++) {
+		struct ubispl_load *lv = lvols + i;
+
+		generic_set_bit(lv->vol_id, ubi->toload);
+	}
+
+	ipl_scan(ubi);
+
+	for (i = 0; i < nrvols; i++) {
+		struct ubispl_load *lv = lvols + i;
+
+		ubi_msg("Loading VolId #%d", lv->vol_id);
+		res = ipl_load(ubi, lv->vol_id, lv->load_addr);
+		if (res < 0) {
+			if (fastmap) {
+				fastmap = 0;
+				goto retry;
+			}
+			ubi_warn("Failed");
+			return res;
+		}
+	}
+	return 0;
+}
diff --git a/drivers/mtd/ubispl/ubispl.h b/drivers/mtd/ubispl/ubispl.h
new file mode 100644
index 0000000..f1b60fe
--- /dev/null
+++ b/drivers/mtd/ubispl/ubispl.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _UBOOT_MTD_UBISPL_H
+#define _UBOOT_MTD_UBISPL_H
+
+#include "../ubi/ubi-media.h"
+#include "ubi-wrapper.h"
+
+/*
+ * The maximum number of volume ids we scan. So you can load volume id
+ * 0 to (CONFIG_SPL_UBI_VOL_ID_MAX - 1)
+ */
+#define UBI_SPL_VOL_IDS		CONFIG_SPL_UBI_VOL_IDS
+/*
+ * The size of the read buffer for the fastmap blocks. In theory up to
+ * UBI_FM_MAX_BLOCKS * CONFIG_SPL_MAX_PEB_SIZE. In practice today
+ * one or two blocks.
+ */
+#define UBI_FM_BUF_SIZE		(UBI_FM_MAX_BLOCKS*CONFIG_SPL_UBI_MAX_PEB_SIZE)
+/*
+ * The size of the bitmaps for the attach/ scan
+ */
+#define UBI_FM_BM_SIZE		((CONFIG_SPL_UBI_MAX_PEBS / BITS_PER_LONG) + 1)
+/*
+ * The maximum number of logical erase blocks per loadable volume
+ */
+#define UBI_MAX_VOL_LEBS	CONFIG_SPL_UBI_MAX_VOL_LEBS
+/*
+ * The bitmap size for the above to denote the found blocks inside the volume
+ */
+#define UBI_VOL_BM_SIZE		((UBI_MAX_VOL_LEBS / BITS_PER_LONG) + 1)
+
+/**
+ * struct ubi_vol_info - UBISPL internal volume represenation
+ * @last_block:		The last block (highest LEB) found for this volume
+ * @found:		Bitmap to mark found LEBS
+ * @lebs_to_pebs:	LEB to PEB translation table
+ */
+struct ubi_vol_info {
+	u32				last_block;
+	unsigned long			found[UBI_VOL_BM_SIZE];
+	u32				lebs_to_pebs[UBI_MAX_VOL_LEBS];
+};
+
+/**
+ * struct ubi_scan_info - UBISPL internal data for FM attach and full scan
+ *
+ * @read:		Read function to access the flash provided by the caller
+ * @peb_count:		Number of physical erase blocks in the UBI FLASH area
+ *			aka MTD partition.
+ * @peb_offset:		Offset of PEB0 in the UBI FLASH area (aka MTD partition)
+ *			to the real start of the FLASH in erase blocks.
+ * @fsize_mb:		Size of the scanned FLASH area in MB (stats only)
+ * @vid_offset:		Offset from the start of a PEB to the VID header
+ * @leb_start:		Offset from the start of a PEB to the data area
+ * @leb_size:		Size of the data area
+ *
+ * @fastmap_pebs:	Counter of PEBs "attached" by fastmap
+ * @fastmap_anchor:	The anchor PEB of the fastmap
+ * @fm_sb:		The fastmap super block data
+ * @fm_vh:		The fastmap VID header
+ * @fm:			Pointer to the fastmap layout
+ * @fm_layout:		The fastmap layout itself
+ * @fm_pool:		The pool of PEBs to scan at fastmap attach time
+ * @fm_wl_pool:		The pool of PEBs scheduled for wearleveling
+ *
+ * @fm_enabled:		Indicator whether fastmap attachment is enabled.
+ * @fm_used:		Bitmap to indicate the PEBS covered by fastmap
+ * @scanned:		Bitmap to indicate the PEBS of which the VID header
+ *			hase been physically scanned.
+ * @corrupt:		Bitmap to indicate corrupt blocks
+ * @toload:		Bitmap to indicate the volumes which should be loaded
+ *
+ * @blockinfo:		The vid headers of the scanned blocks
+ * @volinfo:		The volume information of the interesting (toload)
+ *			volumes
+ *
+ * @fm_buf:		The large fastmap attach buffer
+ */
+struct ubi_scan_info {
+	ubispl_read_flash		read;
+	unsigned int			fsize_mb;
+	unsigned int			peb_count;
+	unsigned int			peb_offset;
+
+	unsigned long			vid_offset;
+	unsigned long			leb_start;
+	unsigned long			leb_size;
+
+	/* Fastmap: The upstream required fields */
+	int				fastmap_pebs;
+	int				fastmap_anchor;
+	size_t				fm_size;
+	struct ubi_fm_sb		fm_sb;
+	struct ubi_vid_hdr		fm_vh;
+	struct ubi_fastmap_layout	*fm;
+	struct ubi_fastmap_layout	fm_layout;
+	struct ubi_fm_pool		fm_pool;
+	struct ubi_fm_pool		fm_wl_pool;
+
+	/* Fastmap: UBISPL specific data */
+	int				fm_enabled;
+	unsigned long			fm_used[UBI_FM_BM_SIZE];
+	unsigned long			scanned[UBI_FM_BM_SIZE];
+	unsigned long			corrupt[UBI_FM_BM_SIZE];
+	unsigned long			toload[UBI_FM_BM_SIZE];
+
+	/* Data for storing the VID and volume information */
+	struct ubi_vol_info		volinfo[UBI_SPL_VOL_IDS];
+	struct ubi_vid_hdr		blockinfo[CONFIG_SPL_UBI_MAX_PEBS];
+
+	/* The large buffer for the fastmap */
+	uint8_t				fm_buf[UBI_FM_BUF_SIZE];
+};
+
+#ifdef CFG_DEBUG
+#define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__)
+#else
+#define ubi_dbg(fmt, ...)
+#endif
+
+#ifdef CONFIG_UBI_SILENCE_MSG
+#define ubi_msg(fmt, ...)
+#else
+#define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
+#endif
+/* UBI warning messages */
+#define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__)
+/* UBI error messages */
+#define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__)
+
+#endif
diff --git a/include/ubispl.h b/include/ubispl.h
new file mode 100644
index 0000000..0c4bafe
--- /dev/null
+++ b/include/ubispl.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#ifndef __UBOOT_UBISPL_H
+#define __UBOOT_UBISPL_H
+
+/*
+ * The following CONFIG options are relevant for UBISPL
+ *
+ * #define CONFIG_SPL_UBI_MAX_VOL_LEBS		256
+ *
+ * Defines the maximum number of logical erase blocks per loadable
+ * (static) volume to size the ubispl internal arrays.
+ *
+ * #define CONFIG_SPL_UBI_MAX_PEB_SIZE		(256*1024)
+ *
+ * Defines the maximum physical erase block size to size the fastmap
+ * buffer for ubispl.
+ *
+ * #define CONFIG_SPL_UBI_MAX_PEBS		4096
+ *
+ * Define the maximum number of physical erase blocks to size the
+ * ubispl internal arrays.
+ *
+ * #define CONFIG_SPL_UBI_VOL_IDS		8
+ *
+ * Defines the maximum number of volumes in which UBISPL is
+ * interested. Limits the amount of memory for the scan data and
+ * speeds up the scan process as we simply ignore stuff which we dont
+ * want to load from the SPL anyway. So the volumes which can be
+ * loaded in the above example are ids 0 - 7
+ */
+
+/*
+ * The struct definition is in drivers/mtd/ubispl/ubispl.h. It does
+ * not fit into the BSS due to the large buffer requirement of the
+ * upstream fastmap code. So the caller of ubispl_load_volumes needs
+ * to hand in a pointer to a free memory area where ubispl will place
+ * its data. The area is not required to be initialized.
+ */
+struct ubi_scan_info;
+
+typedef int (*ubispl_read_flash)(int pnum, int offset, int len, void *dst);
+
+/**
+ * struct ubispl_info - description structure for fast ubi scan
+ * @ubi:		Pointer to memory space for ubi scan info structure
+ * @peb_size:		Physical erase block size
+ * @vid_offset:		Offset of the VID header
+ * @leb_start:		Start of the logical erase block, i.e. offset of data
+ * @peb_count:		Number of physical erase blocks in the UBI FLASH area
+ *			aka MTD partition.
+ * @peb_offset:		Offset of PEB0 in the UBI FLASH area (aka MTD partition)
+ *			to the real start of the FLASH in erase blocks.
+ * @fastmap:		Enable fastmap attachment
+ * @read:		Read function to access the flash
+ */
+struct ubispl_info {
+	struct ubi_scan_info	*ubi;
+	u32			peb_size;
+	u32			vid_offset;
+	u32			leb_start;
+	u32			peb_count;
+	u32			peb_offset;
+	int			fastmap;
+	ubispl_read_flash	read;
+};
+
+/**
+ * struct ubispl_load - structure to describe a volume to load
+ * @vol_id:	Volume id
+ * @load_addr:	Load address of the volume
+ */
+struct ubispl_load {
+	int		vol_id;
+	void		*load_addr;
+};
+
+/**
+ * ubispl_load_volumes - Scan flash and load volumes
+ * @info:	Pointer to the ubi scan info structure
+ * @lovls:	Pointer to array of volumes to load
+ * @nrvols:	Array size of @lovls
+ */
+int ubispl_load_volumes(struct ubispl_info *info,
+			struct ubispl_load *lvols, int nrvols);
+
+#endif
-- 
2.1.4

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

* [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
                   ` (2 preceding siblings ...)
  2016-01-17  3:13 ` [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
@ 2016-01-17  3:13 ` Ladislav Michl
  2016-01-21  6:06   ` Heiko Schocher
  2016-01-17  3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:13 UTC (permalink / raw)
  To: u-boot

Add support for loading from UBI volumes on the top of NAND.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 common/spl/Makefile  |  3 +++
 common/spl/spl.c     |  4 ++++
 common/spl/spl_ubi.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spl.h        |  4 ++++
 4 files changed, 79 insertions(+)
 create mode 100644 common/spl/spl_ubi.c

diff --git a/common/spl/Makefile b/common/spl/Makefile
index 10a4589..36e5338 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -12,8 +12,11 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
 obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += spl_ymodem.o
+ifndef CONFIG_SPL_UBI
 obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
+endif
 obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
+obj-$(CONFIG_SPL_UBI) += spl_ubi.o
 obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
 obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o
 obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o
diff --git a/common/spl/spl.c b/common/spl/spl.c
index e5167bf..b945a48 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -288,8 +288,12 @@ static int spl_load_image(u32 boot_device)
 #endif
 #ifdef CONFIG_SPL_NAND_SUPPORT
 	case BOOT_DEVICE_NAND:
+#ifdef CONFIG_SPL_UBI
+		return spl_ubi_load_image(boot_device);
+#else
 		return spl_nand_load_image();
 #endif
+#endif
 #ifdef CONFIG_SPL_ONENAND_SUPPORT
 	case BOOT_DEVICE_ONENAND:
 		return spl_onenand_load_image();
diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c
new file mode 100644
index 0000000..dd8ce36
--- /dev/null
+++ b/common/spl/spl_ubi.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016
+ * Ladislav Michl <ladis@linux-mips.org>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <nand.h>
+#include <ubispl.h>
+#include <spl.h>
+
+int spl_ubi_load_image(u32 boot_device)
+{
+	int ret;
+	struct image_header *header;
+	struct ubispl_info info;
+	struct ubispl_load volumes[2];
+
+#ifdef CONFIG_SPL_NAND_SUPPORT
+	if (boot_device == BOOT_DEVICE_NAND)
+		nand_init();
+#endif
+	info.ubi = (struct ubi_scan_info *) CONFIG_SPL_UBI_INFO_ADDR;
+	info.fastmap = 1;
+	info.read = nand_spl_read_block;
+
+	info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
+	info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
+	info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
+	info.leb_start = CONFIG_SPL_UBI_LEB_START;
+	info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
+
+#ifdef CONFIG_SPL_OS_BOOT
+	if (!spl_start_uboot()) {
+		volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
+		volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
+		volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
+		volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
+
+		ret = ubispl_load_volumes(&info, volumes, 2);
+		if (!ret) {
+			header = (struct image_header *) volumes[0].load_addr;
+			spl_parse_image_header(header);
+			puts("Linux loaded.\n");
+			goto out;
+		}
+		puts("Loading Linux failed, falling back to U-Boot.\n");
+	}
+#endif
+	header = (struct image_header *)
+		(CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
+	volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
+	volumes[0].load_addr = (void *)header;
+
+	ret = ubispl_load_volumes(&info, volumes, 1);
+	if (!ret)
+		spl_parse_image_header(header);
+#ifdef CONFIG_SPL_OS_BOOT
+out:
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+	if (boot_device == BOOT_DEVICE_NAND)
+		nand_deselect();
+#endif
+	return ret;
+}
diff --git a/include/spl.h b/include/spl.h
index 92cdc04..1ab9295 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -40,6 +40,7 @@ u32 spl_boot_mode(void);
 void spl_set_header_raw_uboot(void);
 void spl_parse_image_header(const struct image_header *header);
 void spl_board_prepare_for_linux(void);
+int spl_board_ubi_load_image(u32 boot_device);
 void __noreturn jump_to_image_linux(void *arg);
 int spl_start_uboot(void);
 void spl_display_print(void);
@@ -53,6 +54,9 @@ int spl_onenand_load_image(void);
 /* NOR SPL functions */
 int spl_nor_load_image(void);
 
+/* UBI SPL functions */
+int spl_ubi_load_image(u32 boot_device);
+
 /* MMC SPL functions */
 int spl_mmc_load_image(u32 boot_device);
 
-- 
2.1.4

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

* [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
                   ` (3 preceding siblings ...)
  2016-01-17  3:13 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Ladislav Michl
@ 2016-01-17  3:15 ` Ladislav Michl
  2016-01-21  6:07   ` Heiko Schocher
  2016-01-17  3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
  2016-01-17  3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:15 UTC (permalink / raw)
  To: u-boot

Other payload than uImage is currently considered to be raw U-Boot
image. Check also for zImage in Falcon mode.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 arch/arm/lib/Makefile |  2 ++
 arch/arm/lib/bootm.c  | 32 --------------------------------
 arch/arm/lib/zimage.c | 40 ++++++++++++++++++++++++++++++++++++++++
 common/spl/spl.c      | 23 +++++++++++++++++++++++
 4 files changed, 65 insertions(+), 32 deletions(-)
 create mode 100644 arch/arm/lib/zimage.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index f3db7b5..07a9019 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -26,11 +26,13 @@ endif
 obj-$(CONFIG_CPU_V7M) += cmd_boot.o
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_CMD_BOOTM) += zimage.o
 obj-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
 obj-$(CONFIG_USE_ARCH_MEMSET) += memset.o
 obj-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
 else
 obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
+obj-$(CONFIG_SPL_FRAMEWORK) += zimage.o
 endif
 obj-$(CONFIG_SEMIHOSTING) += semihosting.o
 
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index a477cae..fbfc0ad 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -348,38 +348,6 @@ int do_bootm_linux(int flag, int argc, char * const argv[],
 	return 0;
 }
 
-#ifdef CONFIG_CMD_BOOTZ
-
-struct zimage_header {
-	uint32_t	code[9];
-	uint32_t	zi_magic;
-	uint32_t	zi_start;
-	uint32_t	zi_end;
-};
-
-#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
-
-int bootz_setup(ulong image, ulong *start, ulong *end)
-{
-	struct zimage_header *zi;
-
-	zi = (struct zimage_header *)map_sysmem(image, 0);
-	if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC) {
-		puts("Bad Linux ARM zImage magic!\n");
-		return 1;
-	}
-
-	*start = zi->zi_start;
-	*end = zi->zi_end;
-
-	printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", image, *start,
-	      *end);
-
-	return 0;
-}
-
-#endif	/* CONFIG_CMD_BOOTZ */
-
 #if defined(CONFIG_BOOTM_VXWORKS)
 void boot_prep_vxworks(bootm_headers_t *images)
 {
diff --git a/arch/arm/lib/zimage.c b/arch/arm/lib/zimage.c
new file mode 100644
index 0000000..f870d72
--- /dev/null
+++ b/arch/arm/lib/zimage.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016
+ * Ladislav Michl <ladis@linux-mips.org>
+ *
+ * bootz code:
+ * Copyright (C) 2012 Marek Vasut <marek.vasut@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#include <common.h>
+
+#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
+
+struct arm_z_header {
+	uint32_t	code[9];
+	uint32_t	zi_magic;
+	uint32_t	zi_start;
+	uint32_t	zi_end;
+} __attribute__ ((__packed__));
+
+int bootz_setup(ulong image, ulong *start, ulong *end)
+{
+	struct arm_z_header *zi = (struct arm_z_header *) image;
+
+	if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC) {
+#ifndef CONFIG_SPL_FRAMEWORK
+		puts("Bad Linux ARM zImage magic!\n");
+#endif
+		return 1;
+	}
+
+	*start = zi->zi_start;
+	*end = zi->zi_end;
+#ifndef CONFIG_SPL_FRAMEWORK
+	printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", image, *start,
+	      *end);
+#endif
+
+	return 0;
+}
diff --git a/common/spl/spl.c b/common/spl/spl.c
index b945a48..7fd8e5d 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -52,6 +52,15 @@ __weak int spl_start_uboot(void)
 	puts("SPL: Direct Linux boot not active!\n");
 	return 1;
 }
+
+/*
+ * Weak default function for arch specific zImage check. Return zero
+ * and fill start and end address if image is recognized.
+ */
+int __weak bootz_setup(ulong image, ulong *start, ulong *end)
+{
+	 return 1;
+}
 #endif
 
 /*
@@ -112,6 +121,20 @@ void spl_parse_image_header(const struct image_header *header)
 		 */
 		panic("** no mkimage signature but raw image not supported");
 #else
+#ifdef CONFIG_SPL_OS_BOOT
+		ulong start, end;
+
+		if (!bootz_setup((ulong)header, &start, &end)) {
+			spl_image.name = "Linux";
+			spl_image.os = IH_OS_LINUX;
+			spl_image.load_addr = CONFIG_SYS_LOAD_ADDR;
+			spl_image.entry_point = CONFIG_SYS_LOAD_ADDR;
+			spl_image.size = end - start;
+			debug("spl: payload zImage, load addr: 0x%x size: %d\n",
+				spl_image.load_addr, spl_image.size);
+			return;
+		}
+#endif
 		/* Signature not found - assume u-boot.bin */
 		debug("mkimage signature not found - ih_magic = %x\n",
 			header->ih_magic);
-- 
2.1.4

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
                   ` (4 preceding siblings ...)
  2016-01-17  3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
@ 2016-01-17  3:16 ` Ladislav Michl
  2016-01-21  6:07   ` Heiko Schocher
  2016-01-17  3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:16 UTC (permalink / raw)
  To: u-boot

Convert IGEP board to use UBI volumes for U-Boot, its environment and
kernel. With exception of first four sectors read by SoC boot
ROM whole NAND is UBI managed. As code is too big now, drop
CONFIG_SPL_EXT_SUPPORT to make it fit.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 include/configs/omap3_igep00x0.h | 80 ++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 35 deletions(-)

diff --git a/include/configs/omap3_igep00x0.h b/include/configs/omap3_igep00x0.h
index 5da6cfd..9afbcbe 100644
--- a/include/configs/omap3_igep00x0.h
+++ b/include/configs/omap3_igep00x0.h
@@ -74,6 +74,8 @@
 #define CONFIG_CMD_CACHE
 #ifdef CONFIG_BOOT_ONENAND
 #define CONFIG_CMD_ONENAND	/* ONENAND support		*/
+#else
+#define CONFIG_CMD_UBI
 #endif
 #define CONFIG_CMD_DHCP
 #define CONFIG_CMD_PING
@@ -86,6 +88,10 @@
 	"stdout=serial\0" \
 	"stderr=serial\0"
 
+#define ENV_MTD_SETTINGS \
+	"mtdids=nand0=gpmc-nand.0\0" \
+	"mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
+
 #define MEM_LAYOUT_SETTINGS \
 	DEFAULT_LINUX_BOOT_ENV \
 	"scriptaddr=0x87E00000\0" \
@@ -96,36 +102,15 @@
 
 #include <config_distro_bootcmd.h>
 
-
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	ENV_DEVICE_SETTINGS \
+	ENV_MTD_SETTINGS \
 	MEM_LAYOUT_SETTINGS \
 	BOOTENV
 
 #endif
 
 /*
- * FLASH and environment organization
- */
-
-#ifdef CONFIG_BOOT_ONENAND
-#define CONFIG_SYS_ONENAND_BASE		ONENAND_MAP
-
-#define ONENAND_ENV_OFFSET		0x260000 /* environment starts here */
-
-#define CONFIG_ENV_IS_IN_ONENAND	1
-#define CONFIG_ENV_SIZE			(512 << 10) /* Total Size Environment */
-#define CONFIG_ENV_ADDR			ONENAND_ENV_OFFSET
-#endif
-
-#ifdef CONFIG_NAND
-#define CONFIG_ENV_OFFSET		0x260000 /* environment starts here */
-#define CONFIG_ENV_IS_IN_NAND	        1
-#define CONFIG_ENV_SIZE			(512 << 10) /* Total Size Environment */
-#define CONFIG_ENV_ADDR			NAND_ENV_OFFSET
-#endif
-
-/*
  * SMSC911x Ethernet
  */
 #if defined(CONFIG_CMD_NET)
@@ -134,19 +119,50 @@
 #define CONFIG_SMC911X_BASE		0x2C000000
 #endif /* (CONFIG_CMD_NET) */
 
+/*
+ * FLASH and environment organization
+ */
+#ifdef CONFIG_NAND
+#define CONFIG_SPL_UBI			1
+#define CONFIG_SPL_UBI_MAX_VOL_LEBS	256
+#define CONFIG_SPL_UBI_MAX_PEB_SIZE	(256*1024)
+#define CONFIG_SPL_UBI_MAX_PEBS		4096
+#define CONFIG_SPL_UBI_VOL_IDS		8
+#define CONFIG_SPL_UBI_LOAD_MONITOR_ID	0
+#define CONFIG_SPL_UBI_LOAD_KERNEL_ID	3
+#define CONFIG_SPL_UBI_LOAD_ARGS_ID	4
+#define CONFIG_SPL_UBI_PEB_OFFSET	4
+#define CONFIG_SPL_UBI_VID_OFFSET	512
+#define CONFIG_SPL_UBI_LEB_START	2048
+#define CONFIG_SPL_UBI_INFO_ADDR	0x88080000
+
+#define CONFIG_ENV_IS_IN_UBI		1
+#define CONFIG_ENV_UBI_PART		"UBI"
+#define CONFIG_ENV_UBI_VOLUME		"config"
+#define CONFIG_ENV_UBI_VOLUME_REDUND	"config_r"
+#define CONFIG_UBI_SILENCE_MSG		1
+#define CONFIG_UBIFS_SILENCE_MSG	1
+#else
+#define CONFIG_ENV_IS_NOWHERE
+#endif
+#define CONFIG_ENV_SIZE			(32*1024)
+
+#define CONFIG_RBTREE
+#define CONFIG_MTD_PARTITIONS
+#define MTDIDS_DEFAULT			"nand0=gpmc-nand.0"
+#define MTDPARTS_DEFAULT		"mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
+
 /* OneNAND boot config */
 #ifdef CONFIG_BOOT_ONENAND
 #define CONFIG_SPL_ONENAND_SUPPORT
-#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
 #define CONFIG_SYS_ONENAND_PAGE_SIZE	2048
-#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
-#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
-	(512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
-
+#define CONFIG_SYS_ONENAND_BASE		ONENAND_MAP
+#define CONFIG_SYS_ONENAND_U_BOOT_OFFS	0x80000
 #endif
 
 /* NAND boot config */
 #ifdef CONFIG_NAND
+#define CONFIG_SPL_NAND_SUPPORT
 #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
 #define CONFIG_SYS_NAND_5_ADDR_CYCLE
 #define CONFIG_SYS_NAND_PAGE_COUNT	64
@@ -166,14 +182,8 @@
 #define CONFIG_NAND_OMAP_ECCSCHEME	OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
 #define CONFIG_NAND_OMAP_GPMC
 #define CONFIG_BCH
-
-#define CONFIG_SYS_NAND_U_BOOT_OFFS	0x80000
-/* NAND: SPL falcon mode configs */
-#ifdef CONFIG_SPL_OS_BOOT
-#define CONFIG_CMD_SPL_NAND_OFS		0x240000
-#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS	0x280000
-#define CONFIG_CMD_SPL_WRITE_SIZE	0x2000
-#endif
 #endif
 
+#undef CONFIG_SPL_EXT_SUPPORT
+
 #endif /* __IGEP00X0_H */
-- 
2.1.4

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

* [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode
  2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
                   ` (5 preceding siblings ...)
  2016-01-17  3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
@ 2016-01-17  3:16 ` Ladislav Michl
  2016-01-21  6:08   ` Heiko Schocher
  6 siblings, 1 reply; 28+ messages in thread
From: Ladislav Michl @ 2016-01-17  3:16 UTC (permalink / raw)
  To: u-boot

Implement spl_start_uboot to let Falcon mode work.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 board/isee/igep00x0/igep00x0.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
index e2fce50..92811d8 100644
--- a/board/isee/igep00x0/igep00x0.c
+++ b/board/isee/igep00x0/igep00x0.c
@@ -10,6 +10,7 @@
 #include <ns16550.h>
 #include <twl4030.h>
 #include <netdev.h>
+#include <spl.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/arch/mem.h>
@@ -212,3 +213,14 @@ int board_eth_init(bd_t *bis)
 #endif
 }
 #endif
+
+#ifdef CONFIG_SPL_OS_BOOT
+int spl_start_uboot(void)
+{
+	/* break into full u-boot on 'c' */
+	if (serial_tstc() && serial_getc() == 'c')
+		return 1;
+
+	return 0;
+}
+#endif
-- 
2.1.4

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

* [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile
  2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
@ 2016-01-21  6:04   ` Heiko Schocher
  0 siblings, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:04 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:11 schrieb Ladislav Michl:
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
>   drivers/Makefile | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/drivers/Makefile b/drivers/Makefile
> index 00da40b..1b9f8d6 100644
> --- a/drivers/Makefile
> +++ b/drivers/Makefile
> @@ -18,14 +18,14 @@ obj-$(CONFIG_ARMADA_38X) += ddr/marvell/a38x/
>   obj-$(CONFIG_ARMADA_XP) += ddr/marvell/axp/
>   obj-$(CONFIG_ALTERA_SDRAM) += ddr/altera/
>   obj-$(CONFIG_SPL_SERIAL_SUPPORT) += serial/
> -obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
>   obj-$(CONFIG_SPL_SPI_SUPPORT) += spi/
>   obj-$(CONFIG_SPL_POWER_SUPPORT) += power/ power/pmic/
>   obj-$(CONFIG_SPL_POWER_SUPPORT) += power/regulator/
> +obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
>   obj-$(CONFIG_SPL_MTD_SUPPORT) += mtd/
>   obj-$(CONFIG_SPL_NAND_SUPPORT) += mtd/nand/
> -obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
>   obj-$(CONFIG_SPL_ONENAND_SUPPORT) += mtd/onenand/
> +obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
>   obj-$(CONFIG_SPL_DMA_SUPPORT) += dma/
>   obj-$(CONFIG_SPL_ETH_SUPPORT) += net/
>   obj-$(CONFIG_SPL_ETH_SUPPORT) += net/phy/
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function
  2016-01-17  3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
@ 2016-01-21  6:05   ` Heiko Schocher
  0 siblings, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:05 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:12 schrieb Ladislav Michl:
> From: Thomas Gleixner <tglx@linutronix.de>
>
> To support UBI in SPL we need a simple NAND read function. Add one to
> nand_spl_simple and keep it as simple as it goes.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> Acked-by: Scott Wood <oss@buserror.net>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
> Changes in v3:
> - Rename nand_spl_read_flash to nand_spl_read_block and optimize it.
>
>   drivers/mtd/nand/nand_spl_simple.c | 62 ++++++++++++++++++++++++++++++++++++++
>   include/nand.h                     |  1 +
>   2 files changed, 63 insertions(+)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/drivers/mtd/nand/nand_spl_simple.c b/drivers/mtd/nand/nand_spl_simple.c
> index e69f662..cf80903 100644
> --- a/drivers/mtd/nand/nand_spl_simple.c
> +++ b/drivers/mtd/nand/nand_spl_simple.c
> @@ -209,6 +209,68 @@ static int nand_read_page(int block, int page, void *dst)
>   }
>   #endif
>
> +#ifdef CONFIG_SPL_UBI
> +/*
> + * Temporary storage for non NAND page aligned and non NAND page sized
> + * reads. Note: This does not support runtime detected FLASH yet, but
> + * that should be reasonably easy to fix by making the buffer large
> + * enough :)
> + */
> +static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
> +
> +/**
> + * nand_spl_read_block - Read data from physical eraseblock into a buffer
> + * @block:	Number of the physical eraseblock
> + * @offset:	Data offset from the start of @peb
> + * @len:	Data size to read
> + * @dst:	Address of the destination buffer
> + *
> + * This could be further optimized if we'd have a subpage read
> + * function in the simple code. On NAND which allows subpage reads
> + * this would spare quite some time to readout e.g. the VID header of
> + * UBI.
> + *
> + * Notes:
> + *	@offset + @len are not allowed to be larger than a physical
> + *	erase block. No sanity check done for simplicity reasons.
> + *
> + * To support runtime detected flash this needs to be extended by
> + * information about the actual flash geometry, but thats beyond the
> + * scope of this effort and for most applications where fast boot is
> + * required it is not an issue anyway.
> + */
> +int nand_spl_read_block(int block, int offset, int len, void *dst)
> +{
> +	int page, read;
> +
> +	/* Calculate the page number */
> +	page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
> +
> +	/* Offset to the start of a flash page */
> +	offset = offset % CONFIG_SYS_NAND_PAGE_SIZE;
> +
> +	while (len) {
> +		/*
> +		 * Non page aligned reads go to the scratch buffer.
> +		 * Page aligned reads go directly to the destination.
> +		 */
> +		if (offset || len < CONFIG_SYS_NAND_PAGE_SIZE) {
> +			nand_read_page(block, page, scratch_buf);
> +			read = min(len, CONFIG_SYS_NAND_PAGE_SIZE - offset);
> +			memcpy(dst, scratch_buf + offset, read);
> +			offset = 0;
> +		} else {
> +			nand_read_page(block, page, dst);
> +			read = CONFIG_SYS_NAND_PAGE_SIZE;
> +		}
> +		page++;
> +		len -= read;
> +		dst += read;
> +	}
> +	return 0;
> +}
> +#endif
> +
>   int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
>   {
>   	unsigned int block, lastblock;
> diff --git a/include/nand.h b/include/nand.h
> index d2a53ab..2f9a1ec 100644
> --- a/include/nand.h
> +++ b/include/nand.h
> @@ -124,6 +124,7 @@ int nand_unlock(nand_info_t *meminfo, loff_t start, size_t length,
>   int nand_get_lock_status(nand_info_t *meminfo, loff_t offset);
>
>   int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
> +int nand_spl_read_block(int block, int offset, int len, void *dst);
>   void nand_deselect(void);
>
>   #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes
  2016-01-17  3:13 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Ladislav Michl
@ 2016-01-21  6:06   ` Heiko Schocher
  0 siblings, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:06 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:13 schrieb Ladislav Michl:
> Add support for loading from UBI volumes on the top of NAND.
>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> ---
>   common/spl/Makefile  |  3 +++
>   common/spl/spl.c     |  4 ++++
>   common/spl/spl_ubi.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   include/spl.h        |  4 ++++
>   4 files changed, 79 insertions(+)
>   create mode 100644 common/spl/spl_ubi.c

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/common/spl/Makefile b/common/spl/Makefile
> index 10a4589..36e5338 100644
> --- a/common/spl/Makefile
> +++ b/common/spl/Makefile
> @@ -12,8 +12,11 @@ ifdef CONFIG_SPL_BUILD
>   obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
>   obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_nor.o
>   obj-$(CONFIG_SPL_YMODEM_SUPPORT) += spl_ymodem.o
> +ifndef CONFIG_SPL_UBI
>   obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
> +endif
>   obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
> +obj-$(CONFIG_SPL_UBI) += spl_ubi.o
>   obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
>   obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o
>   obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index e5167bf..b945a48 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -288,8 +288,12 @@ static int spl_load_image(u32 boot_device)
>   #endif
>   #ifdef CONFIG_SPL_NAND_SUPPORT
>   	case BOOT_DEVICE_NAND:
> +#ifdef CONFIG_SPL_UBI
> +		return spl_ubi_load_image(boot_device);
> +#else
>   		return spl_nand_load_image();
>   #endif
> +#endif
>   #ifdef CONFIG_SPL_ONENAND_SUPPORT
>   	case BOOT_DEVICE_ONENAND:
>   		return spl_onenand_load_image();
> diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c
> new file mode 100644
> index 0000000..dd8ce36
> --- /dev/null
> +++ b/common/spl/spl_ubi.c
> @@ -0,0 +1,68 @@
> +/*
> + * Copyright (C) 2016
> + * Ladislav Michl <ladis@linux-mips.org>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <config.h>
> +#include <nand.h>
> +#include <ubispl.h>
> +#include <spl.h>
> +
> +int spl_ubi_load_image(u32 boot_device)
> +{
> +	int ret;
> +	struct image_header *header;
> +	struct ubispl_info info;
> +	struct ubispl_load volumes[2];
> +
> +#ifdef CONFIG_SPL_NAND_SUPPORT
> +	if (boot_device == BOOT_DEVICE_NAND)
> +		nand_init();
> +#endif
> +	info.ubi = (struct ubi_scan_info *) CONFIG_SPL_UBI_INFO_ADDR;
> +	info.fastmap = 1;
> +	info.read = nand_spl_read_block;
> +
> +	info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
> +	info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
> +	info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
> +	info.leb_start = CONFIG_SPL_UBI_LEB_START;
> +	info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
> +
> +#ifdef CONFIG_SPL_OS_BOOT
> +	if (!spl_start_uboot()) {
> +		volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
> +		volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
> +		volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
> +		volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
> +
> +		ret = ubispl_load_volumes(&info, volumes, 2);
> +		if (!ret) {
> +			header = (struct image_header *) volumes[0].load_addr;
> +			spl_parse_image_header(header);
> +			puts("Linux loaded.\n");
> +			goto out;
> +		}
> +		puts("Loading Linux failed, falling back to U-Boot.\n");
> +	}
> +#endif
> +	header = (struct image_header *)
> +		(CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
> +	volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
> +	volumes[0].load_addr = (void *)header;
> +
> +	ret = ubispl_load_volumes(&info, volumes, 1);
> +	if (!ret)
> +		spl_parse_image_header(header);
> +#ifdef CONFIG_SPL_OS_BOOT
> +out:
> +#endif
> +#ifdef CONFIG_SPL_NAND_SUPPORT
> +	if (boot_device == BOOT_DEVICE_NAND)
> +		nand_deselect();
> +#endif
> +	return ret;
> +}
> diff --git a/include/spl.h b/include/spl.h
> index 92cdc04..1ab9295 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -40,6 +40,7 @@ u32 spl_boot_mode(void);
>   void spl_set_header_raw_uboot(void);
>   void spl_parse_image_header(const struct image_header *header);
>   void spl_board_prepare_for_linux(void);
> +int spl_board_ubi_load_image(u32 boot_device);
>   void __noreturn jump_to_image_linux(void *arg);
>   int spl_start_uboot(void);
>   void spl_display_print(void);
> @@ -53,6 +54,9 @@ int spl_onenand_load_image(void);
>   /* NOR SPL functions */
>   int spl_nor_load_image(void);
>
> +/* UBI SPL functions */
> +int spl_ubi_load_image(u32 boot_device);
> +
>   /* MMC SPL functions */
>   int spl_mmc_load_image(u32 boot_device);
>
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode
  2016-01-17  3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
@ 2016-01-21  6:07   ` Heiko Schocher
  0 siblings, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:07 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:15 schrieb Ladislav Michl:
> Other payload than uImage is currently considered to be raw U-Boot
> image. Check also for zImage in Falcon mode.
>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> ---
>   arch/arm/lib/Makefile |  2 ++
>   arch/arm/lib/bootm.c  | 32 --------------------------------
>   arch/arm/lib/zimage.c | 40 ++++++++++++++++++++++++++++++++++++++++
>   common/spl/spl.c      | 23 +++++++++++++++++++++++
>   4 files changed, 65 insertions(+), 32 deletions(-)
>   create mode 100644 arch/arm/lib/zimage.c

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
> index f3db7b5..07a9019 100644
> --- a/arch/arm/lib/Makefile
> +++ b/arch/arm/lib/Makefile
> @@ -26,11 +26,13 @@ endif
>   obj-$(CONFIG_CPU_V7M) += cmd_boot.o
>   obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
>   obj-$(CONFIG_CMD_BOOTM) += bootm.o
> +obj-$(CONFIG_CMD_BOOTM) += zimage.o
>   obj-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
>   obj-$(CONFIG_USE_ARCH_MEMSET) += memset.o
>   obj-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
>   else
>   obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
> +obj-$(CONFIG_SPL_FRAMEWORK) += zimage.o
>   endif
>   obj-$(CONFIG_SEMIHOSTING) += semihosting.o
>
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index a477cae..fbfc0ad 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -348,38 +348,6 @@ int do_bootm_linux(int flag, int argc, char * const argv[],
>   	return 0;
>   }
>
> -#ifdef CONFIG_CMD_BOOTZ
> -
> -struct zimage_header {
> -	uint32_t	code[9];
> -	uint32_t	zi_magic;
> -	uint32_t	zi_start;
> -	uint32_t	zi_end;
> -};
> -
> -#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
> -
> -int bootz_setup(ulong image, ulong *start, ulong *end)
> -{
> -	struct zimage_header *zi;
> -
> -	zi = (struct zimage_header *)map_sysmem(image, 0);
> -	if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC) {
> -		puts("Bad Linux ARM zImage magic!\n");
> -		return 1;
> -	}
> -
> -	*start = zi->zi_start;
> -	*end = zi->zi_end;
> -
> -	printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", image, *start,
> -	      *end);
> -
> -	return 0;
> -}
> -
> -#endif	/* CONFIG_CMD_BOOTZ */
> -
>   #if defined(CONFIG_BOOTM_VXWORKS)
>   void boot_prep_vxworks(bootm_headers_t *images)
>   {
> diff --git a/arch/arm/lib/zimage.c b/arch/arm/lib/zimage.c
> new file mode 100644
> index 0000000..f870d72
> --- /dev/null
> +++ b/arch/arm/lib/zimage.c
> @@ -0,0 +1,40 @@
> +/*
> + * Copyright (C) 2016
> + * Ladislav Michl <ladis@linux-mips.org>
> + *
> + * bootz code:
> + * Copyright (C) 2012 Marek Vasut <marek.vasut@gmail.com>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +#include <common.h>
> +
> +#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
> +
> +struct arm_z_header {
> +	uint32_t	code[9];
> +	uint32_t	zi_magic;
> +	uint32_t	zi_start;
> +	uint32_t	zi_end;
> +} __attribute__ ((__packed__));
> +
> +int bootz_setup(ulong image, ulong *start, ulong *end)
> +{
> +	struct arm_z_header *zi = (struct arm_z_header *) image;
> +
> +	if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC) {
> +#ifndef CONFIG_SPL_FRAMEWORK
> +		puts("Bad Linux ARM zImage magic!\n");
> +#endif
> +		return 1;
> +	}
> +
> +	*start = zi->zi_start;
> +	*end = zi->zi_end;
> +#ifndef CONFIG_SPL_FRAMEWORK
> +	printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", image, *start,
> +	      *end);
> +#endif
> +
> +	return 0;
> +}
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index b945a48..7fd8e5d 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -52,6 +52,15 @@ __weak int spl_start_uboot(void)
>   	puts("SPL: Direct Linux boot not active!\n");
>   	return 1;
>   }
> +
> +/*
> + * Weak default function for arch specific zImage check. Return zero
> + * and fill start and end address if image is recognized.
> + */
> +int __weak bootz_setup(ulong image, ulong *start, ulong *end)
> +{
> +	 return 1;
> +}
>   #endif
>
>   /*
> @@ -112,6 +121,20 @@ void spl_parse_image_header(const struct image_header *header)
>   		 */
>   		panic("** no mkimage signature but raw image not supported");
>   #else
> +#ifdef CONFIG_SPL_OS_BOOT
> +		ulong start, end;
> +
> +		if (!bootz_setup((ulong)header, &start, &end)) {
> +			spl_image.name = "Linux";
> +			spl_image.os = IH_OS_LINUX;
> +			spl_image.load_addr = CONFIG_SYS_LOAD_ADDR;
> +			spl_image.entry_point = CONFIG_SYS_LOAD_ADDR;
> +			spl_image.size = end - start;
> +			debug("spl: payload zImage, load addr: 0x%x size: %d\n",
> +				spl_image.load_addr, spl_image.size);
> +			return;
> +		}
> +#endif
>   		/* Signature not found - assume u-boot.bin */
>   		debug("mkimage signature not found - ih_magic = %x\n",
>   			header->ih_magic);
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-17  3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
@ 2016-01-21  6:07   ` Heiko Schocher
  2016-01-22 22:35     ` Enric Balletbo Serra
  0 siblings, 1 reply; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:07 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
> Convert IGEP board to use UBI volumes for U-Boot, its environment and
> kernel. With exception of first four sectors read by SoC boot
> ROM whole NAND is UBI managed. As code is too big now, drop
> CONFIG_SPL_EXT_SUPPORT to make it fit.
>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> ---
>   include/configs/omap3_igep00x0.h | 80 ++++++++++++++++++++++------------------
>   1 file changed, 45 insertions(+), 35 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/include/configs/omap3_igep00x0.h b/include/configs/omap3_igep00x0.h
> index 5da6cfd..9afbcbe 100644
> --- a/include/configs/omap3_igep00x0.h
> +++ b/include/configs/omap3_igep00x0.h
> @@ -74,6 +74,8 @@
>   #define CONFIG_CMD_CACHE
>   #ifdef CONFIG_BOOT_ONENAND
>   #define CONFIG_CMD_ONENAND	/* ONENAND support		*/
> +#else
> +#define CONFIG_CMD_UBI
>   #endif
>   #define CONFIG_CMD_DHCP
>   #define CONFIG_CMD_PING
> @@ -86,6 +88,10 @@
>   	"stdout=serial\0" \
>   	"stderr=serial\0"
>
> +#define ENV_MTD_SETTINGS \
> +	"mtdids=nand0=gpmc-nand.0\0" \
> +	"mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
> +
>   #define MEM_LAYOUT_SETTINGS \
>   	DEFAULT_LINUX_BOOT_ENV \
>   	"scriptaddr=0x87E00000\0" \
> @@ -96,36 +102,15 @@
>
>   #include <config_distro_bootcmd.h>
>
> -
>   #define CONFIG_EXTRA_ENV_SETTINGS \
>   	ENV_DEVICE_SETTINGS \
> +	ENV_MTD_SETTINGS \
>   	MEM_LAYOUT_SETTINGS \
>   	BOOTENV
>
>   #endif
>
>   /*
> - * FLASH and environment organization
> - */
> -
> -#ifdef CONFIG_BOOT_ONENAND
> -#define CONFIG_SYS_ONENAND_BASE		ONENAND_MAP
> -
> -#define ONENAND_ENV_OFFSET		0x260000 /* environment starts here */
> -
> -#define CONFIG_ENV_IS_IN_ONENAND	1
> -#define CONFIG_ENV_SIZE			(512 << 10) /* Total Size Environment */
> -#define CONFIG_ENV_ADDR			ONENAND_ENV_OFFSET
> -#endif
> -
> -#ifdef CONFIG_NAND
> -#define CONFIG_ENV_OFFSET		0x260000 /* environment starts here */
> -#define CONFIG_ENV_IS_IN_NAND	        1
> -#define CONFIG_ENV_SIZE			(512 << 10) /* Total Size Environment */
> -#define CONFIG_ENV_ADDR			NAND_ENV_OFFSET
> -#endif
> -
> -/*
>    * SMSC911x Ethernet
>    */
>   #if defined(CONFIG_CMD_NET)
> @@ -134,19 +119,50 @@
>   #define CONFIG_SMC911X_BASE		0x2C000000
>   #endif /* (CONFIG_CMD_NET) */
>
> +/*
> + * FLASH and environment organization
> + */
> +#ifdef CONFIG_NAND
> +#define CONFIG_SPL_UBI			1
> +#define CONFIG_SPL_UBI_MAX_VOL_LEBS	256
> +#define CONFIG_SPL_UBI_MAX_PEB_SIZE	(256*1024)
> +#define CONFIG_SPL_UBI_MAX_PEBS		4096
> +#define CONFIG_SPL_UBI_VOL_IDS		8
> +#define CONFIG_SPL_UBI_LOAD_MONITOR_ID	0
> +#define CONFIG_SPL_UBI_LOAD_KERNEL_ID	3
> +#define CONFIG_SPL_UBI_LOAD_ARGS_ID	4
> +#define CONFIG_SPL_UBI_PEB_OFFSET	4
> +#define CONFIG_SPL_UBI_VID_OFFSET	512
> +#define CONFIG_SPL_UBI_LEB_START	2048
> +#define CONFIG_SPL_UBI_INFO_ADDR	0x88080000
> +
> +#define CONFIG_ENV_IS_IN_UBI		1
> +#define CONFIG_ENV_UBI_PART		"UBI"
> +#define CONFIG_ENV_UBI_VOLUME		"config"
> +#define CONFIG_ENV_UBI_VOLUME_REDUND	"config_r"
> +#define CONFIG_UBI_SILENCE_MSG		1
> +#define CONFIG_UBIFS_SILENCE_MSG	1
> +#else
> +#define CONFIG_ENV_IS_NOWHERE
> +#endif
> +#define CONFIG_ENV_SIZE			(32*1024)
> +
> +#define CONFIG_RBTREE
> +#define CONFIG_MTD_PARTITIONS
> +#define MTDIDS_DEFAULT			"nand0=gpmc-nand.0"
> +#define MTDPARTS_DEFAULT		"mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
> +
>   /* OneNAND boot config */
>   #ifdef CONFIG_BOOT_ONENAND
>   #define CONFIG_SPL_ONENAND_SUPPORT
> -#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
>   #define CONFIG_SYS_ONENAND_PAGE_SIZE	2048
> -#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
> -#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
> -	(512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
> -
> +#define CONFIG_SYS_ONENAND_BASE		ONENAND_MAP
> +#define CONFIG_SYS_ONENAND_U_BOOT_OFFS	0x80000
>   #endif
>
>   /* NAND boot config */
>   #ifdef CONFIG_NAND
> +#define CONFIG_SPL_NAND_SUPPORT
>   #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
>   #define CONFIG_SYS_NAND_5_ADDR_CYCLE
>   #define CONFIG_SYS_NAND_PAGE_COUNT	64
> @@ -166,14 +182,8 @@
>   #define CONFIG_NAND_OMAP_ECCSCHEME	OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
>   #define CONFIG_NAND_OMAP_GPMC
>   #define CONFIG_BCH
> -
> -#define CONFIG_SYS_NAND_U_BOOT_OFFS	0x80000
> -/* NAND: SPL falcon mode configs */
> -#ifdef CONFIG_SPL_OS_BOOT
> -#define CONFIG_CMD_SPL_NAND_OFS		0x240000
> -#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS	0x280000
> -#define CONFIG_CMD_SPL_WRITE_SIZE	0x2000
> -#endif
>   #endif
>
> +#undef CONFIG_SPL_EXT_SUPPORT
> +
>   #endif /* __IGEP00X0_H */
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode
  2016-01-17  3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
@ 2016-01-21  6:08   ` Heiko Schocher
  2016-01-22 22:38     ` Enric Balletbo Serra
  0 siblings, 1 reply; 28+ messages in thread
From: Heiko Schocher @ 2016-01-21  6:08 UTC (permalink / raw)
  To: u-boot

Hello Ladislav,

Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
> Implement spl_start_uboot to let Falcon mode work.
>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> ---
>   board/isee/igep00x0/igep00x0.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
> index e2fce50..92811d8 100644
> --- a/board/isee/igep00x0/igep00x0.c
> +++ b/board/isee/igep00x0/igep00x0.c
> @@ -10,6 +10,7 @@
>   #include <ns16550.h>
>   #include <twl4030.h>
>   #include <netdev.h>
> +#include <spl.h>
>   #include <asm/gpio.h>
>   #include <asm/io.h>
>   #include <asm/arch/mem.h>
> @@ -212,3 +213,14 @@ int board_eth_init(bd_t *bis)
>   #endif
>   }
>   #endif
> +
> +#ifdef CONFIG_SPL_OS_BOOT
> +int spl_start_uboot(void)
> +{
> +	/* break into full u-boot on 'c' */
> +	if (serial_tstc() && serial_getc() == 'c')
> +		return 1;
> +
> +	return 0;
> +}
> +#endif
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-21  6:07   ` Heiko Schocher
@ 2016-01-22 22:35     ` Enric Balletbo Serra
  2016-01-24 13:44       ` Ladislav Michl
  2016-01-25  6:39       ` Heiko Schocher
  0 siblings, 2 replies; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-01-22 22:35 UTC (permalink / raw)
  To: u-boot

Hi Ladis,

Many thanks for your work on this, see some comments below ...

2016-01-21 7:07 GMT+01:00 Heiko Schocher <hs@denx.de>:
> Hello Ladislav,
>
> Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
>>
>> Convert IGEP board to use UBI volumes for U-Boot, its environment and
>> kernel. With exception of first four sectors read by SoC boot
>> ROM whole NAND is UBI managed. As code is too big now, drop
>> CONFIG_SPL_EXT_SUPPORT to make it fit.
>>
>> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
>> ---
>>   include/configs/omap3_igep00x0.h | 80
>> ++++++++++++++++++++++------------------
>>   1 file changed, 45 insertions(+), 35 deletions(-)
>
>
> Reviewed-by: Heiko Schocher <hs@denx.de>
>
> bye,
> Heiko
>
>>
>> diff --git a/include/configs/omap3_igep00x0.h
>> b/include/configs/omap3_igep00x0.h
>> index 5da6cfd..9afbcbe 100644
>> --- a/include/configs/omap3_igep00x0.h
>> +++ b/include/configs/omap3_igep00x0.h
>> @@ -74,6 +74,8 @@
>>   #define CONFIG_CMD_CACHE
>>   #ifdef CONFIG_BOOT_ONENAND
>>   #define CONFIG_CMD_ONENAND    /* ONENAND support              */
>> +#else
>> +#define CONFIG_CMD_UBI
>>   #endif
>>   #define CONFIG_CMD_DHCP
>>   #define CONFIG_CMD_PING
>> @@ -86,6 +88,10 @@
>>         "stdout=serial\0" \
>>         "stderr=serial\0"
>>
>> +#define ENV_MTD_SETTINGS \
>> +       "mtdids=nand0=gpmc-nand.0\0" \
>> +       "mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
>> +

I think this should be protected by CONFIG_BOOT_NAND, if is defined
CONFIG_BOOT_ONENAND the ENV_MTD_SETTINGS are wrong.

Also, as we're changing the memory map, I'd like to change the
reserved space for SPL to 2M instead of 512k, so we cover all NAND
block sizes from (64KB to 512KB)

>>   #define MEM_LAYOUT_SETTINGS \
>>         DEFAULT_LINUX_BOOT_ENV \
>>         "scriptaddr=0x87E00000\0" \
>> @@ -96,36 +102,15 @@
>>
>>   #include <config_distro_bootcmd.h>
>>
>> -
>>   #define CONFIG_EXTRA_ENV_SETTINGS \
>>         ENV_DEVICE_SETTINGS \
>> +       ENV_MTD_SETTINGS \
>>         MEM_LAYOUT_SETTINGS \
>>         BOOTENV
>>
>>   #endif
>>
>>   /*
>> - * FLASH and environment organization
>> - */
>> -
>> -#ifdef CONFIG_BOOT_ONENAND
>> -#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>> -
>> -#define ONENAND_ENV_OFFSET             0x260000 /* environment starts
>> here */
>> -
>> -#define CONFIG_ENV_IS_IN_ONENAND       1
>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total Size
>> Environment */
>> -#define CONFIG_ENV_ADDR                        ONENAND_ENV_OFFSET
>> -#endif
>> -
>> -#ifdef CONFIG_NAND
>> -#define CONFIG_ENV_OFFSET              0x260000 /* environment starts
>> here */
>> -#define CONFIG_ENV_IS_IN_NAND          1
>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total Size
>> Environment */
>> -#define CONFIG_ENV_ADDR                        NAND_ENV_OFFSET
>> -#endif
>> -
>> -/*
>>    * SMSC911x Ethernet
>>    */
>>   #if defined(CONFIG_CMD_NET)
>> @@ -134,19 +119,50 @@
>>   #define CONFIG_SMC911X_BASE           0x2C000000
>>   #endif /* (CONFIG_CMD_NET) */
>>
>> +/*
>> + * FLASH and environment organization
>> + */
>> +#ifdef CONFIG_NAND
>> +#define CONFIG_SPL_UBI                 1
>> +#define CONFIG_SPL_UBI_MAX_VOL_LEBS    256
>> +#define CONFIG_SPL_UBI_MAX_PEB_SIZE    (256*1024)
>> +#define CONFIG_SPL_UBI_MAX_PEBS                4096
>> +#define CONFIG_SPL_UBI_VOL_IDS         8
>> +#define CONFIG_SPL_UBI_LOAD_MONITOR_ID 0
>> +#define CONFIG_SPL_UBI_LOAD_KERNEL_ID  3
>> +#define CONFIG_SPL_UBI_LOAD_ARGS_ID    4
>> +#define CONFIG_SPL_UBI_PEB_OFFSET      4
>> +#define CONFIG_SPL_UBI_VID_OFFSET      512
>> +#define CONFIG_SPL_UBI_LEB_START       2048
>> +#define CONFIG_SPL_UBI_INFO_ADDR       0x88080000
>> +
>> +#define CONFIG_ENV_IS_IN_UBI           1
>> +#define CONFIG_ENV_UBI_PART            "UBI"
>> +#define CONFIG_ENV_UBI_VOLUME          "config"
>> +#define CONFIG_ENV_UBI_VOLUME_REDUND   "config_r"
>> +#define CONFIG_UBI_SILENCE_MSG         1
>> +#define CONFIG_UBIFS_SILENCE_MSG       1
>> +#else
>> +#define CONFIG_ENV_IS_NOWHERE
>> +#endif
>> +#define CONFIG_ENV_SIZE                        (32*1024)
>> +
>> +#define CONFIG_RBTREE
>> +#define CONFIG_MTD_PARTITIONS
>> +#define MTDIDS_DEFAULT                 "nand0=gpmc-nand.0"
>> +#define MTDPARTS_DEFAULT
>> "mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
>> +

Same comment as above.

>>   /* OneNAND boot config */
>>   #ifdef CONFIG_BOOT_ONENAND
>>   #define CONFIG_SPL_ONENAND_SUPPORT
>> -#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
>>   #define CONFIG_SYS_ONENAND_PAGE_SIZE  2048
>> -#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
>> -#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
>> -       (512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
>> -
>> +#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>> +#define CONFIG_SYS_ONENAND_U_BOOT_OFFS 0x80000
>>   #endif
>>
>>   /* NAND boot config */
>>   #ifdef CONFIG_NAND
>> +#define CONFIG_SPL_NAND_SUPPORT
>>   #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
>>   #define CONFIG_SYS_NAND_5_ADDR_CYCLE
>>   #define CONFIG_SYS_NAND_PAGE_COUNT    64
>> @@ -166,14 +182,8 @@
>>   #define CONFIG_NAND_OMAP_ECCSCHEME    OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
>>   #define CONFIG_NAND_OMAP_GPMC
>>   #define CONFIG_BCH
>> -
>> -#define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>> -/* NAND: SPL falcon mode configs */
>> -#ifdef CONFIG_SPL_OS_BOOT
>> -#define CONFIG_CMD_SPL_NAND_OFS                0x240000
>> -#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS        0x280000
>> -#define CONFIG_CMD_SPL_WRITE_SIZE      0x2000
>> -#endif
>>   #endif
>>
>> +#undef CONFIG_SPL_EXT_SUPPORT
>> +
>>   #endif /* __IGEP00X0_H */
>>
>

About the new layout you propose the following, right?

volume 0 is u-boot.img, 1 and 2 env, 3 kernel, 4 FDT, 5 rootfs (ubifs)

It's not possible load the kernel and the FDT from the rootfs directly, right?

BTW, I created the 5 volumes and copied the files to every volume but
I get following errors, do you know what I am missing?

U-Boot SPL 2016.01-00358-g4efe05f (Jan 22 2016 - 17:16:04)
Trying to boot from NAND
UBI warning: LEB 0 of 1 is missing
UBI warning: Failed to load volume 3
UBI warning: LEB 0 of 1 is missing
UBI warning: Failed to load volume 3
UBI warning: Failed
Loading Linux failed, falling back to U-Boot.
UBI warning: LEB 0 of 1 is missing
UBI warning: Failed to load volume 0
UBI warning: LEB 0 of 1 is missing
UBI warning: Failed to load volume 0
UBI warning: Failed
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Thanks,
Enric

> --
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

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

* [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode
  2016-01-21  6:08   ` Heiko Schocher
@ 2016-01-22 22:38     ` Enric Balletbo Serra
  0 siblings, 0 replies; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-01-22 22:38 UTC (permalink / raw)
  To: u-boot

2016-01-21 7:08 GMT+01:00 Heiko Schocher <hs@denx.de>:
> Hello Ladislav,
>
> Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
>>
>> Implement spl_start_uboot to let Falcon mode work.
>>
>> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
>> ---
>>   board/isee/igep00x0/igep00x0.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>
>
> Reviewed-by: Heiko Schocher <hs@denx.de>
>
> bye,
> Heiko
>
>>
>> diff --git a/board/isee/igep00x0/igep00x0.c
>> b/board/isee/igep00x0/igep00x0.c
>> index e2fce50..92811d8 100644
>> --- a/board/isee/igep00x0/igep00x0.c
>> +++ b/board/isee/igep00x0/igep00x0.c
>> @@ -10,6 +10,7 @@
>>   #include <ns16550.h>
>>   #include <twl4030.h>
>>   #include <netdev.h>
>> +#include <spl.h>
>>   #include <asm/gpio.h>
>>   #include <asm/io.h>
>>   #include <asm/arch/mem.h>
>> @@ -212,3 +213,14 @@ int board_eth_init(bd_t *bis)
>>   #endif
>>   }
>>   #endif
>> +
>> +#ifdef CONFIG_SPL_OS_BOOT
>> +int spl_start_uboot(void)
>> +{
>> +       /* break into full u-boot on 'c' */
>> +       if (serial_tstc() && serial_getc() == 'c')
>> +               return 1;
>> +
>> +       return 0;
>> +}
>> +#endif
>>
>
> --
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-22 22:35     ` Enric Balletbo Serra
@ 2016-01-24 13:44       ` Ladislav Michl
  2016-01-25  6:39       ` Heiko Schocher
  1 sibling, 0 replies; 28+ messages in thread
From: Ladislav Michl @ 2016-01-24 13:44 UTC (permalink / raw)
  To: u-boot

Hi Enric,

On Fri, Jan 22, 2016 at 11:35:49PM +0100, Enric Balletbo Serra wrote:
[...]
> > Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
[...]
> >> +#define ENV_MTD_SETTINGS \
> >> +       "mtdids=nand0=gpmc-nand.0\0" \
> >> +       "mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
> >> +
> 
> I think this should be protected by CONFIG_BOOT_NAND, if is defined
> CONFIG_BOOT_ONENAND the ENV_MTD_SETTINGS are wrong.

Ah, right! I'll do that in next version. Btw, I hope to have OneNAND
board version too, so I would be able to test that as well.

> Also, as we're changing the memory map, I'd like to change the
> reserved space for SPL to 2M instead of 512k, so we cover all NAND
> block sizes from (64KB to 512KB)

What if we do that dynamically? It is not problem in U-Boot as we are
already running FDT fixup, so adding one more shouldn't hurt too much.
And we need to run 'spl export' anyway to fixup RAM size, so it is not
problem for falcon mode, too.

[...] 
> About the new layout you propose the following, right?
> 
> volume 0 is u-boot.img, 1 and 2 env, 3 kernel, 4 FDT, 5 rootfs (ubifs)

Yes, that's right. U-Boot does not care about volumes above 4, it is purely
Linux thing, but I'm using it that way (and somewhere in distant future I'd
like to run database directly on top of UBI volume)

> It's not possible load the kernel and the FDT from the rootfs directly, right?

UBIFS will certainly not fit into SPL size.

> BTW, I created the 5 volumes and copied the files to every volume but
> I get following errors, do you know what I am missing?
> 
> U-Boot SPL 2016.01-00358-g4efe05f (Jan 22 2016 - 17:16:04)
> Trying to boot from NAND
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 3
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 3
> UBI warning: Failed
> Loading Linux failed, falling back to U-Boot.
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 0
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 0
> UBI warning: Failed
> SPL: failed to boot from all boot devices
> ### ERROR ### Please RESET the board ###

I've never seen that. How did you copy files into volumes? Btw, I haven't
tried doing that using U-Boot, but did:
$ ubiformat /dev/mtd1 -f root.ubi
(where root.ubi is product of PTXdist build)
Later I used f.e. 
$ ubiupdatevol /dev/ubi0_0 u-boot.img
to load files into volumes.

	ladis

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-22 22:35     ` Enric Balletbo Serra
  2016-01-24 13:44       ` Ladislav Michl
@ 2016-01-25  6:39       ` Heiko Schocher
  2016-01-25  7:26         ` Enric Balletbo Serra
  2016-01-25 15:13         ` [U-Boot] [PATCHv7 6/7] " Tom Rini
  1 sibling, 2 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-25  6:39 UTC (permalink / raw)
  To: u-boot

Hello Enric, Ladislav,

Am 22.01.2016 um 23:35 schrieb Enric Balletbo Serra:
> Hi Ladis,
>
> Many thanks for your work on this, see some comments below ...

Sorry, pull request is sent with this patch, see:

http://lists.denx.de/pipermail/u-boot/2016-January/239855.html

@Ladislav: Please send changes in a follow up patch, thanks!


> 2016-01-21 7:07 GMT+01:00 Heiko Schocher <hs@denx.de>:
>> Hello Ladislav,
>>
>> Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
>>>
>>> Convert IGEP board to use UBI volumes for U-Boot, its environment and
>>> kernel. With exception of first four sectors read by SoC boot
>>> ROM whole NAND is UBI managed. As code is too big now, drop
>>> CONFIG_SPL_EXT_SUPPORT to make it fit.
>>>
>>> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
>>> ---
>>>    include/configs/omap3_igep00x0.h | 80
>>> ++++++++++++++++++++++------------------
>>>    1 file changed, 45 insertions(+), 35 deletions(-)
>>
>>
>> Reviewed-by: Heiko Schocher <hs@denx.de>
>>
>> bye,
>> Heiko
>>
>>>
>>> diff --git a/include/configs/omap3_igep00x0.h
>>> b/include/configs/omap3_igep00x0.h
>>> index 5da6cfd..9afbcbe 100644
>>> --- a/include/configs/omap3_igep00x0.h
>>> +++ b/include/configs/omap3_igep00x0.h
>>> @@ -74,6 +74,8 @@
>>>    #define CONFIG_CMD_CACHE
>>>    #ifdef CONFIG_BOOT_ONENAND
>>>    #define CONFIG_CMD_ONENAND    /* ONENAND support              */
>>> +#else
>>> +#define CONFIG_CMD_UBI
>>>    #endif
>>>    #define CONFIG_CMD_DHCP
>>>    #define CONFIG_CMD_PING
>>> @@ -86,6 +88,10 @@
>>>          "stdout=serial\0" \
>>>          "stderr=serial\0"
>>>
>>> +#define ENV_MTD_SETTINGS \
>>> +       "mtdids=nand0=gpmc-nand.0\0" \
>>> +       "mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
>>> +
>
> I think this should be protected by CONFIG_BOOT_NAND, if is defined
> CONFIG_BOOT_ONENAND the ENV_MTD_SETTINGS are wrong.

Good point ...

> Also, as we're changing the memory map, I'd like to change the
> reserved space for SPL to 2M instead of 512k, so we cover all NAND
> block sizes from (64KB to 512KB)

I do not understand this, but I have no details about the hw ...

>>>    #define MEM_LAYOUT_SETTINGS \
>>>          DEFAULT_LINUX_BOOT_ENV \
>>>          "scriptaddr=0x87E00000\0" \
>>> @@ -96,36 +102,15 @@
>>>
>>>    #include <config_distro_bootcmd.h>
>>>
>>> -
>>>    #define CONFIG_EXTRA_ENV_SETTINGS \
>>>          ENV_DEVICE_SETTINGS \
>>> +       ENV_MTD_SETTINGS \
>>>          MEM_LAYOUT_SETTINGS \
>>>          BOOTENV
>>>
>>>    #endif
>>>
>>>    /*
>>> - * FLASH and environment organization
>>> - */
>>> -
>>> -#ifdef CONFIG_BOOT_ONENAND
>>> -#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>> -
>>> -#define ONENAND_ENV_OFFSET             0x260000 /* environment starts
>>> here */
>>> -
>>> -#define CONFIG_ENV_IS_IN_ONENAND       1
>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total Size
>>> Environment */
>>> -#define CONFIG_ENV_ADDR                        ONENAND_ENV_OFFSET
>>> -#endif
>>> -
>>> -#ifdef CONFIG_NAND
>>> -#define CONFIG_ENV_OFFSET              0x260000 /* environment starts
>>> here */
>>> -#define CONFIG_ENV_IS_IN_NAND          1
>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total Size
>>> Environment */
>>> -#define CONFIG_ENV_ADDR                        NAND_ENV_OFFSET
>>> -#endif
>>> -
>>> -/*
>>>     * SMSC911x Ethernet
>>>     */
>>>    #if defined(CONFIG_CMD_NET)
>>> @@ -134,19 +119,50 @@
>>>    #define CONFIG_SMC911X_BASE           0x2C000000
>>>    #endif /* (CONFIG_CMD_NET) */
>>>
>>> +/*
>>> + * FLASH and environment organization
>>> + */
>>> +#ifdef CONFIG_NAND
>>> +#define CONFIG_SPL_UBI                 1
>>> +#define CONFIG_SPL_UBI_MAX_VOL_LEBS    256
>>> +#define CONFIG_SPL_UBI_MAX_PEB_SIZE    (256*1024)
>>> +#define CONFIG_SPL_UBI_MAX_PEBS                4096
>>> +#define CONFIG_SPL_UBI_VOL_IDS         8
>>> +#define CONFIG_SPL_UBI_LOAD_MONITOR_ID 0
>>> +#define CONFIG_SPL_UBI_LOAD_KERNEL_ID  3
>>> +#define CONFIG_SPL_UBI_LOAD_ARGS_ID    4
>>> +#define CONFIG_SPL_UBI_PEB_OFFSET      4
>>> +#define CONFIG_SPL_UBI_VID_OFFSET      512
>>> +#define CONFIG_SPL_UBI_LEB_START       2048
>>> +#define CONFIG_SPL_UBI_INFO_ADDR       0x88080000
>>> +
>>> +#define CONFIG_ENV_IS_IN_UBI           1
>>> +#define CONFIG_ENV_UBI_PART            "UBI"
>>> +#define CONFIG_ENV_UBI_VOLUME          "config"
>>> +#define CONFIG_ENV_UBI_VOLUME_REDUND   "config_r"
>>> +#define CONFIG_UBI_SILENCE_MSG         1
>>> +#define CONFIG_UBIFS_SILENCE_MSG       1
>>> +#else
>>> +#define CONFIG_ENV_IS_NOWHERE
>>> +#endif
>>> +#define CONFIG_ENV_SIZE                        (32*1024)
>>> +
>>> +#define CONFIG_RBTREE
>>> +#define CONFIG_MTD_PARTITIONS
>>> +#define MTDIDS_DEFAULT                 "nand0=gpmc-nand.0"
>>> +#define MTDPARTS_DEFAULT
>>> "mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
>>> +
>
> Same comment as above.
>
>>>    /* OneNAND boot config */
>>>    #ifdef CONFIG_BOOT_ONENAND
>>>    #define CONFIG_SPL_ONENAND_SUPPORT
>>> -#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
>>>    #define CONFIG_SYS_ONENAND_PAGE_SIZE  2048
>>> -#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
>>> -#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
>>> -       (512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
>>> -
>>> +#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>> +#define CONFIG_SYS_ONENAND_U_BOOT_OFFS 0x80000
>>>    #endif
>>>
>>>    /* NAND boot config */
>>>    #ifdef CONFIG_NAND
>>> +#define CONFIG_SPL_NAND_SUPPORT
>>>    #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
>>>    #define CONFIG_SYS_NAND_5_ADDR_CYCLE
>>>    #define CONFIG_SYS_NAND_PAGE_COUNT    64
>>> @@ -166,14 +182,8 @@
>>>    #define CONFIG_NAND_OMAP_ECCSCHEME    OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
>>>    #define CONFIG_NAND_OMAP_GPMC
>>>    #define CONFIG_BCH
>>> -
>>> -#define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>>> -/* NAND: SPL falcon mode configs */
>>> -#ifdef CONFIG_SPL_OS_BOOT
>>> -#define CONFIG_CMD_SPL_NAND_OFS                0x240000
>>> -#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS        0x280000
>>> -#define CONFIG_CMD_SPL_WRITE_SIZE      0x2000
>>> -#endif
>>>    #endif
>>>
>>> +#undef CONFIG_SPL_EXT_SUPPORT
>>> +
>>>    #endif /* __IGEP00X0_H */
>>>
>>
>
> About the new layout you propose the following, right?
>
> volume 0 is u-boot.img, 1 and 2 env, 3 kernel, 4 FDT, 5 rootfs (ubifs)
>
> It's not possible load the kernel and the FDT from the rootfs directly, right?

That would be nice, but for this we need UBIFS support in SPL.
Patches are welcome ;-)

> BTW, I created the 5 volumes and copied the files to every volume but
> I get following errors, do you know what I am missing?
>
> U-Boot SPL 2016.01-00358-g4efe05f (Jan 22 2016 - 17:16:04)
> Trying to boot from NAND
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 3
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 3
> UBI warning: Failed
> Loading Linux failed, falling back to U-Boot.
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 0
> UBI warning: LEB 0 of 1 is missing
> UBI warning: Failed to load volume 0
> UBI warning: Failed
> SPL: failed to boot from all boot devices
> ### ERROR ### Please RESET the board ###
>
> Thanks,
> Enric

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25  6:39       ` Heiko Schocher
@ 2016-01-25  7:26         ` Enric Balletbo Serra
  2016-01-25  8:13           ` Heiko Schocher
  2016-01-25 15:56           ` Ladislav Michl
  2016-01-25 15:13         ` [U-Boot] [PATCHv7 6/7] " Tom Rini
  1 sibling, 2 replies; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-01-25  7:26 UTC (permalink / raw)
  To: u-boot

Hi,

2016-01-25 7:39 GMT+01:00 Heiko Schocher <hs@denx.de>:
> Hello Enric, Ladislav,
>
> Am 22.01.2016 um 23:35 schrieb Enric Balletbo Serra:
>>
>> Hi Ladis,
>>
>> Many thanks for your work on this, see some comments below ...
>
>
> Sorry, pull request is sent with this patch, see:
>
> http://lists.denx.de/pipermail/u-boot/2016-January/239855.html
>
> @Ladislav: Please send changes in a follow up patch, thanks!
>
>
>
>> 2016-01-21 7:07 GMT+01:00 Heiko Schocher <hs@denx.de>:
>>>
>>> Hello Ladislav,
>>>
>>> Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
>>>>
>>>>
>>>> Convert IGEP board to use UBI volumes for U-Boot, its environment and
>>>> kernel. With exception of first four sectors read by SoC boot
>>>> ROM whole NAND is UBI managed. As code is too big now, drop
>>>> CONFIG_SPL_EXT_SUPPORT to make it fit.
>>>>
>>>> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
>>>> ---
>>>>    include/configs/omap3_igep00x0.h | 80
>>>> ++++++++++++++++++++++------------------
>>>>    1 file changed, 45 insertions(+), 35 deletions(-)
>>>
>>>
>>>
>>> Reviewed-by: Heiko Schocher <hs@denx.de>
>>>
>>> bye,
>>> Heiko
>>>
>>>>
>>>> diff --git a/include/configs/omap3_igep00x0.h
>>>> b/include/configs/omap3_igep00x0.h
>>>> index 5da6cfd..9afbcbe 100644
>>>> --- a/include/configs/omap3_igep00x0.h
>>>> +++ b/include/configs/omap3_igep00x0.h
>>>> @@ -74,6 +74,8 @@
>>>>    #define CONFIG_CMD_CACHE
>>>>    #ifdef CONFIG_BOOT_ONENAND
>>>>    #define CONFIG_CMD_ONENAND    /* ONENAND support              */
>>>> +#else
>>>> +#define CONFIG_CMD_UBI
>>>>    #endif
>>>>    #define CONFIG_CMD_DHCP
>>>>    #define CONFIG_CMD_PING
>>>> @@ -86,6 +88,10 @@
>>>>          "stdout=serial\0" \
>>>>          "stderr=serial\0"
>>>>
>>>> +#define ENV_MTD_SETTINGS \
>>>> +       "mtdids=nand0=gpmc-nand.0\0" \
>>>> +       "mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
>>>> +
>>
>>
>> I think this should be protected by CONFIG_BOOT_NAND, if is defined
>> CONFIG_BOOT_ONENAND the ENV_MTD_SETTINGS are wrong.
>
>
> Good point ...
>
>> Also, as we're changing the memory map, I'd like to change the
>> reserved space for SPL to 2M instead of 512k, so we cover all NAND
>> block sizes from (64KB to 512KB)
>
>
> I do not understand this, but I have no details about the hw ...
>

The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
in production is a practice flash the SPL 4 times. OneNAND/NAND
devices can have different block sizes and the OMAP ROM boot supports
block sizes from 64KB to 512K. For IGEP boards in particular, at least
there are boards that have block size of 128K and 256K. What I would
meant here is set as default the mtdparts variable to reserve 2M for
SPL, just to cover all the cases.

mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0


>
>>>>    #define MEM_LAYOUT_SETTINGS \
>>>>          DEFAULT_LINUX_BOOT_ENV \
>>>>          "scriptaddr=0x87E00000\0" \
>>>> @@ -96,36 +102,15 @@
>>>>
>>>>    #include <config_distro_bootcmd.h>
>>>>
>>>> -
>>>>    #define CONFIG_EXTRA_ENV_SETTINGS \
>>>>          ENV_DEVICE_SETTINGS \
>>>> +       ENV_MTD_SETTINGS \
>>>>          MEM_LAYOUT_SETTINGS \
>>>>          BOOTENV
>>>>
>>>>    #endif
>>>>
>>>>    /*
>>>> - * FLASH and environment organization
>>>> - */
>>>> -
>>>> -#ifdef CONFIG_BOOT_ONENAND
>>>> -#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>>> -
>>>> -#define ONENAND_ENV_OFFSET             0x260000 /* environment starts
>>>> here */
>>>> -
>>>> -#define CONFIG_ENV_IS_IN_ONENAND       1
>>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total
>>>> Size
>>>> Environment */
>>>> -#define CONFIG_ENV_ADDR                        ONENAND_ENV_OFFSET
>>>> -#endif
>>>> -
>>>> -#ifdef CONFIG_NAND
>>>> -#define CONFIG_ENV_OFFSET              0x260000 /* environment starts
>>>> here */
>>>> -#define CONFIG_ENV_IS_IN_NAND          1
>>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total
>>>> Size
>>>> Environment */
>>>> -#define CONFIG_ENV_ADDR                        NAND_ENV_OFFSET
>>>> -#endif
>>>> -
>>>> -/*
>>>>     * SMSC911x Ethernet
>>>>     */
>>>>    #if defined(CONFIG_CMD_NET)
>>>> @@ -134,19 +119,50 @@
>>>>    #define CONFIG_SMC911X_BASE           0x2C000000
>>>>    #endif /* (CONFIG_CMD_NET) */
>>>>
>>>> +/*
>>>> + * FLASH and environment organization
>>>> + */
>>>> +#ifdef CONFIG_NAND
>>>> +#define CONFIG_SPL_UBI                 1
>>>> +#define CONFIG_SPL_UBI_MAX_VOL_LEBS    256
>>>> +#define CONFIG_SPL_UBI_MAX_PEB_SIZE    (256*1024)
>>>> +#define CONFIG_SPL_UBI_MAX_PEBS                4096
>>>> +#define CONFIG_SPL_UBI_VOL_IDS         8
>>>> +#define CONFIG_SPL_UBI_LOAD_MONITOR_ID 0
>>>> +#define CONFIG_SPL_UBI_LOAD_KERNEL_ID  3
>>>> +#define CONFIG_SPL_UBI_LOAD_ARGS_ID    4
>>>> +#define CONFIG_SPL_UBI_PEB_OFFSET      4
>>>> +#define CONFIG_SPL_UBI_VID_OFFSET      512
>>>> +#define CONFIG_SPL_UBI_LEB_START       2048
>>>> +#define CONFIG_SPL_UBI_INFO_ADDR       0x88080000
>>>> +
>>>> +#define CONFIG_ENV_IS_IN_UBI           1
>>>> +#define CONFIG_ENV_UBI_PART            "UBI"
>>>> +#define CONFIG_ENV_UBI_VOLUME          "config"
>>>> +#define CONFIG_ENV_UBI_VOLUME_REDUND   "config_r"
>>>> +#define CONFIG_UBI_SILENCE_MSG         1
>>>> +#define CONFIG_UBIFS_SILENCE_MSG       1
>>>> +#else
>>>> +#define CONFIG_ENV_IS_NOWHERE
>>>> +#endif
>>>> +#define CONFIG_ENV_SIZE                        (32*1024)
>>>> +
>>>> +#define CONFIG_RBTREE
>>>> +#define CONFIG_MTD_PARTITIONS
>>>> +#define MTDIDS_DEFAULT                 "nand0=gpmc-nand.0"
>>>> +#define MTDPARTS_DEFAULT
>>>> "mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
>>>> +
>>
>>
>> Same comment as above.
>>
>>>>    /* OneNAND boot config */
>>>>    #ifdef CONFIG_BOOT_ONENAND
>>>>    #define CONFIG_SPL_ONENAND_SUPPORT
>>>> -#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
>>>>    #define CONFIG_SYS_ONENAND_PAGE_SIZE  2048
>>>> -#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
>>>> -#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
>>>> -       (512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
>>>> -
>>>> +#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>>> +#define CONFIG_SYS_ONENAND_U_BOOT_OFFS 0x80000
>>>>    #endif
>>>>
>>>>    /* NAND boot config */
>>>>    #ifdef CONFIG_NAND
>>>> +#define CONFIG_SPL_NAND_SUPPORT
>>>>    #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
>>>>    #define CONFIG_SYS_NAND_5_ADDR_CYCLE
>>>>    #define CONFIG_SYS_NAND_PAGE_COUNT    64
>>>> @@ -166,14 +182,8 @@
>>>>    #define CONFIG_NAND_OMAP_ECCSCHEME
>>>> OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
>>>>    #define CONFIG_NAND_OMAP_GPMC
>>>>    #define CONFIG_BCH
>>>> -
>>>> -#define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>>>> -/* NAND: SPL falcon mode configs */
>>>> -#ifdef CONFIG_SPL_OS_BOOT
>>>> -#define CONFIG_CMD_SPL_NAND_OFS                0x240000
>>>> -#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS        0x280000
>>>> -#define CONFIG_CMD_SPL_WRITE_SIZE      0x2000
>>>> -#endif
>>>>    #endif
>>>>
>>>> +#undef CONFIG_SPL_EXT_SUPPORT
>>>> +
>>>>    #endif /* __IGEP00X0_H */
>>>>
>>>
>>
>> About the new layout you propose the following, right?
>>
>> volume 0 is u-boot.img, 1 and 2 env, 3 kernel, 4 FDT, 5 rootfs (ubifs)
>>
>> It's not possible load the kernel and the FDT from the rootfs directly,
>> right?
>
>
> That would be nice, but for this we need UBIFS support in SPL.
> Patches are welcome ;-)
>

Hehe, yes, I think the problem is fit the ubifs into the SPL size.

>> BTW, I created the 5 volumes and copied the files to every volume but
>> I get following errors, do you know what I am missing?
>>
>> U-Boot SPL 2016.01-00358-g4efe05f (Jan 22 2016 - 17:16:04)
>> Trying to boot from NAND
>> UBI warning: LEB 0 of 1 is missing
>> UBI warning: Failed to load volume 3
>> UBI warning: LEB 0 of 1 is missing
>> UBI warning: Failed to load volume 3
>> UBI warning: Failed
>> Loading Linux failed, falling back to U-Boot.
>> UBI warning: LEB 0 of 1 is missing
>> UBI warning: Failed to load volume 0
>> UBI warning: LEB 0 of 1 is missing
>> UBI warning: Failed to load volume 0
>> UBI warning: Failed
>> SPL: failed to boot from all boot devices
>> ### ERROR ### Please RESET the board ###
>>
>> Thanks,
>> Enric
>
>
> bye,
> Heiko
>
> --
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25  7:26         ` Enric Balletbo Serra
@ 2016-01-25  8:13           ` Heiko Schocher
  2016-01-25 15:56           ` Ladislav Michl
  1 sibling, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-25  8:13 UTC (permalink / raw)
  To: u-boot

Hello Enric,

Am 25.01.2016 um 08:26 schrieb Enric Balletbo Serra:
> Hi,
>
> 2016-01-25 7:39 GMT+01:00 Heiko Schocher <hs@denx.de>:
>> Hello Enric, Ladislav,
>>
>> Am 22.01.2016 um 23:35 schrieb Enric Balletbo Serra:
>>>
>>> Hi Ladis,
>>>
>>> Many thanks for your work on this, see some comments below ...
>>
>>
>> Sorry, pull request is sent with this patch, see:
>>
>> http://lists.denx.de/pipermail/u-boot/2016-January/239855.html
>>
>> @Ladislav: Please send changes in a follow up patch, thanks!
>>
>>
>>
>>> 2016-01-21 7:07 GMT+01:00 Heiko Schocher <hs@denx.de>:
>>>>
>>>> Hello Ladislav,
>>>>
>>>> Am 17.01.2016 um 04:16 schrieb Ladislav Michl:
>>>>>
>>>>>
>>>>> Convert IGEP board to use UBI volumes for U-Boot, its environment and
>>>>> kernel. With exception of first four sectors read by SoC boot
>>>>> ROM whole NAND is UBI managed. As code is too big now, drop
>>>>> CONFIG_SPL_EXT_SUPPORT to make it fit.
>>>>>
>>>>> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
>>>>> ---
>>>>>     include/configs/omap3_igep00x0.h | 80
>>>>> ++++++++++++++++++++++------------------
>>>>>     1 file changed, 45 insertions(+), 35 deletions(-)
>>>>
>>>>
>>>>
>>>> Reviewed-by: Heiko Schocher <hs@denx.de>
>>>>
>>>> bye,
>>>> Heiko
>>>>
>>>>>
>>>>> diff --git a/include/configs/omap3_igep00x0.h
>>>>> b/include/configs/omap3_igep00x0.h
>>>>> index 5da6cfd..9afbcbe 100644
>>>>> --- a/include/configs/omap3_igep00x0.h
>>>>> +++ b/include/configs/omap3_igep00x0.h
>>>>> @@ -74,6 +74,8 @@
>>>>>     #define CONFIG_CMD_CACHE
>>>>>     #ifdef CONFIG_BOOT_ONENAND
>>>>>     #define CONFIG_CMD_ONENAND    /* ONENAND support              */
>>>>> +#else
>>>>> +#define CONFIG_CMD_UBI
>>>>>     #endif
>>>>>     #define CONFIG_CMD_DHCP
>>>>>     #define CONFIG_CMD_PING
>>>>> @@ -86,6 +88,10 @@
>>>>>           "stdout=serial\0" \
>>>>>           "stderr=serial\0"
>>>>>
>>>>> +#define ENV_MTD_SETTINGS \
>>>>> +       "mtdids=nand0=gpmc-nand.0\0" \
>>>>> +       "mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
>>>>> +
>>>
>>>
>>> I think this should be protected by CONFIG_BOOT_NAND, if is defined
>>> CONFIG_BOOT_ONENAND the ENV_MTD_SETTINGS are wrong.
>>
>>
>> Good point ...
>>
>>> Also, as we're changing the memory map, I'd like to change the
>>> reserved space for SPL to 2M instead of 512k, so we cover all NAND
>>> block sizes from (64KB to 512KB)
>>
>>
>> I do not understand this, but I have no details about the hw ...
>>
>
> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
> in production is a practice flash the SPL 4 times. OneNAND/NAND
> devices can have different block sizes and the OMAP ROM boot supports
> block sizes from 64KB to 512K. For IGEP boards in particular, at least
> there are boards that have block size of 128K and 256K. What I would
> meant here is set as default the mtdparts variable to reserve 2M for
> SPL, just to cover all the cases.

Thanks for the explanation.

> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
>
>
>>
>>>>>     #define MEM_LAYOUT_SETTINGS \
>>>>>           DEFAULT_LINUX_BOOT_ENV \
>>>>>           "scriptaddr=0x87E00000\0" \
>>>>> @@ -96,36 +102,15 @@
>>>>>
>>>>>     #include <config_distro_bootcmd.h>
>>>>>
>>>>> -
>>>>>     #define CONFIG_EXTRA_ENV_SETTINGS \
>>>>>           ENV_DEVICE_SETTINGS \
>>>>> +       ENV_MTD_SETTINGS \
>>>>>           MEM_LAYOUT_SETTINGS \
>>>>>           BOOTENV
>>>>>
>>>>>     #endif
>>>>>
>>>>>     /*
>>>>> - * FLASH and environment organization
>>>>> - */
>>>>> -
>>>>> -#ifdef CONFIG_BOOT_ONENAND
>>>>> -#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>>>> -
>>>>> -#define ONENAND_ENV_OFFSET             0x260000 /* environment starts
>>>>> here */
>>>>> -
>>>>> -#define CONFIG_ENV_IS_IN_ONENAND       1
>>>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total
>>>>> Size
>>>>> Environment */
>>>>> -#define CONFIG_ENV_ADDR                        ONENAND_ENV_OFFSET
>>>>> -#endif
>>>>> -
>>>>> -#ifdef CONFIG_NAND
>>>>> -#define CONFIG_ENV_OFFSET              0x260000 /* environment starts
>>>>> here */
>>>>> -#define CONFIG_ENV_IS_IN_NAND          1
>>>>> -#define CONFIG_ENV_SIZE                        (512 << 10) /* Total
>>>>> Size
>>>>> Environment */
>>>>> -#define CONFIG_ENV_ADDR                        NAND_ENV_OFFSET
>>>>> -#endif
>>>>> -
>>>>> -/*
>>>>>      * SMSC911x Ethernet
>>>>>      */
>>>>>     #if defined(CONFIG_CMD_NET)
>>>>> @@ -134,19 +119,50 @@
>>>>>     #define CONFIG_SMC911X_BASE           0x2C000000
>>>>>     #endif /* (CONFIG_CMD_NET) */
>>>>>
>>>>> +/*
>>>>> + * FLASH and environment organization
>>>>> + */
>>>>> +#ifdef CONFIG_NAND
>>>>> +#define CONFIG_SPL_UBI                 1
>>>>> +#define CONFIG_SPL_UBI_MAX_VOL_LEBS    256
>>>>> +#define CONFIG_SPL_UBI_MAX_PEB_SIZE    (256*1024)
>>>>> +#define CONFIG_SPL_UBI_MAX_PEBS                4096
>>>>> +#define CONFIG_SPL_UBI_VOL_IDS         8
>>>>> +#define CONFIG_SPL_UBI_LOAD_MONITOR_ID 0
>>>>> +#define CONFIG_SPL_UBI_LOAD_KERNEL_ID  3
>>>>> +#define CONFIG_SPL_UBI_LOAD_ARGS_ID    4
>>>>> +#define CONFIG_SPL_UBI_PEB_OFFSET      4
>>>>> +#define CONFIG_SPL_UBI_VID_OFFSET      512
>>>>> +#define CONFIG_SPL_UBI_LEB_START       2048
>>>>> +#define CONFIG_SPL_UBI_INFO_ADDR       0x88080000
>>>>> +
>>>>> +#define CONFIG_ENV_IS_IN_UBI           1
>>>>> +#define CONFIG_ENV_UBI_PART            "UBI"
>>>>> +#define CONFIG_ENV_UBI_VOLUME          "config"
>>>>> +#define CONFIG_ENV_UBI_VOLUME_REDUND   "config_r"
>>>>> +#define CONFIG_UBI_SILENCE_MSG         1
>>>>> +#define CONFIG_UBIFS_SILENCE_MSG       1
>>>>> +#else
>>>>> +#define CONFIG_ENV_IS_NOWHERE
>>>>> +#endif
>>>>> +#define CONFIG_ENV_SIZE                        (32*1024)
>>>>> +
>>>>> +#define CONFIG_RBTREE
>>>>> +#define CONFIG_MTD_PARTITIONS
>>>>> +#define MTDIDS_DEFAULT                 "nand0=gpmc-nand.0"
>>>>> +#define MTDPARTS_DEFAULT
>>>>> "mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
>>>>> +
>>>
>>>
>>> Same comment as above.
>>>
>>>>>     /* OneNAND boot config */
>>>>>     #ifdef CONFIG_BOOT_ONENAND
>>>>>     #define CONFIG_SPL_ONENAND_SUPPORT
>>>>> -#define CONFIG_SYS_ONENAND_U_BOOT_OFFS  0x80000
>>>>>     #define CONFIG_SYS_ONENAND_PAGE_SIZE  2048
>>>>> -#define CONFIG_SPL_ONENAND_LOAD_ADDR    0x80000
>>>>> -#define CONFIG_SPL_ONENAND_LOAD_SIZE    \
>>>>> -       (512 * 1024 - CONFIG_SPL_ONENAND_LOAD_ADDR)
>>>>> -
>>>>> +#define CONFIG_SYS_ONENAND_BASE                ONENAND_MAP
>>>>> +#define CONFIG_SYS_ONENAND_U_BOOT_OFFS 0x80000
>>>>>     #endif
>>>>>
>>>>>     /* NAND boot config */
>>>>>     #ifdef CONFIG_NAND
>>>>> +#define CONFIG_SPL_NAND_SUPPORT
>>>>>     #define CONFIG_SYS_NAND_BUSWIDTH_16BIT
>>>>>     #define CONFIG_SYS_NAND_5_ADDR_CYCLE
>>>>>     #define CONFIG_SYS_NAND_PAGE_COUNT    64
>>>>> @@ -166,14 +182,8 @@
>>>>>     #define CONFIG_NAND_OMAP_ECCSCHEME
>>>>> OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
>>>>>     #define CONFIG_NAND_OMAP_GPMC
>>>>>     #define CONFIG_BCH
>>>>> -
>>>>> -#define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>>>>> -/* NAND: SPL falcon mode configs */
>>>>> -#ifdef CONFIG_SPL_OS_BOOT
>>>>> -#define CONFIG_CMD_SPL_NAND_OFS                0x240000
>>>>> -#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS        0x280000
>>>>> -#define CONFIG_CMD_SPL_WRITE_SIZE      0x2000
>>>>> -#endif
>>>>>     #endif
>>>>>
>>>>> +#undef CONFIG_SPL_EXT_SUPPORT
>>>>> +
>>>>>     #endif /* __IGEP00X0_H */
>>>>>
>>>>
>>>
>>> About the new layout you propose the following, right?
>>>
>>> volume 0 is u-boot.img, 1 and 2 env, 3 kernel, 4 FDT, 5 rootfs (ubifs)
>>>
>>> It's not possible load the kernel and the FDT from the rootfs directly,
>>> right?
>>
>>
>> That would be nice, but for this we need UBIFS support in SPL.
>> Patches are welcome ;-)
>>
>
> Hehe, yes, I think the problem is fit the ubifs into the SPL size.

Yes, maybe ...

bye,
Heiko
>
>>> BTW, I created the 5 volumes and copied the files to every volume but
>>> I get following errors, do you know what I am missing?
>>>
>>> U-Boot SPL 2016.01-00358-g4efe05f (Jan 22 2016 - 17:16:04)
>>> Trying to boot from NAND
>>> UBI warning: LEB 0 of 1 is missing
>>> UBI warning: Failed to load volume 3
>>> UBI warning: LEB 0 of 1 is missing
>>> UBI warning: Failed to load volume 3
>>> UBI warning: Failed
>>> Loading Linux failed, falling back to U-Boot.
>>> UBI warning: LEB 0 of 1 is missing
>>> UBI warning: Failed to load volume 0
>>> UBI warning: LEB 0 of 1 is missing
>>> UBI warning: Failed to load volume 0
>>> UBI warning: Failed
>>> SPL: failed to boot from all boot devices
>>> ### ERROR ### Please RESET the board ###
>>>
>>> Thanks,
>>> Enric
>>
>>
>> bye,
>> Heiko
>>
>> --
>> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25  6:39       ` Heiko Schocher
  2016-01-25  7:26         ` Enric Balletbo Serra
@ 2016-01-25 15:13         ` Tom Rini
  2016-01-25 15:35           ` Heiko Schocher
  1 sibling, 1 reply; 28+ messages in thread
From: Tom Rini @ 2016-01-25 15:13 UTC (permalink / raw)
  To: u-boot

On Mon, Jan 25, 2016 at 07:39:10AM +0100, Heiko Schocher wrote:
> Hello Enric, Ladislav,
> 
> Am 22.01.2016 um 23:35 schrieb Enric Balletbo Serra:
> >Hi Ladis,
> >
> >Many thanks for your work on this, see some comments below ...
> 
> Sorry, pull request is sent with this patch, see:
> 
> http://lists.denx.de/pipermail/u-boot/2016-January/239855.html

Note that the PR there just lists one patch...

> @Ladislav: Please send changes in a follow up patch, thanks!

No, sorry.  I had intentionally not yet grabbed the PR there yet since I
didn't want this series in until Enric had ack'd them as it's a behavior
change and he is listed as the maintainer.  You grabbed them a bit too
early, sorry!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160125/621656be/attachment.sig>

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25 15:13         ` [U-Boot] [PATCHv7 6/7] " Tom Rini
@ 2016-01-25 15:35           ` Heiko Schocher
  0 siblings, 0 replies; 28+ messages in thread
From: Heiko Schocher @ 2016-01-25 15:35 UTC (permalink / raw)
  To: u-boot

Hello Tom,

Am 25.01.2016 um 16:13 schrieb Tom Rini:
> On Mon, Jan 25, 2016 at 07:39:10AM +0100, Heiko Schocher wrote:
>> Hello Enric, Ladislav,
>>
>> Am 22.01.2016 um 23:35 schrieb Enric Balletbo Serra:
>>> Hi Ladis,
>>>
>>> Many thanks for your work on this, see some comments below ...
>>
>> Sorry, pull request is sent with this patch, see:
>>
>> http://lists.denx.de/pipermail/u-boot/2016-January/239855.html
>
> Note that the PR there just lists one patch...

wrong link, sorry.

>> @Ladislav: Please send changes in a follow up patch, thanks!
>
> No, sorry.  I had intentionally not yet grabbed the PR there yet since I
> didn't want this series in until Enric had ack'd them as it's a behavior
> change and he is listed as the maintainer.  You grabbed them a bit too
> early, sorry!

Ups, sorry (may I was to happy for having UBI support in SPL)

Ok, so I wait for a new version for this patch.

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25  7:26         ` Enric Balletbo Serra
  2016-01-25  8:13           ` Heiko Schocher
@ 2016-01-25 15:56           ` Ladislav Michl
  2016-01-25 16:56             ` Enric Balletbo Serra
  2016-06-04 20:48             ` [U-Boot] [RFC] runtime mtdparts_default; was: " Ladislav Michl
  1 sibling, 2 replies; 28+ messages in thread
From: Ladislav Michl @ 2016-01-25 15:56 UTC (permalink / raw)
  To: u-boot

Hi Enric,

On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
> in production is a practice flash the SPL 4 times. OneNAND/NAND
> devices can have different block sizes and the OMAP ROM boot supports
> block sizes from 64KB to 512K. For IGEP boards in particular, at least
> there are boards that have block size of 128K and 256K. What I would
> meant here is set as default the mtdparts variable to reserve 2M for
> SPL, just to cover all the cases.
> 
> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0

So far there was no ack or nack to yesterday's proposal making that
dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
only mtd needs fixed offset. So I'd like to see this offset calculated as
4*block_size, not some "worst case" value...

	ladis

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25 15:56           ` Ladislav Michl
@ 2016-01-25 16:56             ` Enric Balletbo Serra
  2016-04-13  5:19               ` Heiko Schocher
  2016-06-04 20:48             ` [U-Boot] [RFC] runtime mtdparts_default; was: " Ladislav Michl
  1 sibling, 1 reply; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-01-25 16:56 UTC (permalink / raw)
  To: u-boot

Hi Ladis,

2016-01-25 16:56 GMT+01:00 Ladislav Michl <ladis@linux-mips.org>:
> Hi Enric,
>
> On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
>> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
>> in production is a practice flash the SPL 4 times. OneNAND/NAND
>> devices can have different block sizes and the OMAP ROM boot supports
>> block sizes from 64KB to 512K. For IGEP boards in particular, at least
>> there are boards that have block size of 128K and 256K. What I would
>> meant here is set as default the mtdparts variable to reserve 2M for
>> SPL, just to cover all the cases.
>>
>> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
>
> So far there was no ack or nack to yesterday's proposal making that
> dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
> only mtd needs fixed offset. So I'd like to see this offset calculated as
> 4*block_size, not some "worst case" value...
>
>         ladis

Your proposal looks good to me.

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-01-25 16:56             ` Enric Balletbo Serra
@ 2016-04-13  5:19               ` Heiko Schocher
  2016-04-13 11:39                 ` Enric Balletbo Serra
  0 siblings, 1 reply; 28+ messages in thread
From: Heiko Schocher @ 2016-04-13  5:19 UTC (permalink / raw)
  To: u-boot

Hello Enric,

Am 25.01.2016 um 17:56 schrieb Enric Balletbo Serra:
> Hi Ladis,
>
> 2016-01-25 16:56 GMT+01:00 Ladislav Michl <ladis@linux-mips.org>:
>> Hi Enric,
>>
>> On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
>>> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
>>> in production is a practice flash the SPL 4 times. OneNAND/NAND
>>> devices can have different block sizes and the OMAP ROM boot supports
>>> block sizes from 64KB to 512K. For IGEP boards in particular, at least
>>> there are boards that have block size of 128K and 256K. What I would
>>> meant here is set as default the mtdparts variable to reserve 2M for
>>> SPL, just to cover all the cases.
>>>
>>> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
>>
>> So far there was no ack or nack to yesterday's proposal making that
>> dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
>> only mtd needs fixed offset. So I'd like to see this offset calculated as
>> 4*block_size, not some "worst case" value...
>>
>>          ladis
>
> Your proposal looks good to me.
>

Are there any updates for this patch? The UBI SPL support is pending
for a while ...

I pushed my last (rebased to mainline) state to:

http://git.denx.de/?p=u-boot/u-boot-ubi.git;a=shortlog;h=refs/heads/ubi-spl

without the 2 igep00x0 board patches:

- [U-Boot,PATCHv7,6/7] igep00x0: UBIize
   https://patchwork.ozlabs.org/patch/569214/

- [U-Boot,PATCHv4,7/7] igep00x0: Falcon mode
   https://patchwork.ozlabs.org/patch/569215/

Could you please update your patches for the board support, so we can
push the UBI SPL support to mainline?

Thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-04-13  5:19               ` Heiko Schocher
@ 2016-04-13 11:39                 ` Enric Balletbo Serra
  2016-04-19 10:15                   ` Enric Balletbo Serra
  0 siblings, 1 reply; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-04-13 11:39 UTC (permalink / raw)
  To: u-boot

2016-04-13 7:19 GMT+02:00 Heiko Schocher <hs@denx.de>:
> Hello Enric,
>
>
> Am 25.01.2016 um 17:56 schrieb Enric Balletbo Serra:
>>
>> Hi Ladis,
>>
>> 2016-01-25 16:56 GMT+01:00 Ladislav Michl <ladis@linux-mips.org>:
>>>
>>> Hi Enric,
>>>
>>> On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
>>>>
>>>> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
>>>> in production is a practice flash the SPL 4 times. OneNAND/NAND
>>>> devices can have different block sizes and the OMAP ROM boot supports
>>>> block sizes from 64KB to 512K. For IGEP boards in particular, at least
>>>> there are boards that have block size of 128K and 256K. What I would
>>>> meant here is set as default the mtdparts variable to reserve 2M for
>>>> SPL, just to cover all the cases.
>>>>
>>>> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
>>>
>>>
>>> So far there was no ack or nack to yesterday's proposal making that
>>> dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
>>> only mtd needs fixed offset. So I'd like to see this offset calculated as
>>> 4*block_size, not some "worst case" value...
>>>
>>>          ladis
>>
>>
>> Your proposal looks good to me.
>>
>
> Are there any updates for this patch? The UBI SPL support is pending
> for a while ...
>
> I pushed my last (rebased to mainline) state to:
>
> http://git.denx.de/?p=u-boot/u-boot-ubi.git;a=shortlog;h=refs/heads/ubi-spl
>
> without the 2 igep00x0 board patches:
>
> - [U-Boot,PATCHv7,6/7] igep00x0: UBIize
>   https://patchwork.ozlabs.org/patch/569214/
>
> - [U-Boot,PATCHv4,7/7] igep00x0: Falcon mode
>   https://patchwork.ozlabs.org/patch/569215/
>
> Could you please update your patches for the board support, so we can
> push the UBI SPL support to mainline?
>

Ladis, did you have a chance to look and solve the latest comments I did?

These patch series looks really interesting, like Heiko I would like
to see these merged.

> Thanks!
>
>
> bye,
> Heiko
> --
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCHv7 6/7] igep00x0: UBIize
  2016-04-13 11:39                 ` Enric Balletbo Serra
@ 2016-04-19 10:15                   ` Enric Balletbo Serra
  0 siblings, 0 replies; 28+ messages in thread
From: Enric Balletbo Serra @ 2016-04-19 10:15 UTC (permalink / raw)
  To: u-boot

Hi Ladislav,

2016-04-13 13:39 GMT+02:00 Enric Balletbo Serra <eballetbo@gmail.com>:
> 2016-04-13 7:19 GMT+02:00 Heiko Schocher <hs@denx.de>:
>> Hello Enric,
>>
>>
>> Am 25.01.2016 um 17:56 schrieb Enric Balletbo Serra:
>>>
>>> Hi Ladis,
>>>
>>> 2016-01-25 16:56 GMT+01:00 Ladislav Michl <ladis@linux-mips.org>:
>>>>
>>>> Hi Enric,
>>>>
>>>> On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
>>>>>
>>>>> The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
>>>>> in production is a practice flash the SPL 4 times. OneNAND/NAND
>>>>> devices can have different block sizes and the OMAP ROM boot supports
>>>>> block sizes from 64KB to 512K. For IGEP boards in particular, at least
>>>>> there are boards that have block size of 128K and 256K. What I would
>>>>> meant here is set as default the mtdparts variable to reserve 2M for
>>>>> SPL, just to cover all the cases.
>>>>>
>>>>> mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
>>>>
>>>>
>>>> So far there was no ack or nack to yesterday's proposal making that
>>>> dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
>>>> only mtd needs fixed offset. So I'd like to see this offset calculated as
>>>> 4*block_size, not some "worst case" value...
>>>>
>>>>          ladis
>>>
>>>
>>> Your proposal looks good to me.
>>>
>>
>> Are there any updates for this patch? The UBI SPL support is pending
>> for a while ...
>>
>> I pushed my last (rebased to mainline) state to:
>>
>> http://git.denx.de/?p=u-boot/u-boot-ubi.git;a=shortlog;h=refs/heads/ubi-spl
>>
>> without the 2 igep00x0 board patches:
>>
>> - [U-Boot,PATCHv7,6/7] igep00x0: UBIize
>>   https://patchwork.ozlabs.org/patch/569214/
>>
>> - [U-Boot,PATCHv4,7/7] igep00x0: Falcon mode
>>   https://patchwork.ozlabs.org/patch/569215/
>>
>> Could you please update your patches for the board support, so we can
>> push the UBI SPL support to mainline?
>>
>
> Ladis, did you have a chance to look and solve the latest comments I did?
>

If you don't have enough time maybe I can pickup the patches and
finish the work, if it's ok. I'll have some time this weekend.


> These patch series looks really interesting, like Heiko I would like
> to see these merged.
>
>> Thanks!
>>
>>
>> bye,
>> Heiko
>> --
>> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [RFC] runtime mtdparts_default; was: igep00x0: UBIize
  2016-01-25 15:56           ` Ladislav Michl
  2016-01-25 16:56             ` Enric Balletbo Serra
@ 2016-06-04 20:48             ` Ladislav Michl
  1 sibling, 0 replies; 28+ messages in thread
From: Ladislav Michl @ 2016-06-04 20:48 UTC (permalink / raw)
  To: u-boot

Hi Enric and all,

On Mon, Jan 25, 2016 at 04:56:51PM +0100, Ladislav Michl wrote:
> Hi Enric,
> 
> On Mon, Jan 25, 2016 at 08:26:23AM +0100, Enric Balletbo Serra wrote:
> > The ROM boot on OMAP reads the first 4 blocks searching for the SPL,
> > in production is a practice flash the SPL 4 times. OneNAND/NAND
> > devices can have different block sizes and the OMAP ROM boot supports
> > block sizes from 64KB to 512K. For IGEP boards in particular, at least
> > there are boards that have block size of 128K and 256K. What I would
> > meant here is set as default the mtdparts variable to reserve 2M for
> > SPL, just to cover all the cases.
> > 
> > mtdparts=mtdparts=gpmc-nand.0:2m(SPL),-(UBI)\0
> 
> So far there was no ack or nack to yesterday's proposal making that
> dynamic; Both boot ROM and ubispl code thinks in terms of eraseblocks,
> only mtd needs fixed offset. So I'd like to see this offset calculated as
> 4*block_size, not some "worst case" value...

So to make mtdparts_default runtime configurable, we need to fill it before
relocating env, but after mtd devices get probed, see curent hack in code.

Do we want some generic way of producing board specific mtdpart defaults?
Patch bellow gives some clue how it could work, but implementation is
not nice. Would something like that in principle acceptable (either weak
function or config option)?

Btw, current mtdparts init code is broken for non-relocated env as it assigns
parts name pointer to tmp_parts, so later check for that pointer being null
(env variable not found) does not really check for that variable. I'll send
separate patch for that.

Best regards,
	ladis

PS: patch is based on the top of ubi spl series...

diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
index 759daef..b5b5cc4 100644
--- a/board/isee/igep00x0/igep00x0.c
+++ b/board/isee/igep00x0/igep00x0.c
@@ -18,6 +18,7 @@
 #include <asm/arch/mux.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/mach-types.h>
+#include <linux/mtd/mtd.h>
 #include "igep00x0.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -167,6 +168,23 @@ void set_fdt(void)
 	}
 }
 
+char igep00x0_mtdids[24];
+char igep00x0_mtdparts[48];
+
+void mtdids_generate(void)
+{
+	struct mtd_info *mtd = get_mtd_device(NULL, 0);
+	if (mtd) {
+		const char *linux_name = "omap2-nand";
+		snprintf(igep00x0_mtdids, sizeof(igep00x0_mtdids),
+		         "%s=%s",
+		         mtd->name, linux_name);
+		snprintf(igep00x0_mtdparts, sizeof(igep00x0_mtdparts),
+		         "mtdparts=%s:%dk(SPL),-(UBI)",
+		         linux_name, 4 * mtd->erasesize >> 10);
+	}
+}
+
 /*
  * Routine: misc_init_r
  * Description: Configure board specific parts
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 44b2c3a..d05b8cf 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -110,15 +110,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 /* default values for mtdids and mtdparts variables */
 #if defined(MTDIDS_DEFAULT)
-static const char *const mtdids_default = MTDIDS_DEFAULT;
+static char *mtdids_default = MTDIDS_DEFAULT;
 #else
-static const char *const mtdids_default = NULL;
+static char *mtdids_default = NULL;
 #endif
 
 #if defined(MTDPARTS_DEFAULT)
-static const char *const mtdparts_default = MTDPARTS_DEFAULT;
+static char *mtdparts_default = MTDPARTS_DEFAULT;
 #else
-static const char *const mtdparts_default = NULL;
+static char *mtdparts_default = NULL;
 #endif
 
 /* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
@@ -1524,7 +1524,7 @@ static int spread_partitions(void)
  */
 static int parse_mtdparts(const char *const mtdparts)
 {
-	const char *p = mtdparts;
+	const char *p = NULL;
 	struct mtd_device *dev;
 	int err = 1;
 	char tmp_parts[MTDPARTS_MAXLEN];
@@ -1541,10 +1541,13 @@ static int parse_mtdparts(const char *const mtdparts)
 	if (gd->flags & GD_FLG_ENV_READY) {
 		p = getenv("mtdparts");
 	} else {
-		p = tmp_parts;
-		getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+		if (getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN) != -1)
+			p = tmp_parts;
 	}
 
+	if (!p)
+		p = mtdparts;
+
 	if (strncmp(p, "mtdparts=", 9) != 0) {
 		printf("mtdparts variable doesn't start with 'mtdparts='\n");
 		return err;
@@ -1720,11 +1723,13 @@ int mtdparts_init(void)
 	 * before the env is relocated, then we need to use our own stack
 	 * buffer.  gd->env_buf will be too small.
 	 */
-	if (gd->flags & GD_FLG_ENV_READY) {
+	if (gd->flags & GD_FLG_ENV_READY)
 		parts = getenv("mtdparts");
-	} else {
-		parts = tmp_parts;
-		getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+	else {
+		if (getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN) == -1)
+			parts = NULL;
+		else
+			parts = tmp_parts;
 	}
 	current_partition = getenv("partition");
 
@@ -1758,10 +1763,14 @@ int mtdparts_init(void)
 		return 1;
 	}
 
-	/* do no try to use defaults when mtdparts variable is not defined,
-	 * just check the length */
-	if (!parts)
-		printf("mtdparts variable not set, see 'help mtdparts'\n");
+	/* use defaults when mtdparts variable is not defined, but do not save
+	 * it to environment */
+	if (!parts) {
+		if (mtdparts_default)
+			parts = mtdparts_default;
+		else
+			printf("mtdparts variable not set, see 'help mtdparts'\n");
+	}
 
 	if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
 		printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
diff --git a/common/board_r.c b/common/board_r.c
index d959ad3..b9b2d7f 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -491,8 +491,12 @@ static int should_load_env(void)
 #endif
 }
 
+extern void mtdids_generate(void);
+
 static int initr_env(void)
 {
+	mtdids_generate();
+
 	/* initialize environment */
 	if (should_load_env())
 		env_relocate();
diff --git a/include/configs/omap3_igep00x0.h b/include/configs/omap3_igep00x0.h
index c9157a8..213525d 100644
--- a/include/configs/omap3_igep00x0.h
+++ b/include/configs/omap3_igep00x0.h
@@ -90,10 +90,6 @@
 	"stdout=serial\0" \
 	"stderr=serial\0"
 
-#define ENV_MTD_SETTINGS \
-	"mtdids=nand0=gpmc-nand.0\0" \
-	"mtdparts=mtdparts=gpmc-nand.0:512k(SPL),-(UBI)\0"
-
 #define MEM_LAYOUT_SETTINGS \
 	DEFAULT_LINUX_BOOT_ENV \
 	"scriptaddr=0x87E00000\0" \
@@ -106,7 +102,6 @@
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	ENV_DEVICE_SETTINGS \
-	ENV_MTD_SETTINGS \
 	MEM_LAYOUT_SETTINGS \
 	BOOTENV
 
@@ -151,8 +146,12 @@
 
 #define CONFIG_RBTREE
 #define CONFIG_MTD_PARTITIONS
-#define MTDIDS_DEFAULT			"nand0=gpmc-nand.0"
-#define MTDPARTS_DEFAULT		"mtdparts=gpmc-nand.0:512k(SPL),-(UBI)"
+#ifndef __ASSEMBLY__
+extern char igep00x0_mtdids[];
+extern char igep00x0_mtdparts[];
+#endif
+#define MTDIDS_DEFAULT			igep00x0_mtdids
+#define MTDPARTS_DEFAULT		igep00x0_mtdparts
 
 /* OneNAND boot config */
 #ifdef CONFIG_BOOT_ONENAND

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

end of thread, other threads:[~2016-06-04 20:48 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
2016-01-21  6:04   ` Heiko Schocher
2016-01-17  3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
2016-01-21  6:05   ` Heiko Schocher
2016-01-17  3:13 ` [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17  3:13 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Ladislav Michl
2016-01-21  6:06   ` Heiko Schocher
2016-01-17  3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
2016-01-21  6:07   ` Heiko Schocher
2016-01-17  3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
2016-01-21  6:07   ` Heiko Schocher
2016-01-22 22:35     ` Enric Balletbo Serra
2016-01-24 13:44       ` Ladislav Michl
2016-01-25  6:39       ` Heiko Schocher
2016-01-25  7:26         ` Enric Balletbo Serra
2016-01-25  8:13           ` Heiko Schocher
2016-01-25 15:56           ` Ladislav Michl
2016-01-25 16:56             ` Enric Balletbo Serra
2016-04-13  5:19               ` Heiko Schocher
2016-04-13 11:39                 ` Enric Balletbo Serra
2016-04-19 10:15                   ` Enric Balletbo Serra
2016-06-04 20:48             ` [U-Boot] [RFC] runtime mtdparts_default; was: " Ladislav Michl
2016-01-25 15:13         ` [U-Boot] [PATCHv7 6/7] " Tom Rini
2016-01-25 15:35           ` Heiko Schocher
2016-01-17  3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
2016-01-21  6:08   ` Heiko Schocher
2016-01-22 22:38     ` Enric Balletbo Serra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.