|
@@ -0,0 +1,113 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+FILE_LICENCE ( GPL2_OR_LATER );
|
|
20
|
+
|
|
21
|
+/** @file
|
|
22
|
+ *
|
|
23
|
+ * Command line passed to iPXE
|
|
24
|
+ *
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+#include <stddef.h>
|
|
28
|
+#include <stdint.h>
|
|
29
|
+#include <stdlib.h>
|
|
30
|
+#include <assert.h>
|
|
31
|
+#include <ipxe/init.h>
|
|
32
|
+#include <ipxe/image.h>
|
|
33
|
+#include <ipxe/script.h>
|
|
34
|
+#include <realmode.h>
|
|
35
|
+
|
|
36
|
+/** Command line physical address
|
|
37
|
+ *
|
|
38
|
+ * This can be set by the prefix.
|
|
39
|
+ */
|
|
40
|
+uint32_t __bss16 ( cmdline_phys );
|
|
41
|
+#define cmdline_phys __use_data16 ( cmdline_phys )
|
|
42
|
+
|
|
43
|
+/** Internal copy of the command line */
|
|
44
|
+static char *cmdline_copy;
|
|
45
|
+
|
|
46
|
+/** Free command line image */
|
|
47
|
+static void cmdline_image_free ( struct refcnt *refcnt ) {
|
|
48
|
+ struct image *image = container_of ( refcnt, struct image, refcnt );
|
|
49
|
+
|
|
50
|
+ DBGC ( image, "CMDLINE freeing command line\n" );
|
|
51
|
+ free ( cmdline_copy );
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+/** Embedded script representing the command line */
|
|
55
|
+static struct image cmdline_image = {
|
|
56
|
+ .refcnt = REF_INIT ( cmdline_image_free ),
|
|
57
|
+ .name = "<CMDLINE>",
|
|
58
|
+ .type = &script_image_type,
|
|
59
|
+};
|
|
60
|
+
|
|
61
|
+/**
|
|
62
|
+ * Initialise command line
|
|
63
|
+ *
|
|
64
|
+ */
|
|
65
|
+static void cmdline_init ( void ) {
|
|
66
|
+ struct image *image = &cmdline_image;
|
|
67
|
+ userptr_t cmdline_user;
|
|
68
|
+ char *cmdline;
|
|
69
|
+ char *tmp;
|
|
70
|
+ size_t len;
|
|
71
|
+
|
|
72
|
+ /* Do nothing if no command line was specified */
|
|
73
|
+ if ( ! cmdline_phys ) {
|
|
74
|
+ DBGC ( image, "CMDLINE found no command line\n" );
|
|
75
|
+ return;
|
|
76
|
+ }
|
|
77
|
+ cmdline_user = phys_to_user ( cmdline_phys );
|
|
78
|
+ len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );
|
|
79
|
+
|
|
80
|
+ /* Allocate and copy command line */
|
|
81
|
+ cmdline_copy = malloc ( len );
|
|
82
|
+ if ( ! cmdline_copy ) {
|
|
83
|
+ DBGC ( image, "CMDLINE could not allocate %zd bytes\n", len );
|
|
84
|
+ /* No way to indicate failure */
|
|
85
|
+ return;
|
|
86
|
+ }
|
|
87
|
+ cmdline = cmdline_copy;
|
|
88
|
+ copy_from_user ( cmdline, cmdline_user, 0, len );
|
|
89
|
+ DBGC ( image, "CMDLINE found \"%s\"\n", cmdline );
|
|
90
|
+
|
|
91
|
+ /* Check for unwanted cruft in the command line */
|
|
92
|
+ while ( isspace ( *cmdline ) )
|
|
93
|
+ cmdline++;
|
|
94
|
+ if ( ( tmp = strstr ( cmdline, "BOOT_IMAGE=" ) ) != NULL ) {
|
|
95
|
+ DBGC ( image, "CMDLINE stripping \"%s\"\n", tmp );
|
|
96
|
+ *tmp = '\0';
|
|
97
|
+ }
|
|
98
|
+ DBGC ( image, "CMDLINE using \"%s\"\n", cmdline );
|
|
99
|
+
|
|
100
|
+ /* Prepare and register image */
|
|
101
|
+ cmdline_image.data = virt_to_user ( cmdline );
|
|
102
|
+ cmdline_image.len = strlen ( cmdline );
|
|
103
|
+ if ( cmdline_image.len )
|
|
104
|
+ register_image ( &cmdline_image );
|
|
105
|
+
|
|
106
|
+ /* Drop our reference to the image */
|
|
107
|
+ image_put ( &cmdline_image );
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+/** Command line initialisation function */
|
|
111
|
+struct init_fn cmdline_init_fn __init_fn ( INIT_NORMAL ) = {
|
|
112
|
+ .initialise = cmdline_init,
|
|
113
|
+};
|