All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 7/7] pxe: add support for parsing local syslinux files
Date: Wed, 28 Mar 2012 10:51:38 -0500	[thread overview]
Message-ID: <1332949898-6502-8-git-send-email-robherring2@gmail.com> (raw)
In-Reply-To: <1332949898-6502-1-git-send-email-robherring2@gmail.com>

From: Rob Herring <rob.herring@calxeda.com>

Add a new command "sysboot" which parses syslinux menu files and boots
using kernel and initrd specified by menu files. The operation is similar
to "pxe boot" except local files on ext2 or fat filesystem are parsed.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 common/cmd_pxe.c |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 include/common.h |    6 ++
 2 files changed, 137 insertions(+), 8 deletions(-)

diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
index 4ad067a..82b0a8e 100644
--- a/common/cmd_pxe.c
+++ b/common/cmd_pxe.c
@@ -132,6 +132,49 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 	return 1;
 }
 
+static int (*do_getfile)(char *file_path, char *file_addr);
+
+static int do_get_tftp(char *file_path, char *file_addr)
+{
+	char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
+
+	tftp_argv[1] = file_addr;
+	tftp_argv[2] = file_path;
+
+	if (do_tftpb(NULL, 0, 3, tftp_argv))
+		return -ENOENT;
+
+	return 1;
+}
+
+static char *fs_argv[5];
+
+static int do_get_ext2(char *file_path, char *file_addr)
+{
+	fs_argv[0] = "ext2load";
+	fs_argv[3] = file_addr;
+	fs_argv[4] = file_path;
+
+	if (do_ext2load(NULL, 0, 5, fs_argv))
+		return -ENOENT;
+
+	return 1;
+}
+
+static int do_get_fat(char *file_path, char *file_addr)
+{
+	fs_argv[0] = "fatload";
+	fs_argv[3] = file_addr;
+	fs_argv[4] = file_path;
+
+	if (do_fat_fsload(NULL, 0, 5, fs_argv))
+		return -ENOENT;
+
+	return 1;
+}
+
+
+
 /*
  * As in pxelinux, paths to files referenced from files we retrieve are
  * relative to the location of bootfile. get_relfile takes such a path and
@@ -145,7 +188,6 @@ static int get_relfile(char *file_path, void *file_addr)
 	size_t path_len;
 	char relfile[MAX_TFTP_PATH_LEN+1];
 	char addr_buf[10];
-	char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
 	int err;
 
 	err = get_bootfile_path(file_path, relfile, sizeof(relfile));
@@ -170,13 +212,7 @@ static int get_relfile(char *file_path, void *file_addr)
 
 	sprintf(addr_buf, "%p", file_addr);
 
-	tftp_argv[1] = addr_buf;
-	tftp_argv[2] = relfile;
-
-	if (do_tftpb(NULL, 0, 3, tftp_argv))
-		return -ENOENT;
-
-	return 1;
+	return do_getfile(relfile, addr_buf);
 }
 
 /*
@@ -322,6 +358,8 @@ do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	void *pxefile_addr_r;
 	int err;
 
+	do_getfile = do_get_tftp;
+
 	if (argc != 1)
 		return CMD_RET_USAGE;
 
@@ -1331,6 +1369,8 @@ do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct pxe_menu *cfg;
 	char *pxefile_addr_str;
 
+	do_getfile = do_get_tftp;
+
 	if (argc == 1) {
 		pxefile_addr_str = from_env("pxefile_addr_r");
 		if (!pxefile_addr_str)
@@ -1391,3 +1431,86 @@ U_BOOT_CMD(
 	"get - try to retrieve a pxe file using tftp\npxe "
 	"boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
 );
+
+/*
+ * Boots a system using a local disk syslinux/extlinux file
+ *
+ * Returns 0 on success, 1 on error.
+ */
+int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	unsigned long pxefile_addr_r;
+	struct pxe_menu *cfg;
+	char *pxefile_addr_str;
+	char *filename;
+	int prompt = 0;
+
+	if (strstr(argv[1], "-p")) {
+		prompt = 1;
+		argc--;
+		argv++;
+	}
+
+	if (argc < 4)
+		return cmd_usage(cmdtp);
+
+	if (argc < 5) {
+		pxefile_addr_str = from_env("pxefile_addr_r");
+		if (!pxefile_addr_str)
+			return 1;
+	} else {
+		pxefile_addr_str = argv[4];
+	}
+
+	if (argc < 6)
+		filename = getenv("bootfile");
+	else {
+		filename = argv[5];
+		setenv("bootfile", filename);
+	}
+
+	if (strstr(argv[3], "ext2"))
+		do_getfile = do_get_ext2;
+	else if (strstr(argv[3], "fat"))
+		do_getfile = do_get_fat;
+	else {
+		printf("Invalid filesystem: %s\n", argv[3]);
+		return 1;
+	}
+	fs_argv[1] = argv[1];
+	fs_argv[2] = argv[2];
+
+	if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
+		printf("Invalid pxefile address: %s\n", pxefile_addr_str);
+		return 1;
+	}
+
+	if (get_pxe_file(filename, (void *)pxefile_addr_r) < 0) {
+		printf("Error reading config file\n");
+		return 1;
+	}
+
+	cfg = parse_pxefile((char *)(pxefile_addr_r));
+
+	if (cfg == NULL) {
+		printf("Error parsing config file\n");
+		return 1;
+	}
+
+	if (prompt)
+		cfg->prompt = 1;
+
+	handle_pxe_menu(cfg);
+
+	destroy_pxe_menu(cfg);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	sysboot, 7, 1, do_sysboot,
+	"command to get and boot from syslinux files",
+	"[-p] <interface> <dev[:part]> <ext2|fat> [addr] [filename]\n"
+	"    - load and parse syslinux menu file 'filename' from ext2 or fat\n"
+	"      filesystem on 'dev' on 'interface' to address 'addr'"
+);
diff --git a/include/common.h b/include/common.h
index 74d9704..67029b8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -307,6 +307,12 @@ void	doc_probe(unsigned long physadr);
 /* common/cmd_net.c */
 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+/* common/cmd_fat.c */
