wok-next view gpxe/stuff/cmdline.u @ 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
children a08b2e53cf96
line source
1 --- gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
2 +++ gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
3 @@ -77,7 +77,9 @@
4 popw %ax
5 addw $(0x100/16), %ax /* Adjust cs */
6 pushw %ax
7 - jmp go_setup_code
8 + pushw $run_etherboot_floppy
9 + /* Calculated lcall to _start with %cs:0000 = image start */
10 + lret
12 bootsector:
13 jmp $BOOTSEG, $go /* reload cs:ip to match relocation addr */
14 @@ -197,7 +199,7 @@
15 */
17 /* Jump to loaded copy */
18 - ljmp $SYSSEG, $run_etherboot2
19 + ljmp $SYSSEG, $run_etherboot_floppy
21 endseg: .word SYSSEG + _load_size_pgh
22 .section ".zinfo.fixup", "a" /* Compressor fixup information */
23 @@ -436,8 +438,7 @@
24 * we just have to ensure that %cs:0000 is where the start of
25 * the Etherboot image *would* be.
26 */
27 -go_setup_code:
28 - pushw $run_etherboot
29 + pushw $run_etherboot_zImage
30 /* Calculated lcall to _start with %cs:0000 = image start */
31 lret
33 @@ -448,7 +449,23 @@
34 /*
35 We're now at the beginning of the kernel proper.
36 */
37 -run_etherboot2:
38 +run_etherboot_zImage:
39 + mov $0x0020, %si
40 + lodsw
41 + cmp $0xA33F, %ax
42 + jne run_etherboot
43 + lodsw
44 + xchg %ax, %si
45 + push %ds
46 + pop %es
47 + movw $boot_url, %di
48 +copy_cmdline:
49 + lodsb
50 + stosb
51 + or %al, %al
52 + jne copy_cmdline
53 + jmp run_etherboot
54 +run_etherboot_floppy:
55 push %cs
56 pop %ds
57 run_etherboot:
59 --- gpxe-0.9.3/src/net/udp/dns.c
60 +++ gpxe-0.9.3/src/net/udp/dns.c
61 @@ -506,6 +506,19 @@
62 .resolv = dns_resolv,
63 };
65 +int apply_nameserver(struct in_addr sin_addr)
66 +{
67 + struct sockaddr_in *sin_nameserver;
68 +
69 + sin_nameserver = ( struct sockaddr_in * ) &nameserver;
70 + sin_nameserver->sin_family = AF_INET;
71 + sin_nameserver->sin_addr = sin_addr;
72 + DBG ( "DNS using nameserver %s\n",
73 + inet_ntoa ( sin_addr ) );
74 +
75 + return 0;
76 +}
77 +
78 /**
79 * Apply DHCP nameserver option
80 *
81 @@ -514,16 +527,10 @@
82 */
83 static int apply_dhcp_nameserver ( unsigned int tag __unused,
84 struct dhcp_option *option ) {
85 - struct sockaddr_in *sin_nameserver;
86 -
87 - sin_nameserver = ( struct sockaddr_in * ) &nameserver;
88 - sin_nameserver->sin_family = AF_INET;
89 - dhcp_ipv4_option ( option, &sin_nameserver->sin_addr );
90 -
91 - DBG ( "DNS using nameserver %s\n",
92 - inet_ntoa ( sin_nameserver->sin_addr ) );
93 + struct in_addr sin_addr;
95 - return 0;
96 + dhcp_ipv4_option ( option, &sin_addr );
97 + return apply_nameserver(sin_addr);
98 }
100 /** DHCP nameserver applicator */
102 --- gpxe-0.9.3/src/usr/autoboot.c
103 +++ gpxe-0.9.3/src/usr/autoboot.c
104 @@ -23,6 +23,7 @@
105 #include <gpxe/dhcp.h>
106 #include <gpxe/image.h>
107 #include <gpxe/embedded.h>
108 +#include <gpxe/ip.h>
109 #include <usr/ifmgmt.h>
110 #include <usr/route.h>
111 #include <usr/dhcpmgmt.h>
112 @@ -150,16 +151,68 @@
113 */
114 static int netboot ( struct net_device *netdev ) {
115 char buf[256];
116 - int rc;
117 + int rc, nodhcp;
118 + char *ip, *gw, *dns, *s;
119 + extern int apply_nameserver(struct in_addr sin_addr);
121 /* Open device and display device status */
122 if ( ( rc = ifopen ( netdev ) ) != 0 )
123 return rc;
124 ifstat ( netdev );
126 + ip = gw = dns = NULL;
127 + nodhcp = 0;
128 + for (s = forced_url.url; *s && s < forced_url.url + 256;) {
129 + while (*s == ' ') s++;
130 + if (!strncmp(s,"ip=",3)) ip = s + 3, *s++ = 0;
131 + if (!strncmp(s,"gw=",3)) gw = s + 3, *s++ = 0;
132 + if (!strncmp(s,"dns=",4)) dns = s + 4, *s++ = 0;
133 + if (!strncmp(s,"nodhcp",5)) nodhcp++, *s++ = 0;
134 + if (!strncmp(s,"url=",4)) {
135 + char *p = forced_url.url;
136 + for (s += 4; *s && *s != ' '; *p++ = *s++);
137 + *p = 0;
138 + }
139 + while (*s && *s != ' ') s++;
140 + *s++ = 0;
141 + }
142 +
143 /* Configure device via DHCP */
144 - if ( ( rc = dhcp ( netdev ) ) != 0 )
145 - return rc;
146 + if (forced_url.url[0]) printf("url=%s\n",forced_url.url);
147 + if ( nodhcp || ( rc = dhcp ( netdev ) ) != 0 ) {
148 +#define IN_CLASSA(x) (( (x).s_addr & 0x80000000) == 0)
149 +#define IN_CLASSB(x) (( (x).s_addr & 0xc0000000) == 0x80000000)
150 +#define IN_CLASSA_NET 0xff000000
151 +#define IN_CLASSB_NET 0xffff0000
152 +#define IN_CLASSC_NET 0xffffff00
153 +#define IN_CLASSLESS_NET(x) (0xffffffff << (32 - (x)))
154 + struct in_addr address, netmask, gateway, nameserver;
155 + char *p;
156 +
157 + if (!ip || !gw || !inet_aton(gw, &gateway))
158 + return rc;
159 + p = strchr(ip,'/');
160 + if (p) *p++ = 0;
161 + if (!inet_aton(ip, &address))
162 + return rc;
163 + if (p) {
164 + int n;
165 + for (n = 0; *p >= '0' && *p <= '9';
166 + n *= 10, n += *p++ - 10);
167 + netmask.s_addr = IN_CLASSLESS_NET(n);
168 + }
169 + else if (IN_CLASSA(address)) netmask.s_addr = IN_CLASSA_NET;
170 + else if (IN_CLASSB(address)) netmask.s_addr = IN_CLASSB_NET;
171 + else netmask.s_addr = IN_CLASSC_NET;
172 + del_ipv4_address ( netdev );
173 + if ( ( rc = add_ipv4_address ( netdev, address, netmask,
174 + gateway ) ) != 0 ) {
175 + return rc;
176 + }
177 + if (dns) printf("dns=%s\n",dns);
178 + if (dns && inet_aton(dns, &nameserver))
179 + apply_nameserver(nameserver);
180 + }
181 route();
183 /* Try to boot an embedded image if we have one */