mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] OMAP: Boot from UBI
@ 2013-06-21  9:53 Christoph Fritz
  2013-06-21  9:55 ` [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox " Christoph Fritz
  2013-06-21  9:55 ` [PATCH 2/2] ARM OMAP: add support for loading Environment " Christoph Fritz
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Fritz @ 2013-06-21  9:53 UTC (permalink / raw)
  To: barebox

This small set of patches adds boot from UBI support on OMAP SoCs:
MLO attaches UBI, loads barebox from within a static volume and
goes up from there.
The benefit: NAND wearleveling is also done for barebox.

A NAND layout can now look like this:

       +------------+-->0x00000000-> xload start   (MLO copy on 1st block)
       |            |
       |            |-->0x0001FFFF-> xload end
       |            |-->0x00020000-> xload1 start   (MLO backup copy on 2rd)
       |            |
       |            |-->0x0003FFFF-> xload1 end
       |            |-->0x00040000-> xload2 start   (MLO backup copy on 3rd)
       |            |
       |            |-->0x0005FFFF-> xload2 end
       |            |-->0x00060000-> xload3 start   (MLO backup copy on 4rd)
       |            |
       |            |-->0x0007FFFF-> xload3 end
       |            |-->0x00080000-> ubi start
       |            |
       |            |
       |            |     UBI-Volumes:
       |            |           - barebox_0 [1M]
       |            |           - bareboxenv_0 [512k]
       |            |           - kernel_0 [6M]
       |            |           - oftree_0 [512k]
       |            |           - bmp_0 [2M]
       |            |           - root [-]
       |            |
       |            |
       +------------+-->0x0FFFFFFF-> root end

Next step (ToDo) is to decrease boot-time because it takes nearly
six secounds to get to a fully featured barebox-prompt. Possible
solutions are:

 - use UBI Fastmap to decrease scan time
 - only scan UBI once and transfer gained data to next boot stage:
   MLO (scans UBI) -> Barebox (gets data) -> Kernel (gets data)

---
Christoph Fritz (2):
  ARM OMAP: MLO: add support for loading Barebox from UBI
  ARM OMAP: add support for loading Environment from UBI

 arch/arm/mach-omap/Kconfig |   44 +++++++++++++++++++++++++
 arch/arm/mach-omap/xload.c |   76 ++++++++++++++++++++++++++++++++++++++++++--
 common/Kconfig             |   34 ++++++++++++++++++++
 common/startup.c           |   17 ++++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)

-- 
1.7.10.4



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

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