+int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
+
+/* common/cmd_ext2.c */
+int do_ext2load(cmd_tbl_t *, int, int, char * const []);
+
 /* common/cmd_nvedit.c */
 int	env_init     (void);
 void	env_relocate (void);
-- 
1.7.5.4

  parent reply	other threads:[~2012-03-28 15:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28 15:51 [U-Boot] [PATCH 0/7] PXE parsing fixes and local file support Rob Herring
2012-03-28 15:51 ` [U-Boot] [PATCH 1/7] menu: only timeout when menu is displayed Rob Herring
2012-06-21 20:34   ` Wolfgang Denk
2012-03-28 15:51 ` [U-Boot] [PATCH 2/7] pxe: support include files at top-level Rob Herring
2012-05-25 20:43   ` [U-Boot] [PATCH v2] " Rob Herring
2012-06-21 20:34     ` Wolfgang Denk
2012-03-28 15:51 ` [U-Boot] [PATCH 3/7] pxe: add support for label menu text Rob Herring
2012-06-21 20:34   ` Wolfgang Denk
2012-03-28 15:51 ` [U-Boot] [PATCH 4/7] pxe: support linux entries for labels Rob Herring
2012-06-21 20:35   ` Wolfgang Denk
2012-03-28 15:51 ` [U-Boot] [PATCH 5/7] pxe: support absolute paths Rob Herring
2012-06-21 20:35   ` Wolfgang Denk
2012-03-28 15:51 ` [U-Boot] [PATCH 6/7] pxe: parse initrd file from append string Rob Herring
2012-06-21 20:35   ` Wolfgang Denk
2012-03-28 15:51 ` Rob Herring [this message]
2012-05-23 22:11   ` [U-Boot] [PATCH 7/7] pxe: add support for parsing local syslinux files Joe Hershberger
2012-05-23 22:57     ` Rob Herring
2012-05-23 23:02       ` Joe Hershberger
2012-05-25 18:56         ` Joe Hershberger
2012-05-25 20:47   ` [U-Boot] [PATCH v2] " Rob Herring
2012-05-25 21:44     ` Joe Hershberger
2012-06-21 20:36     ` Wolfgang Denk

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=1332949898-6502-8-git-send-email-robherring2@gmail.com \
    --to=robherring2@gmail.com \
    --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.