wok-6.x view gpxe/stuff/default_boot.u @ rev 1001

gpxe: set pxelinux TFTP prefix
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 06 17:25:17 2008 +0000 (2008-07-06)
parents a28a18adeab4
children 5367046716ba
line source
1 --- gpxe-0.9.3/src/arch/i386/interface/pxe/pxe_call.c
2 +++ gpxe-0.9.3/src/arch/i386/interface/pxe/pxe_call.c
3 @@ -96,6 +96,8 @@
4 PXENV_EXIT_t ( * file_select ) ( struct s_PXENV_FILE_SELECT * );
5 PXENV_EXIT_t ( * file_read ) ( struct s_PXENV_FILE_READ * );
6 PXENV_EXIT_t ( * get_file_size ) ( struct s_PXENV_GET_FILE_SIZE * );
7 + PXENV_EXIT_t ( * file_exec ) ( struct s_PXENV_FILE_EXEC * );
8 + PXENV_EXIT_t ( * file_api_check ) ( struct s_PXENV_FILE_API_CHECK * );
9 };
11 /**
12 @@ -294,6 +296,14 @@
13 pxenv_call.get_file_size = pxenv_get_file_size;
14 param_len = sizeof ( pxenv_any.get_file_size );
15 break;
16 + case PXENV_FILE_EXEC:
17 + pxenv_call.file_exec = pxenv_file_exec;
18 + param_len = sizeof ( pxenv_any.file_exec );
19 + break;
20 + case PXENV_FILE_API_CHECK:
21 + pxenv_call.file_api_check = pxenv_file_api_check;
22 + param_len = sizeof ( pxenv_any.file_api_check );
23 + break;
24 default:
25 DBG ( "PXENV_UNKNOWN_%hx", opcode );
26 pxenv_call.unknown = pxenv_unknown;
28 --- gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
29 +++ gpxe-0.9.3/src/arch/i386/prefix/lkrnprefix.S
30 @@ -441,6 +441,8 @@
31 /* Calculated lcall to _start with %cs:0000 = image start */
32 lret
34 +boot_url:
35 + .space 256, 0
37 .org PREFIXSIZE
38 /*
39 @@ -453,6 +455,13 @@
40 movw %bx, %ss
41 movw $_estack16, %sp
43 + /* Copy our boot_url structure to the forced_url variable */
44 + movw %bx, %es
45 + movw $forced_url, %di
46 + movw $boot_url, %si
47 + movw $256, %cx
48 + rep movsb
49 +
50 /* Jump to .text16 segment */
51 pushw %ax
52 pushw $1f
54 --- gpxe-0.9.3/src/arch/i386/prefix/pxeprefix.S
55 +++ gpxe-0.9.3/src/arch/i386/prefix/pxeprefix.S
56 @@ -19,6 +19,9 @@
57 .section ".prefix"
58 /* Set up our non-stack segment registers */
59 jmp $0x7c0, $1f
60 +#define PXELOADER_KEEP_UNDI
61 +boot_url:
62 + .space 256, 0
63 1: movw %cs, %ax
64 movw %ax, %ds
65 movw $0x40, %ax /* BIOS data segment access */
66 @@ -703,16 +706,22 @@
67 /* Set up real-mode stack */
68 movw %bx, %ss
69 movw $_estack16, %sp
70 -
71 + movw %bx, %es
72 +
73 #ifdef PXELOADER_KEEP_UNDI
74 /* Copy our undi_device structure to the preloaded_undi variable */
75 - movw %bx, %es
76 movw $preloaded_undi, %di
77 movw $undi_device, %si
78 movw $undi_device_size, %cx
79 rep movsb
80 #endif
82 + /* Copy our boot_url structure to the forced_url variable */
83 + movw $forced_url, %di
84 + movw $boot_url, %si
85 + movw $256, %cx
86 + rep movsb
87 +
88 /* Jump to .text16 segment with %ds pointing to .data16 */
89 movw %bx, %ds
90 pushw %ax
92 --- gpxe-0.9.3/src/include/pxe_api.h
93 +++ gpxe-0.9.3/src/include/pxe_api.h
94 @@ -1684,6 +1684,54 @@
96 /** @} */ /* pxenv_get_file_size */
98 +/** @defgroup pxenv_file_exec PXENV_FILE_EXEC
99 + *
100 + * FILE EXEC
101 + *
102 + * @{
103 + */
104 +
105 +/** PXE API function code for pxenv_file_exec() */
106 +#define PXENV_FILE_EXEC 0x00e5
107 +
108 +/** Parameter block for pxenv_file_exec() */
109 +struct s_PXENV_FILE_EXEC {
110 + PXENV_STATUS_t Status; /**< PXE status code */
111 + SEGOFF16_t Command; /**< Command to execute */
112 +} PACKED;
113 +
114 +typedef struct s_PXENV_FILE_EXEC PXENV_FILE_EXEC_t;
115 +
116 +extern PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec );
117 +
118 +/** @} */ /* pxenv_file_exec */
119 +
120 +/** @defgroup pxenv_file_api_check PXENV_FILE_API_CHECK
121 + *
122 + * FILE API CHECK
123 + *
124 + * @{
125 + */
126 +
127 +/** PXE API function code for pxenv_file_api_check() */
128 +#define PXENV_FILE_API_CHECK 0x00e6
129 +
130 +/** Parameter block for pxenv_file_api_check() */
131 +struct s_PXENV_FILE_API_CHECK {
132 + PXENV_STATUS_t Status; /**< PXE status code */
133 + UINT16_t Size; /**< Size of structure */
134 + UINT32_t Magic; /**< Magic number */
135 + UINT32_t Provider; /**< Implementation identifier */
136 + UINT32_t APIMask; /**< Supported API functions */
137 + UINT32_t Flags; /**< Reserved for the future */
138 +} PACKED;
139 +
140 +typedef struct s_PXENV_FILE_API_CHECK PXENV_FILE_API_CHECK_t;
141 +
142 +extern PXENV_EXIT_t pxenv_file_api_check ( struct s_PXENV_FILE_API_CHECK *file_api_check );
143 +
144 +/** @} */ /* pxenv_file_api_check */
145 +
146 /** @} */ /* pxe_file_api */
148 /** @defgroup pxe_loader_api PXE Loader API
150 --- gpxe-0.9.3/src/include/pxe.h
151 +++ gpxe-0.9.3/src/include/pxe.h
152 @@ -63,6 +63,8 @@
153 struct s_PXENV_FILE_SELECT file_select;
154 struct s_PXENV_FILE_READ file_read;
155 struct s_PXENV_GET_FILE_SIZE get_file_size;
156 + struct s_PXENV_FILE_EXEC file_exec;
157 + struct s_PXENV_FILE_API_CHECK file_api_check;
158 };
160 typedef union u_PXENV_ANY PXENV_ANY_t;
162 --- gpxe-0.9.3/src/interface/pxe/pxe_file.c
163 +++ gpxe-0.9.3/src/interface/pxe/pxe_file.c
164 @@ -31,7 +31,7 @@
165 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
166 */
168 -FEATURE ( FEATURE_MISC, "PXEXT", DHCP_EB_FEATURE_PXE_EXT, 1 );
169 +FEATURE ( FEATURE_MISC, "PXEXT", DHCP_EB_FEATURE_PXE_EXT, 2 );
171 /**
172 * FILE OPEN
173 @@ -189,3 +189,76 @@
174 get_file_size->Status = PXENV_STATUS_SUCCESS;
175 return PXENV_EXIT_SUCCESS;
176 }
177 +
178 +/**
179 + * FILE EXEC
180 + *
181 + * @v file_exec Pointer to a struct s_PXENV_FILE_EXEC
182 + * @v s_PXENV_FILE_EXEC::Command Command to execute
183 + * @ret #PXENV_EXIT_SUCCESS Command was executed successfully
184 + * @ret #PXENV_EXIT_FAILURE Command was not executed successfully
185 + * @ret s_PXENV_FILE_EXEC::Status PXE status code
186 + *
187 + */
188 +PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) {
189 + userptr_t command;
190 + size_t command_len;
191 + int rc;
192 +
193 + DBG ( "PXENV_FILE_EXEC" );
194 +
195 + /* Copy name from external program, and exec it */
196 + command = real_to_user ( file_exec->Command.segment,
197 + file_exec->Command.offset );
198 + command_len = strlen_user ( command, 0 );
199 + {
200 + char command_string[ command_len + 1 ];
201 +
202 + copy_from_user ( command_string, command, 0,
203 + sizeof ( command_string ) );
204 + DBG ( " %s", command_string );
205 +
206 + if ( ( rc = system ( command_string ) ) != 0 ) {
207 + file_exec->Status = PXENV_STATUS ( rc );
208 + return PXENV_EXIT_FAILURE;
209 + }
210 + }
211 +
212 + file_exec->Status = PXENV_STATUS_SUCCESS;
213 + return PXENV_EXIT_SUCCESS;
214 +}
215 +
216 +/**
217 + * FILE API CHECK
218 + *
219 + * @v file_exec Pointer to a struct s_PXENV_FILE_API_CHECK
220 + * @v s_PXENV_FILE_API_CHECK::Magic Inbound magic number (0x91d447b2)
221 + * @ret #PXENV_EXIT_SUCCESS Command was executed successfully
222 + * @ret #PXENV_EXIT_FAILURE Command was not executed successfully
223 + * @ret s_PXENV_FILE_API_CHECK::Status PXE status code
224 + * @ret s_PXENV_FILE_API_CHECK::Magic Outbound magic number (0xe9c17b20)
225 + * @ret s_PXENV_FILE_API_CHECK::Provider "gPXE" (0x45585067)
226 + * @ret s_PXENV_FILE_API_CHECK::APIMask API function bitmask
227 + * @ret s_PXENV_FILE_API_CHECK::Flags Reserved
228 + *
229 + */
230 +PXENV_EXIT_t pxenv_file_api_check ( struct s_PXENV_FILE_API_CHECK *file_api_check ) {
231 + DBG ( "PXENV_FILE_API_CHECK" );
232 +
233 + if ( file_api_check->Magic != 0x91d447b2 ) {
234 + file_api_check->Status = PXENV_STATUS_BAD_FUNC;
235 + return PXENV_EXIT_FAILURE;
236 + } else if ( file_api_check->Size <
237 + sizeof(struct s_PXENV_FILE_API_CHECK) ) {
238 + file_api_check->Status = PXENV_STATUS_OUT_OF_RESOURCES;
239 + return PXENV_EXIT_FAILURE;
240 + } else {
241 + file_api_check->Status = PXENV_STATUS_SUCCESS;
242 + file_api_check->Size = sizeof(struct s_PXENV_FILE_API_CHECK);
243 + file_api_check->Magic = 0xe9c17b20;
244 + file_api_check->Provider = 0x45585067; /* "gPXE" */
245 + file_api_check->APIMask = 0x0000007f; /* Functions e0-e6 */
246 + file_api_check->Flags = 0; /* None defined */
247 + return PXENV_EXIT_SUCCESS;
248 + }
249 +}
251 --- gpxe-0.9.3/src/usr/autoboot.c
252 +++ gpxe-0.9.3/src/usr/autoboot.c
253 @@ -120,6 +120,28 @@
254 return -ENOTSUP;
255 }
257 +static void set_url ( char buf[], const char url[] ) {
258 + int i, d = 0;
259 +
260 + for (i = 0; url[i] >= ' '; i++) {
261 + if (url[i] == '/') d = i;
262 + buf[i] = url[i];
263 + }
264 + buf[i] = 0;
265 + if (strstr(buf,"pxelinux")) {
266 + struct dhcp_option_block *options = list_entry (
267 + dhcp_option_blocks.next, typeof ( *options ), list );
268 +
269 + set_dhcp_option( options, 208, "\xF1\x00\x74\x7E", 4 );
270 + set_dhcp_option( options, 210, buf, d+1 );
271 + }
272 +}
273 +
274 +struct _forced_url {
275 + char url[256];
276 +};
277 +struct _forced_url __data16 ( forced_url );
278 +#define forced_url __use_data16 ( forced_url )
279 /**
280 * Boot from a network device
281 *
282 @@ -148,6 +170,12 @@
283 /* Try to download and boot whatever we are given as a filename */
284 dhcp_snprintf ( buf, sizeof ( buf ),
285 find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
286 +
287 + if ( forced_url.url[0] != 0 ) {
288 + /* Try to boot a forced url if we have one */
289 + set_url ( buf, forced_url.url );
290 + }
291 + while (1) {
292 if ( buf[0] ) {
293 printf ( "Booting from filename \"%s\"\n", buf );
294 return boot_filename ( buf );
295 @@ -162,7 +190,8 @@
296 }
298 printf ( "No filename or root path specified\n" );
299 - return -ENOENT;
300 + set_url ( buf, "http://boot.slitaz.org/gpxe" );
301 + }
302 }
304 /**