mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Christoph Fritz <chf.fritz@googlemail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox from UBI
Date: Fri, 21 Jun 2013 11:55:21 +0200	[thread overview]
Message-ID: <1371808521.3949.14.camel@mars> (raw)
In-Reply-To: <1371808410.3949.13.camel@mars>

This patch adds support to OMAP MLO to load a secound
stage bootloader from a static UBI volume.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 arch/arm/mach-omap/Kconfig |   44 +++++++++++++++++++++++++
 arch/arm/mach-omap/xload.c |   76 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 236a165..e08524e 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -213,6 +213,50 @@ choice
 
 endchoice
 
+config BB_IN_UBI
+	bool "Load Barebox from an UBI static volume"
+	depends on ARCH_OMAP3
+	depends on UBI
+	depends on OMAP_BUILD_IFT
+	help
+	  Say Y here if you would like to make the MLO load barebox
+	  from an UBI volume if bootsource is NAND.
+
+if BB_IN_UBI
+
+menu "Configure Loading Barebox from UBI"
+
+config BB_IN_UBI_PARTITION_START
+	hex
+	default 0x00080000
+	prompt "Offset size where partition begins"
+	help
+	  Start of mtd partition which holdes UBI volumes for barebox and
+	  barebox-environment. This value depends on your board partition
+	  layout. Default offset is 512k.
+
+config BB_IN_UBI_PARTITION_SIZE
+	hex
+	default 0xff80000
+	prompt "Length of partition"
+	help
+	  Size of mtd partition which holdes UBI volumes for barebox and
+	  barebox-environment. This value depends on your board partition
+	  layout. Default length is set to 255.5MB.
+
+config BB_IN_UBI_VOLNAME
+	string
+	default "ubi0.barebox_0"
+	prompt "Name of UBI static volume holding Barebox"
+	help
+	  Name of UBI static volume holding Barebox inside the mtd
+	  partition. This string value depends on your UBI volume name
+	  configuration scheme. Default string is "ubi0.barebox_0".
+
+endmenu
+
+endif
+
 endif
 
 config MACH_OMAP_ADVANCED_MUX
diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
index 3cce3f2..6c51c55 100644
--- a/arch/arm/mach-omap/xload.c
+++ b/arch/arm/mach-omap/xload.c
@@ -9,6 +9,10 @@
 #include <fcntl.h>
 #include <sizes.h>
 #include <filetype.h>
+#include <mtd/ubi-user.h>
+#include <mtd/ubi-media.h>
+#include <linux/mtd/mtd-abi.h>
+#include <asm-generic/ioctl.h>
 
 static void *read_image_head(const char *name)
 {
@@ -82,6 +86,69 @@ static void *omap_xload_boot_nand(int offset)
 	return to;
 }
 
+static void *omap_xload_boot_ubi_nand(void)
+{
+	void *to = NULL;
+#ifdef CONFIG_BB_IN_UBI
+	void *header;
+	int ret;
+	struct cdev *cdev;
+	struct mtd_info_user user;
+	int size;
+
+	devfs_add_partition("nand0", CONFIG_BB_IN_UBI_PARTITION_START,
+		CONFIG_BB_IN_UBI_PARTITION_SIZE, DEVFS_PARTITION_FIXED, "u");
+	dev_add_bb_dev("u", "bbu");
+
+	cdev = cdev_open("u", O_RDONLY);
+	if (!cdev) {
+		printf("cdev_open failed\n");
+		return NULL;
+	}
+
+	ret = cdev_ioctl(cdev, MEMGETINFO, &user);
+	if (!ret)
+		ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+	else {
+		printf("failed to attach: %s\n", strerror(-ret));
+		cdev_close(cdev);
+		return NULL;
+	}
+
+	cdev_close(cdev);
+
+	header = read_image_head(CONFIG_BB_IN_UBI_VOLNAME);
+	if (header == NULL) {
+		printf("failed to read image head\n");
+		return NULL;
+	}
+
+	size = get_image_size(header);
+	if (!size) {
+		printf("failed to get image size\n");
+		return NULL;
+	}
+
+	to = xmalloc(size);
+
+	cdev = cdev_open(CONFIG_BB_IN_UBI_VOLNAME, O_RDONLY);
+	if (!cdev) {
+		printf("cdev_open failed\n");
+		return NULL;
+	}
+
+	if (cdev_read(cdev, to, size, 0, 0) < 0) {
+		printf("cdev_read failed\n");
+		cdev_close(cdev);
+		return NULL;
+        }
+
+	cdev_close(cdev);
+
+#endif
+	return to;
+}
+
 static void *omap_xload_boot_mmc(void)
 {
 	int ret;
@@ -180,8 +247,13 @@ static __noreturn int omap_xload(void)
 			printf("booting from USB not enabled\n");
 		}
 	case BOOTSOURCE_NAND:
-		printf("booting from NAND\n");
-		func = omap_xload_boot_nand(SZ_128K);
+		if (IS_ENABLED(CONFIG_BB_IN_UBI)) {
+			printf("booting from UBI static volume\n");
+			func = omap_xload_boot_ubi_nand();
+		} else {
+			printf("booting from NAND\n");
+			func = omap_xload_boot_nand(SZ_128K);
+		}
 		break;
 	case BOOTSOURCE_SPI:
 		printf("booting from SPI\n");
-- 
1.7.10.4



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

  reply	other threads:[~2013-06-21  9:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-21  9:53 [PATCH 0/2] OMAP: Boot " Christoph Fritz
2013-06-21  9:55 ` Christoph Fritz [this message]
2013-06-25  4:22   ` [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox " Sascha Hauer
2013-06-21  9:55 ` [PATCH 2/2] ARM OMAP: add support for loading Environment " Christoph Fritz
2013-06-25  5:26   ` Sascha Hauer

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1371808521.3949.14.camel@mars \
    --to=chf.fritz@googlemail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

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

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