wok-next rev 1121

gpxe: add cmdline support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jul 21 14:22:01 2008 +0000 (2008-07-21)
parents 3c46706775f3
children a08b2e53cf96
files gpxe/receipt gpxe/stuff/cmdline.u
line diff
     1.1 --- a/gpxe/receipt	Sun Jul 20 23:51:51 2008 +0200
     1.2 +++ b/gpxe/receipt	Mon Jul 21 14:22:01 2008 +0000
     1.3 @@ -13,7 +13,8 @@
     1.4  compile_rules()
     1.5  {
     1.6  	cd $src/src
     1.7 -	for i in prefix.u default_boot.u; do
     1.8 +	for i in prefix.u default_boot.u cmdline.u; do
     1.9 +		echo "Apply $i..."
    1.10  		patch -p2 < ../../stuff/$i || return 1
    1.11  	done
    1.12  	make bin/gpxe.lkrn bin/undionly.kpxe
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gpxe/stuff/cmdline.u	Mon Jul 21 14:22:01 2008 +0000
     2.3 @@ -0,0 +1,183 @@
     2.4 +--- gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
     2.5 ++++ gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
     2.6 +@@ -77,7 +77,9 @@
     2.7 + 	popw	%ax
     2.8 + 	addw	$(0x100/16), %ax	/* Adjust cs */
     2.9 + 	pushw	%ax
    2.10 +-	jmp	go_setup_code
    2.11 ++	pushw	$run_etherboot_floppy
    2.12 ++	/* Calculated lcall to _start with %cs:0000 = image start */
    2.13 ++	lret
    2.14 + 
    2.15 + bootsector:
    2.16 + 	jmp	$BOOTSEG, $go		/* reload cs:ip to match relocation addr */
    2.17 +@@ -197,7 +199,7 @@
    2.18 + 	 */
    2.19 + 
    2.20 + 	/* Jump to loaded copy */
    2.21 +-	ljmp	$SYSSEG, $run_etherboot2
    2.22 ++	ljmp	$SYSSEG, $run_etherboot_floppy
    2.23 + 
    2.24 + endseg:	.word SYSSEG + _load_size_pgh
    2.25 + 	.section ".zinfo.fixup", "a"	/* Compressor fixup information */
    2.26 +@@ -436,8 +438,7 @@
    2.27 + 	 * we just have to ensure that %cs:0000 is where the start of
    2.28 + 	 * the Etherboot image *would* be.
    2.29 + 	 */
    2.30 +-go_setup_code: 
    2.31 +-	pushw	$run_etherboot
    2.32 ++	pushw	$run_etherboot_zImage
    2.33 + 	/* Calculated lcall to _start with %cs:0000 = image start */
    2.34 + 	lret
    2.35 + 
    2.36 +@@ -448,7 +449,23 @@
    2.37 + /*
    2.38 + 	We're now at the beginning of the kernel proper.
    2.39 +  */
    2.40 +-run_etherboot2:
    2.41 ++run_etherboot_zImage:
    2.42 ++	mov	$0x0020, %si
    2.43 ++	lodsw
    2.44 ++	cmp	$0xA33F, %ax
    2.45 ++	jne	run_etherboot
    2.46 ++	lodsw
    2.47 ++	xchg	%ax, %si
    2.48 ++	push	%ds
    2.49 ++	pop	%es
    2.50 ++	movw	$boot_url, %di
    2.51 ++copy_cmdline:
    2.52 ++	lodsb
    2.53 ++	stosb
    2.54 ++	or	%al, %al
    2.55 ++	jne	copy_cmdline
    2.56 ++	jmp	run_etherboot
    2.57 ++run_etherboot_floppy:
    2.58 + 	push	%cs
    2.59 + 	pop	%ds
    2.60 + run_etherboot:
    2.61 +
    2.62 +--- gpxe-0.9.3/src/net/udp/dns.c
    2.63 ++++ gpxe-0.9.3/src/net/udp/dns.c
    2.64 +@@ -506,6 +506,19 @@
    2.65 + 	.resolv = dns_resolv,
    2.66 + };
    2.67 + 
    2.68 ++int apply_nameserver(struct in_addr sin_addr)
    2.69 ++{
    2.70 ++	struct sockaddr_in *sin_nameserver;
    2.71 ++
    2.72 ++	sin_nameserver = ( struct sockaddr_in * ) &nameserver;
    2.73 ++	sin_nameserver->sin_family = AF_INET;
    2.74 ++	sin_nameserver->sin_addr = sin_addr;
    2.75 ++	DBG ( "DNS using nameserver %s\n",
    2.76 ++	      inet_ntoa ( sin_addr ) );
    2.77 ++
    2.78 ++	return 0;
    2.79 ++}
    2.80 ++
    2.81 + /**
    2.82 +  * Apply DHCP nameserver option
    2.83 +  *
    2.84 +@@ -514,16 +527,10 @@
    2.85 +  */
    2.86 + static int apply_dhcp_nameserver ( unsigned int tag __unused,
    2.87 + 				   struct dhcp_option *option ) {
    2.88 +-	struct sockaddr_in *sin_nameserver;
    2.89 +-
    2.90 +-	sin_nameserver = ( struct sockaddr_in * ) &nameserver;
    2.91 +-	sin_nameserver->sin_family = AF_INET;
    2.92 +-	dhcp_ipv4_option ( option, &sin_nameserver->sin_addr );
    2.93 +-
    2.94 +-	DBG ( "DNS using nameserver %s\n",
    2.95 +-	      inet_ntoa ( sin_nameserver->sin_addr ) );
    2.96 ++	struct in_addr sin_addr;
    2.97 + 
    2.98 +-	return 0;
    2.99 ++	dhcp_ipv4_option ( option, &sin_addr );
   2.100 ++	return apply_nameserver(sin_addr);
   2.101 + }
   2.102 + 
   2.103 + /** DHCP nameserver applicator */
   2.104 +
   2.105 +--- gpxe-0.9.3/src/usr/autoboot.c
   2.106 ++++ gpxe-0.9.3/src/usr/autoboot.c
   2.107 +@@ -23,6 +23,7 @@
   2.108 + #include <gpxe/dhcp.h>
   2.109 + #include <gpxe/image.h>
   2.110 + #include <gpxe/embedded.h>
   2.111 ++#include <gpxe/ip.h>
   2.112 + #include <usr/ifmgmt.h>
   2.113 + #include <usr/route.h>
   2.114 + #include <usr/dhcpmgmt.h>
   2.115 +@@ -150,16 +151,68 @@
   2.116 +  */
   2.117 + static int netboot ( struct net_device *netdev ) {
   2.118 + 	char buf[256];
   2.119 +-	int rc;
   2.120 ++	int rc, nodhcp;
   2.121 ++	char *ip, *gw, *dns, *s;
   2.122 ++	extern int apply_nameserver(struct in_addr sin_addr);
   2.123 + 
   2.124 + 	/* Open device and display device status */
   2.125 + 	if ( ( rc = ifopen ( netdev ) ) != 0 )
   2.126 + 		return rc;
   2.127 + 	ifstat ( netdev );
   2.128 + 
   2.129 ++	ip = gw = dns = NULL;
   2.130 ++	nodhcp = 0;
   2.131 ++	for (s = forced_url.url; *s && s < forced_url.url + 256;) {
   2.132 ++		while (*s == ' ') s++;
   2.133 ++		if (!strncmp(s,"ip=",3)) ip = s + 3, *s++ = 0;
   2.134 ++		if (!strncmp(s,"gw=",3)) gw = s + 3, *s++ = 0;
   2.135 ++		if (!strncmp(s,"dns=",4)) dns = s + 4, *s++ = 0;
   2.136 ++		if (!strncmp(s,"nodhcp",5)) nodhcp++, *s++ = 0;
   2.137 ++		if (!strncmp(s,"url=",4)) {
   2.138 ++			char *p = forced_url.url;
   2.139 ++			for (s += 4; *s && *s != ' '; *p++ = *s++);
   2.140 ++			*p = 0;
   2.141 ++		}
   2.142 ++		while (*s && *s != ' ') s++;
   2.143 ++		*s++ = 0;
   2.144 ++	}
   2.145 ++	
   2.146 + 	/* Configure device via DHCP */
   2.147 +-	if ( ( rc = dhcp ( netdev ) ) != 0 )
   2.148 +-		return rc;
   2.149 ++	if (forced_url.url[0]) printf("url=%s\n",forced_url.url);
   2.150 ++	if ( nodhcp || ( rc = dhcp ( netdev ) ) != 0 ) {
   2.151 ++#define IN_CLASSA(x)	(( (x).s_addr & 0x80000000) == 0)
   2.152 ++#define IN_CLASSB(x)	(( (x).s_addr & 0xc0000000) == 0x80000000)
   2.153 ++#define IN_CLASSA_NET	0xff000000
   2.154 ++#define IN_CLASSB_NET	0xffff0000
   2.155 ++#define IN_CLASSC_NET	0xffffff00
   2.156 ++#define IN_CLASSLESS_NET(x)	(0xffffffff << (32 - (x)))
   2.157 ++		struct in_addr address, netmask, gateway, nameserver;
   2.158 ++		char *p;
   2.159 ++
   2.160 ++		if (!ip || !gw || !inet_aton(gw, &gateway))
   2.161 ++			return rc;
   2.162 ++		p = strchr(ip,'/');
   2.163 ++		if (p) *p++ = 0;
   2.164 ++		if (!inet_aton(ip, &address))
   2.165 ++			return rc;
   2.166 ++		if (p) {
   2.167 ++			int n;
   2.168 ++			for (n = 0; *p >= '0' && *p <= '9'; 
   2.169 ++			     n *= 10, n += *p++ - 10);
   2.170 ++			netmask.s_addr = IN_CLASSLESS_NET(n);
   2.171 ++		}
   2.172 ++		else if (IN_CLASSA(address)) netmask.s_addr = IN_CLASSA_NET;
   2.173 ++		else if (IN_CLASSB(address)) netmask.s_addr = IN_CLASSB_NET;
   2.174 ++		else netmask.s_addr = IN_CLASSC_NET;
   2.175 ++		del_ipv4_address ( netdev );
   2.176 ++		if ( ( rc = add_ipv4_address ( netdev, address, netmask,
   2.177 ++					       gateway ) ) != 0 ) {
   2.178 ++			return rc;
   2.179 ++		}
   2.180 ++		if (dns) printf("dns=%s\n",dns);
   2.181 ++		if (dns && inet_aton(dns, &nameserver))
   2.182 ++			apply_nameserver(nameserver);
   2.183 ++	}
   2.184 + 	route();
   2.185 + 
   2.186 + 	/* Try to boot an embedded image if we have one */