ソースを参照

[image] Allow multiple embedded images

This patch extends the embedded image feature to allow multiple
embedded images instead of just one.

gPXE now always boots the first embedded image on startup instead of
doing the hardcoded DHCP boot (aka autoboot).

Based heavily upon a patch by Stefan Hajnoczi <stefanha@gmail.com>.
tags/v0.9.7
Michael Brown 15年前
コミット
076154a1c6

+ 4
- 0
contrib/scripts/gpxelinux.gpxe ファイルの表示

@@ -0,0 +1,4 @@
1
+#!gpxe
2
+dhcp net0
3
+imgload img1
4
+boot img1

+ 8
- 0
contrib/scripts/static.gpxe ファイルの表示

@@ -0,0 +1,8 @@
1
+#!gpxe
2
+ifopen net0
3
+set net0/ip 10.0.2.15
4
+set net0/netmask 255.255.255.0
5
+set net0/gateway 10.0.2.2
6
+set net0/dns 10.0.2.3
7
+kernel http://etherboot.org/gtest/gtest.gpxe
8
+boot gtest.gpxe

+ 33
- 9
src/Makefile.housekeeping ファイルの表示

@@ -85,6 +85,13 @@ VERYCLEANUP	+= .toolcheck
85 85
 # Check for various tool workarounds
86 86
 #
87 87
 
88
+# Make syntax does not allow use of comma or space in certain places.
89
+# This ugly workaround is suggested in the manual.
90
+#
91
+COMMA	:= ,
92
+EMPTY	:=
93
+SPACE	:= $(EMPTY) $(EMPTY)
94
+
88 95
 # Check for an old version of gas (binutils 2.9.1)
89 96
 #
90 97
 OLDGAS	:= $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
@@ -280,9 +287,9 @@ ASFLAGS		+= --fatal-warnings
280 287
 ASFLAGS		+= $(EXTRA_ASFLAGS)
281 288
 LDFLAGS		+= $(EXTRA_LDFLAGS)
282 289
 
283
-# Embedded image, if present
290
+# Embedded image(s), or default if not set
284 291
 #
285
-EMBEDDED_IMAGE	= /dev/null
292
+EMBEDDED_IMAGE	= image/default.gpxe
286 293
 
287 294
 # Inhibit -Werror if NO_WERROR is specified on make command line
288 295
 #
@@ -406,13 +413,31 @@ drivers :
406 413
 roms :
407 414
 	@$(ECHO) $(ROMS)
408 415
 