* [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox from UBI
  2013-06-21  9:53 [PATCH 0/2] OMAP: Boot from UBI Christoph Fritz
@ 2013-06-21  9:55 ` Christoph Fritz
  2013-06-25  4:22   ` Sascha Hauer
  2013-06-21  9:55 ` [PATCH 2/2] ARM OMAP: add support for loading Environment " Christoph Fritz
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Fritz @ 2013-06-21  9:55 UTC (permalink / raw)
  To: barebox

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

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

* [PATCH 2/2] ARM OMAP: add support for loading Environment from UBI
  2013-06-21  9:53 [PATCH 0/2] OMAP: Boot from UBI Christoph Fritz
  2013-06-21  9:55 ` [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox " Christoph Fritz
@ 2013-06-21  9:55 ` Christoph Fritz
  2013-06-25  5:26   ` Sascha Hauer
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Fritz @ 2013-06-21  9:55 UTC (permalink / raw)
  To: barebox

This patch adds support to load environment from a static
UBI volume.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 common/Kconfig   |   34 ++++++++++++++++++++++++++++++++++
 common/startup.c |   17 +++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index d36ed13..058eb21 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -103,6 +103,40 @@ config MEMINFO
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
+config ENVIRONMENT_IN_UBI
+	bool "Load Environment from an UBI static volume"
+	depends on UBI
+	depends on ENV_HANDLING
+	help
+	  Say Y here if you would like to attach UBI and load
+	  the environment from an UBI volume.
+
+if ENVIRONMENT_IN_UBI
+
+menu "Configure Loading Environment from UBI"
+
+config ENV_IN_UBI_PARTITION
+	string
+	default "/dev/root"
+	prompt "Filepath of mtd partition holding UBI volumes"
+	help
+	  Filepath of mtd partition holding UBI static volume with Barebox
+	  environment inside.  This value depends on your board partition
+	  layout. Default string value is "/dev/root".
+
+config ENV_IN_UBI_VOLNAME
+	string
+	default "/dev/ubi0.bareboxenv_0"
+	prompt "Filepath of UBI static volume holding environment"
+	help
+	  Filepath of UBI static volume holding Barebox environment inside the
+	  partition. This string value depends on your UBI volume name
+	  configuration scheme. Default string is "/dev/ubi0.bareboxenv_0".
+
+endmenu
+
+endif
+
 menu "memory layout"
 
 source "pbl/Kconfig"
diff --git a/common/startup.c b/common/startup.c
index ff00ca7..01c0e1d 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -117,6 +117,23 @@ void __noreturn start_barebox(void)
 	if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
 		int ret;
 
+		if (IS_ENABLED(CONFIG_ENVIRONMENT_IN_UBI)) {
+#ifdef CONFIG_ENVIRONMENT_IN_UBI
+			char s[PATH_MAX + 32];
+			sprintf(s, "%s%s ", "ubiattach ",
+				CONFIG_ENV_IN_UBI_PARTITION);
+			ret = run_command(s, 0);
+			if (ret) {
+				sprintf(s, "%s%s ", "unable to ubiattach ",
+					CONFIG_ENV_IN_UBI_PARTITION);
+				pr_err(s);
+			} else {
+				default_environment_path =
+					CONFIG_ENV_IN_UBI_VOLNAME;
+			}
+#endif
+		}
+
 		ret = envfs_load(default_environment_path, "/env", 0);
 
 		if (ret && IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT)) {
-- 
1.7.10.4



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

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

* Re: [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox from UBI
  2013-06-21  9:55 ` [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox " Christoph Fritz
@ 2013-06-25  4:22   ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-25  4:22 UTC (permalink / raw)
  To: Christoph Fritz; +Cc: barebox

Hi Christoph,

On Fri, Jun 21, 2013 at 11:55:21AM +0200, Christoph Fritz wrote:
> 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(-)
> 
> +static void *omap_xload_boot_ubi_nand(void)
> +{
> +	void *to = NULL;
> +#ifdef CONFIG_BB_IN_UBI

You shouldn't need this ifdef

> +	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");

I don't like putting these in kconfig. Ideally these should be passed by
the board code.

> +
> +	cdev = cdev_open(CONFIG_BB_IN_UBI_VOLNAME, O_RDONLY);
> +	if (!cdev) {
> +		printf("cdev_open failed\n");

Such error messages should always print the return value if possible.

> +		return NULL;
> +	}
> +
> +	if (cdev_read(cdev, to, size, 0, 0) < 0) {
> +		printf("cdev_read failed\n");

ditto.

> +		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();

You could check for filetype_ubi here instead of making this a
compiletime decision.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

* Re: [PATCH 2/2] ARM OMAP: add support for loading Environment from UBI
  2013-06-21  9:55 ` [PATCH 2/2] ARM OMAP: add support for loading Environment " Christoph Fritz
@ 2013-06-25  5:26   ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-25  5:26 UTC (permalink / raw)
  To: Christoph Fritz; +Cc: barebox

On Fri, Jun 21, 2013 at 11:55:56AM +0200, Christoph Fritz wrote:
> This patch adds support to load environment from a static
> UBI volume.
> 
>  	if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
>  		int ret;
>  
> +		if (IS_ENABLED(CONFIG_ENVIRONMENT_IN_UBI)) {
> +#ifdef CONFIG_ENVIRONMENT_IN_UBI
> +			char s[PATH_MAX + 32];
> +			sprintf(s, "%s%s ", "ubiattach ",
> +				CONFIG_ENV_IN_UBI_PARTITION);
> +			ret = run_command(s, 0);
> +			if (ret) {
> +				sprintf(s, "%s%s ", "unable to ubiattach ",
> +					CONFIG_ENV_IN_UBI_PARTITION);
> +				pr_err(s);
> +			} else {
> +				default_environment_path =
> +					CONFIG_ENV_IN_UBI_VOLNAME;
> +			}
> +#endif

You shouldn't need the ifdef here aswell. Also this should be a helper
function called from board code rather than something in generic code.
You can also hardcode the volume name in board code, I don't think this
needs to be configurable.

Configurability of stuff like environment position always has a problem.
If it wasn't you who compiled a particular binary (or it even was you
and you can't remember), you don't know how the binary behaves. For
everything you hardcode the version printout in barebox will exactly
tell you the behaviour.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2013-06-25  5:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-21  9:53 [PATCH 0/2] OMAP: Boot from UBI Christoph Fritz
2013-06-21  9:55 ` [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox " Christoph Fritz
2013-06-25  4:22   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox