I always forget to compile in a custom embedded script image into iPXE,
and I also don't have full control over my DHCP server in some cases so
I can't set $file.

If you are booting ipxe.lkrn, this _effectively_ lets you do is pass in
a tiny script via the boot command-line.  I use iPXE to compile kernels
on one system and then boot them elsewhere.  The reboot cycles are
*SLOW*, and I like to speed them up.  This should let me do something
like the following in GRUB's menu.lst:

title           iPXE
kernel          /boot/ipxe.lkrn dhcp && kernel http://1.2.3.4/~vmlinuz 
root=UUID=ce4190bb-bdee-48e0-8e47-7e71d167c4ac ro profile=2 single

Previously, I would either have a custom copy of ipxe for each system,
or a custom script on a server, indexed by the system's MAC.  It's
*MUCH* nicer to just keep all of the root= or serial console arguments
all in one file (menu.lst).

This could also be used to anything that the embedded scripts were, like
setting static IPs.

I'm still a bit shaky on whether the assembly here is "right" or whether
it just happens to be cobbled together enough to happen to work.
Michael, thanks for basically writing this for me.  :)  I'm happy to
clean it up some more.

-- Dave
diff --git a/src/arch/i386/prefix/lkrnprefix.S b/src/arch/i386/prefix/lkrnprefix.S
index 3be43ae..fe8a25a 100644
--- a/src/arch/i386/prefix/lkrnprefix.S
+++ b/src/arch/i386/prefix/lkrnprefix.S
@@ -178,6 +178,7 @@ setup_code:
 	 * in the prefix, it doesn't matter: we just have to ensure that
 	 * %cs:0000 is where the start of the image *would* be.
 	 */
+	movl	%es:cmd_line_ptr, %edx 
 	ljmp	$(SYSSEG-(PREFIXSIZE/16)), $run_ipxe
 
 
@@ -196,8 +197,12 @@ run_ipxe:
 
 	/* Set up real-mode stack */
 	movw	%bx, %ss
+	movw	%bx, %ds
 	movw	$_estack16, %sp
 
+	/* cmdline */
+	movl    %edx, cmdline
+
 	/* Jump to .text16 segment */
 	pushw	%ax
 	pushw	$1f
@@ -214,3 +219,8 @@ run_ipxe:
 
 	/* Boot next device */
 	int $0x18
+
+.section ".bss16", "aw", @nobits
+.globl cmdline
+cmdline:
+	.long 0
diff --git a/src/core/main.c b/src/core/main.c
index a1128dd..a998895 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/image.h>
 #include <usr/autoboot.h>
 #include <config/general.h>
+#include <stdlib.h>
 
 #define NORMAL	"\033[0m"
 #define BOLD	"\033[1m"
@@ -32,6 +33,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  * @ret rc		Return status code
  */
+
+
+
+extern uint32_t __data16 ( cmdline );
+#define cmdline __use_data16 ( cmdline )
+
 __asmcall int main ( void ) {
 	struct feature *feature;
 	struct image *image;
@@ -72,6 +79,7 @@ __asmcall int main ( void ) {
 		 * booting fails for any reason, offer a second chance
 		 * to enter the shell for diagnostics.
 		 */
+		run_cmdline();
 		if ( have_images() ) {
 			for_each_image ( image ) {
 				image_exec ( image );
diff --git a/src/include/ipxe/shell.h b/src/include/ipxe/shell.h
index faa32f4..5a2eedd 100644
--- a/src/include/ipxe/shell.h
+++ b/src/include/ipxe/shell.h
@@ -32,5 +32,6 @@ enum shell_stop_state {
 extern void shell_stop ( int stop );
 extern int shell_stopped ( int stop );
 extern int shell ( void );
+extern void run_cmdline ( void );
 
 #endif /* _IPXE_SHELL_H */
_______________________________________________
ipxe-devel mailing list
[email protected]
https://lists.ipxe.org/mailman/listinfo/ipxe-devel

Reply via email to