[U-Boot] [PATCHv2 3/3] igep00x0: UBIize
Ladislav Michl
ladis at linux-mips.org
Mon Jan 4 16:57:52 CET 2016
This patch converts IGEP board to use UBI volumes for environment,
u-boot, kernel... With exception of first four sectors read by SoC
boot ROM whole NAND is UBI managed. Code is too big, so I dropped
CONFIG_SPL_EXT_SUPPORT to make it fit. It is meant more likely as a test
of Thomas' patch, so more people can play with that. Thanks to Marek
Vasut for pointing me to Thomas' work and arguing so well towards UBI
that I had no other choice than giving it a try.
Signed-off-by: Ladislav Michl <ladis at linux-mips.org>
---
board/isee/igep00x0/igep00x0.c | 48 +++++++++++++++++++++++++++++
common/spl/Makefile | 5 ++-
common/spl/spl.c | 13 ++++++++
common/spl/spl_ubi.c | 36 ++++++++++++++++++++++
include/configs/omap3_igep00x0.h | 64 ++++++++++++++++++---------------------
include/configs/ti_armv7_common.h | 1 -
include/spl.h | 4 +++
7 files changed, 134 insertions(+), 37 deletions(-)
create mode 100644 common/spl/spl_ubi.c
diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
index e2fce50..006fae6 100644
--- a/board/isee/igep00x0/igep00x0.c
+++ b/board/isee/igep00x0/igep00x0.c
@@ -10,6 +10,9 @@
#include <ns16550.h>
#include <twl4030.h>
#include <netdev.h>
+#include <nand.h>
+#include <ubispl.h>
+#include <spl.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/mem.h>
@@ -212,3 +215,48 @@ 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
+
+#ifdef CONFIG_SPL_BUILD
+int spl_board_ubi_load_image(u32 boot_device)
+{
+ int ret;
+ struct image_header *header;
+ struct ubispl_info info;
+ struct ubispl_load volumes[4];
+
+ info.ubi = (struct ubi_scan_info *)
+ (CONFIG_SYS_SPL_MALLOC_START + CONFIG_SYS_SPL_MALLOC_SIZE);
+ info.fastmap = 1;
+ info.read = nand_spl_read_flash;
+
+ info.peb_offset = 4;
+ info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
+ info.vid_offset = 512;
+ info.leb_start = 2048;
+ info.peb_count = 4096 - info.peb_offset;
+
+ header = (struct image_header *)
+ (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
+ memset(volumes, 0, sizeof(volumes));
+ volumes[0].name = "loader";
+ volumes[0].vol_id = 0;
+ volumes[0].load_addr = (void *)header;
+
+ ret = ubispl_load_volumes(&info, volumes, 1);
+ if (!ret)
+ spl_parse_image_header(header);
+
+ return ret;
+}
+#endif
diff --git a/common/spl/Makefile b/common/spl/Makefile
index 10a4589..e4535c4 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -10,10 +10,13 @@
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_NOR_SUPPORT) += spl_nor.o
obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
+endif
+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 6e6dee7..048a325 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -286,6 +286,18 @@ static int spl_load_image(u32 boot_device)
case BOOT_DEVICE_MMC2_2:
return spl_mmc_load_image(boot_device);
#endif
+#ifdef CONFIG_SPL_UBI
+#ifdef CONFIG_SPL_NAND_SUPPORT
+ case BOOT_DEVICE_NAND:
+#endif
+#ifdef CONFIG_SPL_ONENAND_SUPPORT
+ case BOOT_DEVICE_ONENAND:
+#endif
+#ifdef CONFIG_SPL_NOR_SUPPORT
+ case BOOT_DEVICE_NOR:
+#endif
+ return spl_ubi_load_image(boot_device);
+#else
#ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND:
return spl_nand_load_image();
@@ -298,6 +310,7 @@ static int spl_load_image(u32 boot_device)
case BOOT_DEVICE_NOR:
return spl_nor_load_image();
#endif
+#endif /* CONFIG_SPL_UBI */
#ifdef CONFIG_SPL_YMODEM_SUPPORT
case BOOT_DEVICE_UART:
return spl_ymodem_load_image();
diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c
new file mode 100644
index 0000000..a292841
--- /dev/null
+++ b/common/spl/spl_ubi.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016
+ * Ladislav Michl <ladis at linux-mips.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include <common.h>
+#include <config.h>
+#include <spl.h>
+#include <asm/io.h>
+#include <nand.h>
+
+__weak int spl_board_ubi_load_image(u32 boot_device)
+{
+ return -EINVAL;
+}
+
+int spl_ubi_load_image(u32 boot_device)
+{
+ int ret;
+
+#ifdef CONFIG_SPL_NAND_SUPPORT
+ if (boot_device == BOOT_DEVICE_NAND)
+ nand_init();
+#endif
+
+ ret = spl_board_ubi_load_image(boot_device);
+
+#ifdef CONFIG_SPL_NAND_SUPPORT
+ if (boot_device == BOOT_DEVICE_NAND)
+ nand_deselect();
+#endif
+
+ return ret;
+}
+
diff --git a/include/configs/omap3_igep00x0.h b/include/configs/omap3_igep00x0.h
index 5da6cfd..451e511 100644
--- a/include/configs/omap3_igep00x0.h
+++ b/include/configs/omap3_igep00x0.h
@@ -77,6 +77,7 @@
#endif
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_PING
+#define CONFIG_CMD_UBI
#ifndef CONFIG_SPL_BUILD
@@ -86,6 +87,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 +101,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 +118,37 @@
#define CONFIG_SMC911X_BASE 0x2C000000
#endif /* (CONFIG_CMD_NET) */
+/*
+ * FLASH and environment organization
+ */
+#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_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
+#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)
-
#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 +168,6 @@
#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
#endif /* __IGEP00X0_H */
diff --git a/include/configs/ti_armv7_common.h b/include/configs/ti_armv7_common.h
index 2087eb1..45bdd75 100644
--- a/include/configs/ti_armv7_common.h
+++ b/include/configs/ti_armv7_common.h
@@ -232,7 +232,6 @@
#define CONFIG_SPL_LIBDISK_SUPPORT
#define CONFIG_SPL_MMC_SUPPORT
#define CONFIG_SPL_FAT_SUPPORT
-#define CONFIG_SPL_EXT_SUPPORT
#endif
#define CONFIG_SYS_THUMB_BUILD
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
More information about the U-Boot
mailing list