409
-# Embedded binary
410
-$(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
411
-	$(QM)$(ECHO) "  [COPY] $@"
412
-	$(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
416
+# List of embedded images included in the last build of embedded.o.
417
+# This is needed in order to correctly rebuild embedded.o whenever the
418
+# list of objects changes.
419
+#
420
+EMBEDDED_LIST	:= $(BIN)/.embedded.list
421
+ifeq ($(wildcard $(EMBEDDED_LIST)),)
422
+EMBEDDED_LIST_IMAGE :=
423
+else
424
+EMBEDDED_LIST_IMAGE := $(shell cat $(EMBEDDED_LIST))
425
+endif
426
+ifneq ($(EMBEDDED_LIST_IMAGE),$(EMBEDDED_IMAGE))
427
+$(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
428
+endif
429
+
430
+$(EMBEDDED_LIST) :
431
+
432
+VERYCLEANUP	+= $(EMBEDDED_LIST)
433
+
434
+EMBEDDED_FILES	:= $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
435
+EMBED_ALL	:= $(foreach i,$(shell seq 1 $(words $(EMBEDDED_FILES))),\
436
+		     EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
437
+			     \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
413 438
 
414
-$(BIN)/embed.o: $(BIN)/embedimg.bin
415
-CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
439
+$(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
440
+CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
416 441
 
417 442
 # Generate the NIC file from the parsed source files.  The NIC file is
418 443
 # only for rom-o-matic.
@@ -491,7 +516,6 @@ TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
491 516
 # Calculate list of debugging versions of objects to be included in
492 517
 # the target.
493 518
 #
494
-COMMA		:= ,
495 519
 DEBUG_LIST	= $(subst $(COMMA), ,$(DEBUG))
496 520
 DEBUG_OBJ_LEVEL	= $(firstword $(word 2,$(subst :, ,$(1))) 1)
497 521
 DEBUG_OBJ_BASE	= $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))

+ 1
- 0
src/core/config.c ファイルの表示

@@ -218,3 +218,4 @@ REQUIRE_OBJECT ( gdbstub_cmd );
218 218
  *
219 219
  */
220 220
 REQUIRE_OBJECT ( device );
221
+REQUIRE_OBJECT ( embedded );

+ 11
- 4
src/core/main.c ファイルの表示

@@ -19,6 +19,7 @@ Literature dealing with the network protocols:
19 19
 #include <gpxe/features.h>
20 20
 #include <gpxe/shell.h>
21 21
 #include <gpxe/shell_banner.h>
22
+#include <gpxe/image.h>
22 23
 #include <usr/autoboot.h>
23 24
 #include <config/general.h>
24 25
 
@@ -36,6 +37,7 @@ static struct feature features_end[0] __table_end ( struct feature, features );
36 37
  */
37 38
 __asmcall int main ( void ) {
38 39
 	struct feature *feature;
40
+	struct image *image;
39 41
 
40 42
 	/* Some devices take an unreasonably long time to initialise */
41 43
 	printf ( PRODUCT_SHORT_NAME " initialising devices...\n" );
@@ -68,11 +70,16 @@ __asmcall int main ( void ) {
68 70
 		/* User wants shell; just give them a shell */
69 71
 		shell();
70 72
 	} else {
71
-		/* User doesn't want shell; try booting.  If booting
72
-		 * fails, offer a second chance to enter the shell for
73
-		 * diagnostics.
73
+		/* User doesn't want shell; load and execute the first
74
+		 * image.  If booting fails (i.e. if the image
75
+		 * returns, or fails to execute), offer a second
76
+		 * chance to enter the shell for diagnostics.
74 77
 		 */
75
-		autoboot();
78
+		for_each_image ( image ) {
79
+			image_exec ( image );
80
+			break;
81
+		}
82
+
76 83
 		if ( shell_banner() )
77 84
 			shell();
78 85
 	}

+ 2
- 0
src/image/default.gpxe ファイルの表示

@@ -0,0 +1,2 @@
1
+#!gpxe
2
+autoboot

+ 0
- 7
src/image/embed.S ファイルの表示

@@ -1,7 +0,0 @@
1
-	.section ".data", "aw", @progbits
2
-	.balign 4
3
-	.globl _embedded_image_start
4
-_embedded_image_start:
5
-	.incbin EMBEDIMG
6
-	.globl _embedded_image_end
7
-_embedded_image_end:

+ 77
- 32
src/image/embedded.c ファイルの表示

@@ -1,49 +1,94 @@
1 1
 /** @file
2 2
  *
3
- * Take a possible embedded image and put it in a struct image
4
- * data structure.
3
+ * Embedded image support
4
+ *
5
+ * Embedded images are images built into the gPXE binary and do not require
6
+ * fetching over the network.
5 7
  */
6 8
 
9
+#include <string.h>
7 10
 #include <gpxe/image.h>
8
-#include <gpxe/malloc.h>
9 11
 #include <gpxe/uaccess.h>
10
-#include <gpxe/umalloc.h>
11
-#include <gpxe/embedded.h>
12
+#include <gpxe/init.h>
12 13
 
13
-extern char _embedded_image_start[], _embedded_image_end[];
14
+/**
15
+ * Free embedded image
16
+ *
17
+ * @v refcnt		Reference counter
18
+ */
19
+static void embedded_image_free ( struct refcnt *refcnt __unused ) {
20
+	/* Do nothing */
21
+}
14 22
 
15
-struct image *embedded_image(void)
16
-{
17
-	static int reclaimed = 0;
18
-	struct image *image;
19
-	size_t eisize = _embedded_image_end - _embedded_image_start;
23
+/* Raw image data for all embedded images */
24
+#undef EMBED
25
+#define EMBED( _index, _path, _name )					\
26
+	extern char embedded_image_ ## _index ## _data[];		\
27
+	extern char embedded_image_ ## _index ## _len[];		\
28
+	__asm__ ( ".section \".rodata\", \"a\", @progbits\n\t"		\
29
+		  "\nembedded_image_" #_index "_data:\n\t"		\
30
+		  ".incbin \"" _path "\"\n\t"				\
31
+		  "\nembedded_image_" #_index "_end:\n\t"		\
32
+		  ".equ embedded_image_" #_index "_len, "		\
33
+			"( embedded_image_" #_index "_end - "		\
34
+			"  embedded_image_" #_index "_data )\n\t"	\
35
+		  ".previous\n\t" );
36
+EMBED_ALL
20 37
 
21
-	if ( !eisize )
22
-		return NULL;	/* No embedded image */
38
+/* Image structures for all embedded images */
39
+#undef EMBED
40
+#define EMBED( _index, _path, _name ) {					\
41
+	.refcnt = { .free = embedded_image_free, },			\
42
+	.name = _name,							\
43
+	.data = ( userptr_t ) ( embedded_image_ ## _index ## _data ),	\
44
+	.len = ( size_t ) embedded_image_ ## _index ## _len,		\
45
+},
46
+static struct image embedded_images[] = {
47
+	EMBED_ALL
48
+};
23 49
 
24
-	if ( reclaimed )
25
-		return NULL;	/* Already reclaimed */
50
+/**
51
+ * Register all embedded images
52
+ */
53
+static void embedded_init ( void ) {
54
+	unsigned int i;
55
+	struct image *image;
56
+	void *data;
57
+	int rc;
26 58
 
27
-	DBG ( "Embedded image: %zd bytes at %p\n",
28
-	      eisize, _embedded_image_start );
59
+	/* Fix up data pointers and register images */
60
+	for ( i = 0 ; i < ( sizeof ( embedded_images ) /
61
+			    sizeof ( embedded_images[0] ) ) ; i++ ) {
62
+		image = &embedded_images[i];
29 63
 
30
-	image = alloc_image();
31
-	if (!image)
32
-		return NULL;
64
+		/* virt_to_user() cannot be used in a static
65
+		 * initialiser, so we cast the pointer to a userptr_t
66
+		 * in the initialiser and fix it up here.  (This will
67
+		 * actually be a no-op on most platforms.)
68
+		 */
69
+		data = ( ( void * ) image->data );
70
+		image->data = virt_to_user ( data );
33 71
 
34
-	image->len     = eisize;
35
-	image->data    = umalloc(eisize);
36
-	if (image->data == UNULL) {
37
-		image_put(image);
38
-		return image = NULL;
39
-	}
40
-	copy_to_user(image->data, 0, _embedded_image_start, eisize);
41
-	register_image(image);
72
+		DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
73
+		      image->name, image->len, data );
42 74
 
43
-	/* Reclaim embedded image memory */
44
-	reclaimed = 1;
45
-	mpopulate(_embedded_image_start, eisize);
75
+		if ( ( rc = register_image ( image ) ) != 0 ) {
76
+			DBG ( "Could not register embedded image \"%s\": "
77
+			      "%s\n", image->name, strerror ( rc ) );
78
+			return;
79
+		}
80
+	}
46 81
 
47
-	return image;
82
+	/* Load the first image */
83
+	image = &embedded_images[0];
84
+	if ( ( rc = image_autoload ( image ) ) != 0 ) {
85
+		DBG ( "Could not load embedded image \"%s\": %s\n",
86
+		      image->name, strerror ( rc ) );
87
+		return;
88
+	}
48 89
 }
49 90
 
91
+/** Embedded image initialisation function */
92
+struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = {
93
+	.initialise = embedded_init,
94
+};

+ 0
- 9
src/include/gpxe/embedded.h ファイルの表示

@@ -1,9 +0,0 @@
1
-#ifndef _GPXE_EMBEDDED_H
2
-#define _GPXE_EMBEDDED_H
3
-
4
-#include <gpxe/image.h>
5
-
6
-struct image *embedded_image(void);
7
-
8
-#endif
9
-

+ 1
- 0
src/include/gpxe/errfile.h ファイルの表示

@@ -145,6 +145,7 @@
145 145
 #define ERRFILE_script		      ( ERRFILE_IMAGE | 0x00020000 )
146 146
 #define ERRFILE_segment		      ( ERRFILE_IMAGE | 0x00030000 )
147 147
 #define ERRFILE_efi_image	      ( ERRFILE_IMAGE | 0x00040000 )
148
+#define ERRFILE_embedded	      ( ERRFILE_IMAGE | 0x00050000 )
148 149
 
149 150
 #define ERRFILE_asn1		      ( ERRFILE_OTHER | 0x00000000 )
150 151
 #define ERRFILE_chap		      ( ERRFILE_OTHER | 0x00010000 )

+ 1
- 0
src/include/gpxe/uri.h ファイルの表示

@@ -7,6 +7,7 @@
7 7
  *
8 8
  */
9 9
 
10
+#include <stddef.h>
10 11
 #include <stdlib.h>
11 12
 #include <gpxe/refcnt.h>
12 13
 

+ 0
- 30
src/usr/autoboot.c ファイルの表示

@@ -23,7 +23,6 @@
23 23
 #include <gpxe/dhcp.h>
24 24
 #include <gpxe/settings.h>
25 25
 #include <gpxe/image.h>
26
-#include <gpxe/embedded.h>
27 26
 #include <gpxe/sanboot.h>
28 27
 #include <gpxe/uri.h>
29 28
 #include <usr/ifmgmt.h>
@@ -59,30 +58,6 @@ static struct net_device * find_boot_netdev ( void ) {
59 58
 	return NULL;
60 59
 }
61 60
 
62
-/**
63
- * Boot embedded image
64
- *
65
- * @ret rc		Return status code
66
- */
67
-static int boot_embedded_image ( void ) {
68
-	struct image *image;
69
-	int rc;
70
-
71
-	image = embedded_image();
72
-	if ( !image )
73
-		return ENOENT;
74
-
75
-	if ( ( rc = imgload ( image ) ) != 0 ) {
76
-		printf ( "Could not load embedded image: %s\n",
77
-			 strerror ( rc ) );
78
-	} else if ( ( rc = imgexec ( image ) ) != 0 ) {
79
-		printf ( "Could not boot embedded image: %s\n",
80
-			 strerror ( rc ) );
81
-	}
82
-	image_put ( image );
83
-	return rc;
84
-}
85
-
86 61
 /**
87 62
  * Boot using next-server and filename
88 63
  *
@@ -196,11 +171,6 @@ static int netboot ( struct net_device *netdev ) {
196 171
 		return rc;
197 172
 	route();
198 173
 
199
-	/* Try to boot an embedded image if we have one */
200
-	rc = boot_embedded_image ();
201
-	if ( rc != ENOENT )
202
-		return rc;
203
-
204 174
 	/* Try PXE menu boot, if applicable */
205 175
 	fetch_string_setting ( NULL, &vendor_class_id_setting,
206 176
 			       buf, sizeof ( buf ) );

読み込み中…
キャンセル
保存