瀏覽代碼

Added the embedded pxelinux payload patch from hpa.

tags/v0.9.3
Michael Brown 16 年之前
父節點
當前提交
74fd544101
共有 6 個文件被更改,包括 107 次插入0 次删除
  1. 4
    0
      src/Makefile
  2. 8
    0
      src/Makefile.housekeeping
  3. 7
    0
      src/image/embed.S
  4. 49
    0
      src/image/embedded.c
  5. 9
    0
      src/include/gpxe/embedded.h
  6. 30
    0
      src/usr/autoboot.c

+ 4
- 0
src/Makefile 查看文件

@@ -101,6 +101,10 @@ CFLAGS		+= $(EXTRA_CFLAGS)
101 101
 ASFLAGS		+= $(EXTRA_ASFLAGS)
102 102
 LDFLAGS		+= $(EXTRA_LDFLAGS)
103 103
 
104
+# Embedded image, if present
105
+#
106
+EMBEDDED_IMAGE	?= /dev/null
107
+
104 108
 ifneq ($(NO_WERROR),1)
105 109
 CFLAGS		+= -Werror
106 110
 endif

+ 8
- 0
src/Makefile.housekeeping 查看文件

@@ -214,6 +214,14 @@ drivers :
214 214
 roms :
215 215
 	@$(ECHO) $(ROMS)
216 216
 
217
+# Embedded binary
218
+$(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
219
+	$(QM)$(ECHO) "  [COPY] $@"
220
+	$(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
221
+
222
+$(BIN)/embed.o: $(BIN)/embedimg.bin
223
+CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
224
+
217 225
 # Generate the NIC file from the parsed source files.  The NIC file is
218 226
 # only for rom-o-matic.
219 227
 #

+ 7
- 0
src/image/embed.S 查看文件

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

+ 49
- 0
src/image/embedded.c 查看文件

@@ -0,0 +1,49 @@
1
+/** @file
2
+ *
3
+ * Take a possible embedded image and put it in a struct image
4
+ * data structure.
5
+ */
6
+
7
+#include <stdio.h>
8
+#include <gpxe/image.h>
9
+#include <gpxe/malloc.h>
10
+#include <gpxe/uaccess.h>
11
+#include <gpxe/umalloc.h>
12
+#include <gpxe/embedded.h>
13
+
14
+extern char _embedded_image_start[], _embedded_image_end[];
15
+
16
+struct image *embedded_image(void)
17
+{
18
+	static int reclaimed = 0;
19
+	struct image *image;
20
+	size_t eisize = _embedded_image_end - _embedded_image_start;
21
+
22
+	if ( !eisize )
23
+		return NULL;	/* No embedded image */
24
+
25
+	if ( reclaimed )
26
+		return NULL;	/* Already reclaimed */
27
+
28
+	printf("Embedded image: %d bytes at %p\n",
29
+	       eisize, _embedded_image_start);
30
+
31
+	image = alloc_image();
32
+	if (!image)
33
+		return NULL;
34
+
35
+	image->len     = eisize;
36
+	image->data    = umalloc(eisize);
37
+	if (image->data == UNULL) {
38
+		image_put(image);
39
+		return image = NULL;
40
+	}
41
+	copy_to_user(image->data, 0, _embedded_image_start, eisize);
42
+
43
+	/* Reclaim embedded image memory */
44
+	reclaimed = 1;
45
+	mpopulate(_embedded_image_start, eisize);
46
+
47
+	return image;
48
+}
49
+

+ 9
- 0
src/include/gpxe/embedded.h 查看文件

@@ -0,0 +1,9 @@
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
+

+ 30
- 0
src/usr/autoboot.c 查看文件

@@ -22,6 +22,7 @@
22 22
 #include <gpxe/netdevice.h>
23 23
 #include <gpxe/dhcp.h>
24 24
 #include <gpxe/image.h>
25
+#include <gpxe/embedded.h>
25 26
 #include <usr/ifmgmt.h>
26 27
 #include <usr/route.h>
27 28
 #include <usr/dhcpmgmt.h>
@@ -45,6 +46,30 @@ static struct net_device * find_boot_netdev ( void ) {
45 46
 	return NULL;
46 47
 }
47 48
 
49
+/**
50
+ * Boot embedded image
51
+ *
52
+ * @ret rc		Return status code
53
+ */
54
+static int boot_embedded_image ( void ) {
55
+	struct image *image;
56
+	int rc;
57
+
58
+	image = embedded_image();
59
+	if ( !image )
60
+		return ENOENT;
61
+
62
+	if ( ( rc = imgload ( image ) ) != 0 ) {
63
+		printf ( "Could not load embedded image: %s\n",
64
+			 strerror ( rc ) );
65
+	} else if ( ( rc = imgexec ( image ) ) != 0 ) {
66
+		printf ( "Could not boot embedded image: %s\n",
67
+			 strerror ( rc ) );
68
+	}
69
+	image_put ( image );
70
+	return rc;
71
+}
72
+
48 73
 /**
49 74
  * Boot using filename
50 75
  *
@@ -115,6 +140,11 @@ static int netboot ( struct net_device *netdev ) {
115 140
 		return rc;
116 141
 	route();
117 142
 
143
+	/* Try to boot an embedded image if we have one */
144
+	rc = boot_embedded_image ();
145
+	if ( rc != ENOENT )
146
+		return rc;
147
+
118 148
 	/* Try to download and boot whatever we are given as a filename */
119 149
 	dhcp_snprintf ( buf, sizeof ( buf ),
120 150
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );

Loading…
取消
儲存