Browse Source

[pxe] Add PXENV_FILE_CMDLINE API call

Allow a PXE NBP to obtain its command line (if any) via the new PXE
API call PXENV_FILE_CMDLINE.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
a814eff38e

+ 9
- 0
src/arch/i386/image/pxe_image.c View File

@@ -35,6 +35,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 
36 36
 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
37 37
 
38
+/** PXE command line */
39
+const char *pxe_cmdline;
40
+
38 41
 /**
39 42
  * Execute PXE image
40 43
  *
@@ -66,9 +69,15 @@ static int pxe_exec ( struct image *image ) {
66 69
 	/* Activate PXE */
67 70
 	pxe_activate ( netdev );
68 71
 
72
+	/* Set PXE command line */
73
+	pxe_cmdline = image->cmdline;
74
+
69 75
 	/* Start PXE NBP */
70 76
 	rc = pxe_start_nbp();
71 77
 
78
+	/* Clear PXE command line */
79
+	pxe_cmdline = NULL;
80
+
72 81
 	/* Deactivate PXE */
73 82
 	pxe_deactivate();
74 83
 

+ 1
- 0
src/arch/i386/include/pxe.h View File

@@ -188,6 +188,7 @@ struct pcir_header {
188 188
 	( ( 'P' << 0 ) + ( 'C' << 8 ) + ( 'I' << 16 ) + ( 'R' << 24 ) )
189 189
 
190 190
 extern struct net_device *pxe_netdev;
191
+extern const char *pxe_cmdline;
191 192
 
192 193
 extern void pxe_set_netdev ( struct net_device *netdev );
193 194
 extern PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE

+ 21
- 0
src/arch/i386/include/pxe_api.h View File

@@ -1690,6 +1690,27 @@ typedef struct s_PXENV_FILE_EXIT_HOOK PXENV_FILE_EXIT_HOOK_t;
1690 1690
 
1691 1691
 /** @} */ /* pxenv_file_exit_hook */
1692 1692
 
1693
+/** @defgroup pxenv_file_cmdline PXENV_FILE_CMDLINE
1694
+ *
1695
+ * FILE CMDLINE
1696
+ *
1697
+ * @{
1698
+ */
1699
+
1700
+/** PXE API function code for pxenv_file_cmdline() */
1701
+#define PXENV_FILE_CMDLINE			0x00e8
1702
+
1703
+/** Parameter block for pxenv_file_cmdline() */
1704
+struct s_PXENV_FILE_CMDLINE {
1705
+	PXENV_STATUS_t Status;		/**< PXE status code */
1706
+	UINT16_t BufferSize;		/**< Data buffer size */
1707
+	SEGOFF16_t Buffer;		/**< Data buffer */
1708
+} __attribute__ (( packed ));
1709
+
1710
+typedef struct s_PXENV_FILE_CMDLINE PXENV_FILE_CMDLINE_t;
1711
+
1712
+/** @} */ /* pxe_file_cmdline */
1713
+
1693 1714
 /** @} */ /* pxe_file_api */
1694 1715
 
1695 1716
 /** @defgroup pxe_loader_api PXE Loader API

+ 38
- 0
src/arch/i386/interface/pxe/pxe_file.c View File

@@ -232,6 +232,42 @@ static PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) {
232 232
 	return PXENV_EXIT_SUCCESS;
233 233
 }
234 234
 
235
+/**
236
+ * FILE CMDLINE
237
+ *
238
+ * @v file_cmdline			Pointer to a struct s_PXENV_FILE_CMDLINE
239
+ * @v s_PXENV_FILE_CMDLINE::Buffer	Buffer to contain command line
240
+ * @v s_PXENV_FILE_CMDLINE::BufferSize	Size of buffer
241
+ * @ret #PXENV_EXIT_SUCCESS		Command was executed successfully
242
+ * @ret #PXENV_EXIT_FAILURE		Command was not executed successfully
243
+ * @ret s_PXENV_FILE_EXEC::Status	PXE status code
244
+ * @ret s_PXENV_FILE_EXEC::BufferSize	Length of command line (including NUL)
245
+ *
246
+ */
247
+static PXENV_EXIT_t
248
+pxenv_file_cmdline ( struct s_PXENV_FILE_CMDLINE *file_cmdline ) {
249
+	userptr_t buffer;
250
+	size_t max_len;
251
+	size_t len;
252
+
253
+	DBG ( "PXENV_FILE_CMDLINE to %04x:%04x+%04x \"%s\"\n",
254
+	      file_cmdline->Buffer.segment, file_cmdline->Buffer.offset,
255
+	      file_cmdline->BufferSize, pxe_cmdline );
256
+
257
+	buffer = real_to_user ( file_cmdline->Buffer.segment,
258
+				file_cmdline->Buffer.offset );
259
+	len = file_cmdline->BufferSize;
260
+	max_len = ( pxe_cmdline ?
261
+		    ( strlen ( pxe_cmdline ) + 1 /* NUL */ ) : 0 );
262
+	if ( len > max_len )
263
+		len = max_len;
264
+	copy_to_user ( buffer, 0, pxe_cmdline, len );
265
+	file_cmdline->BufferSize = max_len;
266
+
267
+	file_cmdline->Status = PXENV_STATUS_SUCCESS;
268
+	return PXENV_EXIT_SUCCESS;
269
+}
270
+
235 271
 /**
236 272
  * FILE API CHECK
237 273
  *
@@ -298,6 +334,8 @@ struct pxe_api_call pxe_file_api[] __pxe_api_call = {
298 334
 		       struct s_PXENV_GET_FILE_SIZE ),
299 335
 	PXE_API_CALL ( PXENV_FILE_EXEC, pxenv_file_exec,
300 336
 		       struct s_PXENV_FILE_EXEC ),
337
+	PXE_API_CALL ( PXENV_FILE_CMDLINE, pxenv_file_cmdline,
338
+		       struct s_PXENV_FILE_CMDLINE ),
301 339
 	PXE_API_CALL ( PXENV_FILE_API_CHECK, pxenv_file_api_check,
302 340
 		       struct s_PXENV_FILE_API_CHECK ),
303 341
 };

Loading…
Cancel
Save