mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] beagle: add xloader boot menu support
Date: Sat, 14 Apr 2012 18:17:41 +0200	[thread overview]
Message-ID: <1334420262-4823-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20120414161509.GC30672@game.jcrosoft.org>

This will allow to choice where we boot from.
As example if the nand boot is broken we can choose to boot from mmc.
The autoboot is set to 1s as most of the time you expect to boot from the
default boot.

As the xloader need to be really small to fit in the sram the boot menu allow
to add user interaction.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-omap/xload.c |  115 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
index 59f75e2..90bf05f 100644
--- a/arch/arm/mach-omap/xload.c
+++ b/arch/arm/mach-omap/xload.c
@@ -3,10 +3,12 @@
 #include <nand.h>
 #include <driver.h>
 #include <linux/mtd/mtd.h>
+#include <linux/err.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <mach/xload.h>
 #include <sizes.h>
+#include <menu.h>
 
 void *omap_xload_boot_nand(int offset, int size)
 {
@@ -63,15 +65,11 @@ enum omap_boot_src omap_bootsrc(void)
 #endif
 }
 
-/*
- * Replaces the default shell in xload configuration
- */
-int run_shell(void)
+static void xload_boot(enum omap_boot_src mode)
 {
 	int (*func)(void) = NULL;
 
-	switch (omap_bootsrc())
-	{
+	switch (mode) {
 	case OMAP_BOOTSRC_MMC1:
 		printf("booting from MMC1\n");
 		func = omap_xload_boot_mmc();
@@ -94,3 +92,108 @@ int run_shell(void)
 
 	while (1);
 }
+
+#ifdef CONFIG_MENU
+struct action_entry {
+	enum omap_boot_src mode;
+	struct menu_entry entry;
+};
+
+static void menu_action_command(struct menu *m, struct menu_entry *me)
+{
+	struct action_entry *e = container_of(me, struct action_entry, entry);
+
+	xload_boot(e->mode);
+}
+
+static void menu_action_free(struct menu_entry *me)
+{
+	struct action_entry *e = container_of(me, struct action_entry, entry);
+
+	free(e->entry.display);
+
+	free(e);
+}
+
+static struct menu_entry *menu_add_boot_entry(struct menu *m, const char *display,
+					      enum omap_boot_src mode)
+{
+	struct action_entry *e = calloc(1, sizeof(*e));
+	int ret;
+
+	if (!e)
+		return NULL;
+
+	e->mode = mode;
+	e->entry.action = menu_action_command;
+	e->entry.free = menu_action_free;
+	e->entry.type = 0;
+	e->entry.display = strdup(display);
+
+	ret = menu_add_entry(m, &e->entry);
+	if (ret)
+		goto err_free;
+
+	return &e->entry;
+err_free:
+	menu_action_free(&e->entry);
+	return NULL;
+}
+
+int run_shell(void)
+{
+	struct menu *m;
+	struct menu_entry *mmc1, *nand;
+	int ret = -ENOMEM;
+	enum omap_boot_src mode = omap3_bootsrc();
+
+	m = menu_alloc();
+
+	if (!m)
+		goto boot;
+
+	m->name = strdup("boot");
+
+	if (!m->name)
+		goto boot;
+
+	ret = menu_add(m);
+	if (ret)
+		goto boot;
+
+	mmc1 = menu_add_boot_entry(m, "Boot from mmc1", OMAP_BOOTSRC_MMC1);
+	if (!mmc1)
+		goto boot;
+
+	nand = menu_add_boot_entry(m, "Boot from nand", OMAP_BOOTSRC_NAND);
+	if (!nand)
+		goto boot;
+
+	switch (mode)
+	{
+	case OMAP_BOOTSRC_MMC1:
+		menu_set_selected_entry(m, mmc1);
+		break;
+	case OMAP_BOOTSRC_UNKNOWN:
+	case OMAP_BOOTSRC_NAND:
+		menu_set_selected_entry(m, nand);
+		break;
+	}
+
+	menu_set_auto_select(m, 1);
+
+	menu_show(m);
+
+boot:
+	xload_boot(mode);
+
+	return 0;
+}
+#else
+int run_shell(void)
+{
+	xload_boot(omap_bootsrc());
+
+	return 0;
+}
+#endif
-- 
1.7.9.1


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

  parent reply	other threads:[~2012-04-14 16:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-14 16:15 [PATCH 0/3] Omap xloader boot menu support and beagle env Jean-Christophe PLAGNIOL-VILLARD
2012-04-14 16:17 ` [PATCH 1/3] beagle: add default env support Jean-Christophe PLAGNIOL-VILLARD
2012-04-14 17:52   ` Eric Bénard
2012-04-15  1:29     ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-14 16:17 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-04-14 16:17 ` [PATCH 3/3] beagle/xload: update defconfig Jean-Christophe PLAGNIOL-VILLARD
2012-04-14 20:16 ` [PATCH 0/3] Omap xloader boot menu support and beagle env Sascha Hauer
2012-04-15  1:39   ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-18 10:08 ` 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=1334420262-4823-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.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