All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv2 3/3] igep00x0: UBIize
Date: Mon, 4 Jan 2016 16:57:52 +0100	[thread overview]
Message-ID: <20160104155752.GD4376@localhost.localdomain> (raw)
In-Reply-To: <20160104155242.GA4376@localhost.localdomain>

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@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@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

  parent reply	other threads:[~2016-01-04 15:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-04 15:52 [U-Boot] [PATCHv2 0/3] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-04 15:54 ` [U-Boot] [PATCHv2 1/3] nand_spl_simple: Add a simple flash read function Ladislav Michl
2016-01-04 17:19   ` Marek Vasut
2016-01-04 17:58     ` Ladislav Michl
2016-01-04 18:38       ` Marek Vasut
2016-01-04 18:23   ` Scott Wood
2016-01-04 18:38     ` Ladislav Michl
2016-01-04 18:44       ` Scott Wood
2016-01-04 21:17       ` Ladislav Michl
2016-01-04 21:45         ` Scott Wood
2016-01-04 22:40           ` Marek Vasut
2016-01-04 22:42             ` Scott Wood
2016-01-04 22:52               ` Marek Vasut
2016-01-04 15:56 ` [U-Boot] [PATCHv2 2/3] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-06 16:52   ` Ladislav Michl
2016-01-06 17:09     ` Marek Vasut
2016-01-04 15:57 ` Ladislav Michl [this message]
2016-01-07 10:47 ` [U-Boot] [PATCHv2 0/3] " Heiko Schocher
2016-01-10 14:00   ` Ladislav Michl
2016-01-11  5:50     ` Heiko Schocher

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20160104155752.GD4376@localhost.localdomain \
    --to=ladis@linux-mips.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.