Selaa lähdekoodia

Merge branch 'master' of rom.etherboot.org:/pub/scm/gpxe

tags/v0.9.3
Michael Brown 16 vuotta sitten
vanhempi
commit
122abb50af

+ 56
- 54
src/Makefile Näytä tiedosto

1
+# Location to place generated files
2
+#
3
+BIN		:= bin
4
+
1
 # Initialise variables that get added to throughout the various Makefiles
5
 # Initialise variables that get added to throughout the various Makefiles
2
 #
6
 #
3
 MAKEDEPS	:= Makefile .toolcheck .echocheck
7
 MAKEDEPS	:= Makefile .toolcheck .echocheck
9
 MEDIA		:=
13
 MEDIA		:=
10
 NON_AUTO_MEDIA	:=
14
 NON_AUTO_MEDIA	:=
11
 
15
 
12
-# Grab the central Config file.
13
-#
14
-MAKEDEPS	+= Config
15
-include Config
16
-
17
-# Location to place generated files
18
-#
19
-BIN		:= bin
20
-
21
-# If no architecture is specified in Config or on the command-line,
22
-# use that of the build machine.
23
-#
24
-ifndef ARCH
25
-ARCH		:= $(shell uname -m | sed -e s,i[3456789]86,i386,)
26
-endif
27
-
28
-# handle x86_64 like i386, but set -m32 option for 32bit code only
29
-ifeq ($(ARCH),x86_64)
30
-ARCH		:= i386
31
-CFLAGS		+= -m32
32
-ASFLAGS         += --32
33
-LDFLAGS         += -m elf_i386
34
-endif
35
-
36
-# Drag in architecture-specific Config
16
+# Locations of utilities
37
 #
17
 #
38
-MAKEDEPS	+= arch/$(ARCH)/Config
39
-include arch/$(ARCH)/Config
18
+HOST_CC		:= gcc
19
+RM		:= rm -f
20
+TOUCH		:= touch
21
+MKDIR		:= mkdir
22
+CP		:= cp
23
+ECHO		:= echo
24
+PRINTF		:= printf
25
+PERL		:= /usr/bin/perl
26
+CC		:= $(CROSS_COMPILE)gcc
27
+CPP		:= $(CROSS_COMPILE)gcc -E -Wp,-Wall
28
+AS		:= $(CROSS_COMPILE)as
29
+LD		:= $(CROSS_COMPILE)ld
30
+SIZE		:= $(CROSS_COMPILE)size
31
+AR		:= $(CROSS_COMPILE)ar
32
+RANLIB		:= $(CROSS_COMPILE)ranlib
33
+OBJCOPY		:= $(CROSS_COMPILE)objcopy
34
+NM		:= $(CROSS_COMPILE)nm
35
+OBJDUMP		:= $(CROSS_COMPILE)objdump
36
+PARSEROM	:= $(PERL) ./util/parserom.pl
37
+MAKEROM		:= $(PERL) ./util/makerom.pl
38
+MKCONFIG	:= $(PERL) ./util/mkconfig.pl
39
+SYMCHECK	:= $(PERL) ./util/symcheck.pl
40
+SORTOBJDUMP	:= $(PERL) ./util/sortobjdump.pl
41
+NRV2B		:= ./util/nrv2b
42
+ZBIN		:= ./util/zbin
43
+DOXYGEN		:= doxygen
40
 
44
 
41
 # If invoked with no build target, print out a helpfully suggestive
45
 # If invoked with no build target, print out a helpfully suggestive
42
 # message.
46
 # message.
64
 	@$(ECHO)
68
 	@$(ECHO)
65
 	@$(ECHO) '==========================================================='
69
 	@$(ECHO) '==========================================================='
66
 
70
 
67
-# Locations of utilities
71
+# Grab the central Config file.
72
+#
73
+MAKEDEPS	+= Config
74
+include Config
75
+
76
+# If no architecture is specified in Config or on the command-line,
77
+# use that of the build machine.
78
+#
79
+ARCH		?= $(shell uname -m | sed -e s,i[3456789]86,i386,)
80
+
81
+# handle x86_64 like i386, but set -m32 option for 32bit code only
82
+ifeq ($(ARCH),x86_64)
83
+ARCH		:= i386
84
+CFLAGS		+= -m32
85
+ASFLAGS         += --32
86
+LDFLAGS         += -m elf_i386
87
+endif
88
+
89
+# Drag in architecture-specific Config
68
 #
90
 #
69
-HOST_CC		?= gcc
70
-CPP		?= gcc -E -Wp,-Wall
71
-RM		?= rm -f
72
-TOUCH		?= touch
73
-MKDIR		?= mkdir
74
-CP		?= cp
75
-ECHO		?= echo
76
-PRINTF		?= printf
77
-PERL		?= /usr/bin/perl
78
-CC		?= $(CROSS_COMPILE)gcc
79
-AS		?= $(CROSS_COMPILE)as
80
-LD		?= $(CROSS_COMPILE)ld
81
-SIZE		?= $(CROSS_COMPILE)size
82
-AR		?= $(CROSS_COMPILE)ar
83
-RANLIB		?= $(CROSS_COMPILE)ranlib
84
-OBJCOPY		?= $(CROSS_COMPILE)objcopy
85
-NM		?= $(CROSS_COMPILE)nm
86
-OBJDUMP		?= $(CROSS_COMPILE)objdump
87
-PARSEROM	?= $(PERL) ./util/parserom.pl
88
-MAKEROM		?= $(PERL) ./util/makerom.pl
89
-MKCONFIG	?= $(PERL) ./util/mkconfig.pl
90
-SYMCHECK	?= $(PERL) ./util/symcheck.pl
91
-SORTOBJDUMP	?= $(PERL) ./util/sortobjdump.pl
92
-NRV2B		?= ./util/nrv2b
93
-ZBIN		?= ./util/zbin
94
-DOXYGEN		?= doxygen
91
+MAKEDEPS	+= arch/$(ARCH)/Config
92
+include arch/$(ARCH)/Config
95
 
93
 
96
 # Common flags
94
 # Common flags
97
 #
95
 #
103
 ASFLAGS		+= $(EXTRA_ASFLAGS)
101
 ASFLAGS		+= $(EXTRA_ASFLAGS)
104
 LDFLAGS		+= $(EXTRA_LDFLAGS)
102
 LDFLAGS		+= $(EXTRA_LDFLAGS)
105
 
103
 
104
+# Embedded image, if present
105
+#
106
+EMBEDDED_IMAGE	?= /dev/null
107
+
106
 ifneq ($(NO_WERROR),1)
108
 ifneq ($(NO_WERROR),1)
107
 CFLAGS		+= -Werror
109
 CFLAGS		+= -Werror
108
 endif
110
 endif

+ 11
- 0
src/Makefile.housekeeping Näytä tiedosto

214
 roms :
214
 roms :
215
 	@$(ECHO) $(ROMS)
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
 # Generate the NIC file from the parsed source files.  The NIC file is
225
 # Generate the NIC file from the parsed source files.  The NIC file is
218
 # only for rom-o-matic.
226
 # only for rom-o-matic.
219
 #
227
 #
356
 		-Map $(BIN)/$*.tmp.map
364
 		-Map $(BIN)/$*.tmp.map
357
 	$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
365
 	$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
358
 
366
 
367
+# Keep intermediate object file (useful for debugging)
368
+.SECONDARY : $(BIN)/%.tmp
369
+
359
 # Show a linker map for the specified target
370
 # Show a linker map for the specified target
360
 #
371
 #
361
 $(BIN)/%.map : $(BIN)/%.tmp
372
 $(BIN)/%.map : $(BIN)/%.tmp

+ 24
- 45
src/core/downloader.c Näytä tiedosto

96
 	if ( len <= downloader->image->len )
96
 	if ( len <= downloader->image->len )
97
 		return 0;
97
 		return 0;
98
 
98
 
99
+	DBGC ( downloader, "Downloader %p extending to %zd bytes\n",
100
+	       downloader, len );
101
+
99
 	/* Extend buffer */
102
 	/* Extend buffer */
100
 	new_buffer = urealloc ( downloader->image->data, len );
103
 	new_buffer = urealloc ( downloader->image->data, len );
101
 	if ( ! new_buffer ) {
104
 	if ( ! new_buffer ) {
141
  *
144
  *
142
  */
145
  */
143
 
146
 
144
-/**
145
- * Handle seek() event received via data transfer interface
146
- *
147
- * @v xfer		Downloader data transfer interface
148
- * @v pos		New position
149
- * @ret rc		Return status code
150
- */
151
-static int downloader_xfer_seek ( struct xfer_interface *xfer, off_t offset,
152
-				  int whence ) {
153
-	struct downloader *downloader =
154
-		container_of ( xfer, struct downloader, xfer );
155
-	off_t new_pos;
156
-	int rc;
157
-
158
-	/* Calculate new buffer position */
159
-	switch ( whence ) {
160
-	case SEEK_SET:
161
-		new_pos = offset;
162
-		break;
163
-	case SEEK_CUR:
164
-		new_pos = ( downloader->pos + offset );
165
-		break;
166
-	default:
167
-		assert ( 0 );
168
-		return -EINVAL;
169
-	}
170
-
171
-	/* Ensure that we have enough buffer space for this buffer position */
172
-	if ( ( rc = downloader_ensure_size ( downloader, new_pos ) ) != 0 )
173
-		return rc;
174
-	downloader->pos = new_pos;
175
-
176
-	return 0;
177
-}
178
-
179
 /**
147
 /**
180
  * Handle deliver_raw() event received via data transfer interface
148
  * Handle deliver_raw() event received via data transfer interface
181
  *
149
  *
182
  * @v xfer		Downloader data transfer interface
150
  * @v xfer		Downloader data transfer interface
183
- * @v data		Data buffer
184
- * @v len		Length of data buffer
151
+ * @v iobuf		Datagram I/O buffer
152
+ * @v meta		Data transfer metadata
185
  * @ret rc		Return status code
153
  * @ret rc		Return status code
186
  */
154
  */
187
-static int downloader_xfer_deliver_raw ( struct xfer_interface *xfer,
188
-					 const void *data, size_t len ) {
155
+static int downloader_xfer_deliver_iob ( struct xfer_interface *xfer,
156
+					 struct io_buffer *iobuf,
157
+					 struct xfer_metadata *meta ) {
189
 	struct downloader *downloader =
158
 	struct downloader *downloader =
190
 		container_of ( xfer, struct downloader, xfer );
159
 		container_of ( xfer, struct downloader, xfer );
160
+	size_t len;
191
 	size_t max;
161
 	size_t max;
192
 	int rc;
162
 	int rc;
193
 
163
 
164
+	/* Calculate new buffer position */
165
+	if ( meta->whence != SEEK_CUR )
166
+		downloader->pos = 0;
167
+	downloader->pos += meta->offset;
168
+
194
 	/* Ensure that we have enough buffer space for this data */
169
 	/* Ensure that we have enough buffer space for this data */
170
+	len = iob_len ( iobuf );
195
 	max = ( downloader->pos + len );
171
 	max = ( downloader->pos + len );
196
 	if ( ( rc = downloader_ensure_size ( downloader, max ) ) != 0 )
172
 	if ( ( rc = downloader_ensure_size ( downloader, max ) ) != 0 )
197
-		return rc;
173
+		goto done;
198
 
174
 
199
 	/* Copy data to buffer */
175
 	/* Copy data to buffer */
200
-	copy_to_user ( downloader->image->data, downloader->pos, data, len );
176
+	copy_to_user ( downloader->image->data, downloader->pos,
177
+		       iobuf->data, len );
201
 
178
 
202
 	/* Update current buffer position */
179
 	/* Update current buffer position */
203
 	downloader->pos += len;
180
 	downloader->pos += len;
204
 
181
 
205
-	return 0;
182
+ done:
183
+	free_iob ( iobuf );
184
+	return rc;
206
 }
185
 }
207
 
186
 
208
 /**
187
 /**
227
 static struct xfer_interface_operations downloader_xfer_operations = {
206
 static struct xfer_interface_operations downloader_xfer_operations = {
228
 	.close		= downloader_xfer_close,
207
 	.close		= downloader_xfer_close,
229
 	.vredirect	= xfer_vopen,
208
 	.vredirect	= xfer_vopen,
230
-	.seek		= downloader_xfer_seek,
231
 	.window		= unlimited_xfer_window,
209
 	.window		= unlimited_xfer_window,
232
-	.deliver_iob	= xfer_deliver_as_raw,
233
-	.deliver_raw	= downloader_xfer_deliver_raw,
210
+	.alloc_iob	= default_xfer_alloc_iob,
211
+	.deliver_iob	= downloader_xfer_deliver_iob,
212
+	.deliver_raw	= xfer_deliver_as_iob,
234
 };
213
 };
235
 
214
 
236
 /****************************************************************************
215
 /****************************************************************************

+ 0
- 6
src/core/filter.c Näytä tiedosto

44
 	return xfer_vredirect ( other, type, args );
44
 	return xfer_vredirect ( other, type, args );
45
 }
45
 }
46
 
46
 
47
-int filter_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
48
-	struct xfer_interface *other = filter_other_half ( xfer );
49
-
50
-	return xfer_seek ( other, offset, whence );
51
-}
52
-
53
 size_t filter_window ( struct xfer_interface *xfer ) {
47
 size_t filter_window ( struct xfer_interface *xfer ) {
54
 	struct xfer_interface *other = filter_other_half ( xfer );
48
 	struct xfer_interface *other = filter_other_half ( xfer );
55
 
49
 

+ 1
- 1
src/core/hw.c Näytä tiedosto

36
 static struct xfer_interface_operations hw_xfer_operations = {
36
 static struct xfer_interface_operations hw_xfer_operations = {
37
 	.close		= hw_xfer_close,
37
 	.close		= hw_xfer_close,
38
 	.vredirect	= ignore_xfer_vredirect,
38
 	.vredirect	= ignore_xfer_vredirect,
39
-	.seek		= ignore_xfer_seek,
40
 	.window		= unlimited_xfer_window,
39
 	.window		= unlimited_xfer_window,
40
+	.alloc_iob	= default_xfer_alloc_iob,
41
 	.deliver_iob	= xfer_deliver_as_raw,
41
 	.deliver_iob	= xfer_deliver_as_raw,
42
 	.deliver_raw	= ignore_xfer_deliver_raw,
42
 	.deliver_raw	= ignore_xfer_deliver_raw,
43
 };
43
 };

+ 8
- 29
src/core/posix_io.c Näytä tiedosto

103
 	posix_file_finished ( file, rc );
103
 	posix_file_finished ( file, rc );
104
 }
104
 }
105
 
105
 
106
-/**
107
- * Handle seek() event
108
- *
109
- * @v xfer		POSIX file data transfer interface
110
- * @v pos		New position
111
- * @ret rc		Return status code
112
- */
113
-static int posix_file_xfer_seek ( struct xfer_interface *xfer, off_t offset,
114
-				  int whence ) {
115
-	struct posix_file *file =
116
-		container_of ( xfer, struct posix_file, xfer );
117
-
118
-	switch ( whence ) {
119
-	case SEEK_SET:
120
-		file->pos = offset;
121
-		break;
122
-	case SEEK_CUR:
123
-		file->pos += offset;
124
-		break;
125
-	}
126
-
127
-	if ( file->filesize < file->pos )
128
-		file->filesize = file->pos;
129
-
130
-	return 0;
131
-}
132
-
133
 /**
106
 /**
134
  * Handle deliver_iob() event
107
  * Handle deliver_iob() event
135
  *
108
  *
136
  * @v xfer		POSIX file data transfer interface
109
  * @v xfer		POSIX file data transfer interface
137
  * @v iobuf		I/O buffer
110
  * @v iobuf		I/O buffer
138
- * @v meta		Data transfer metadata, or NULL
111
+ * @v meta		Data transfer metadata
139
  * @ret rc		Return status code
112
  * @ret rc		Return status code
140
  */
113
  */
141
 static int
114
 static int
145
 	struct posix_file *file =
118
 	struct posix_file *file =
146
 		container_of ( xfer, struct posix_file, xfer );
119
 		container_of ( xfer, struct posix_file, xfer );
147
 
120
 
121
+	/* Keep track of file position solely for the filesize */
122
+	if ( meta->whence != SEEK_CUR )
123
+		file->pos = 0;
124
+	file->pos += meta->offset;
125
+	if ( file->filesize < file->pos )
126
+		file->filesize = file->pos;
127
+
148
 	list_add_tail ( &iobuf->list, &file->data );
128
 	list_add_tail ( &iobuf->list, &file->data );
149
 	return 0;
129
 	return 0;
150
 }
130
 }
153
 static struct xfer_interface_operations posix_file_xfer_operations = {
133
 static struct xfer_interface_operations posix_file_xfer_operations = {
154
 	.close		= posix_file_xfer_close,
134
 	.close		= posix_file_xfer_close,
155
 	.vredirect	= xfer_vopen,
135
 	.vredirect	= xfer_vopen,
156
-	.seek		= posix_file_xfer_seek,
157
 	.window		= unlimited_xfer_window,
136
 	.window		= unlimited_xfer_window,
158
 	.alloc_iob	= default_xfer_alloc_iob,
137
 	.alloc_iob	= default_xfer_alloc_iob,
159
 	.deliver_iob	= posix_file_xfer_deliver_iob,
138
 	.deliver_iob	= posix_file_xfer_deliver_iob,

+ 0
- 1
src/core/resolv.c Näytä tiedosto

312
 static struct xfer_interface_operations named_xfer_ops = {
312
 static struct xfer_interface_operations named_xfer_ops = {
313
 	.close		= ignore_xfer_close,
313
 	.close		= ignore_xfer_close,
314
 	.vredirect	= ignore_xfer_vredirect,
314
 	.vredirect	= ignore_xfer_vredirect,
315
-	.seek		= ignore_xfer_seek,
316
 	.window		= no_xfer_window,
315
 	.window		= no_xfer_window,
317
 	.alloc_iob	= default_xfer_alloc_iob,
316
 	.alloc_iob	= default_xfer_alloc_iob,
318
 	.deliver_iob	= xfer_deliver_as_raw,
317
 	.deliver_iob	= xfer_deliver_as_raw,

+ 28
- 41
src/core/xfer.c Näytä tiedosto

85
 	return rc;
85
 	return rc;
86
 }
86
 }
87
 
87
 
88
-/**
89
- * Seek to position
90
- *
91
- * @v xfer		Data transfer interface
92
- * @v offset		Offset to new position
93
- * @v whence		Basis for new position
94
- * @ret rc		Return status code
95
- */
96
-int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
97
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
98
-	int rc;
99
-
100
-	DBGC ( xfer, "XFER %p->%p seek %s+%ld\n", xfer, dest,
101
-	       whence_text ( whence ), offset );
102
-
103
-	rc = dest->op->seek ( dest, offset, whence );
104
-
105
-	if ( rc != 0 ) {
106
-		DBGC ( xfer, "XFER %p<-%p seek: %s\n", xfer, dest,
107
-		       strerror ( rc ) );
108
-	}
109
-	xfer_put ( dest );
110
-	return rc;
111
-}
112
-
113
 /**
88
 /**
114
  * Check flow control window
89
  * Check flow control window
115
  *
90
  *
153
  *
128
  *
154
  * @v xfer		Data transfer interface
129
  * @v xfer		Data transfer interface
155
  * @v iobuf		Datagram I/O buffer
130
  * @v iobuf		Datagram I/O buffer
156
- * @v meta		Data transfer metadata, or NULL
131
+ * @v meta		Data transfer metadata
157
  * @ret rc		Return status code
132
  * @ret rc		Return status code
158
  */
133
  */
159
 int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
134
 int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
184
  */
159
  */
185
 int xfer_deliver_iob ( struct xfer_interface *xfer,
160
 int xfer_deliver_iob ( struct xfer_interface *xfer,
186
 		       struct io_buffer *iobuf ) {
161
 		       struct io_buffer *iobuf ) {
187
-	return xfer_deliver_iob_meta ( xfer, iobuf, NULL );
162
+	static struct xfer_metadata dummy_metadata;
163
+	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
188
 }
164
 }
189
 
165
 
190
 /**
166
 /**
253
 	return rc;
229
 	return rc;
254
 }
230
 }
255
 
231
 
232
+/**
233
+ * Seek to position
234
+ *
235
+ * @v xfer		Data transfer interface
236
+ * @v offset		Offset to new position
237
+ * @v whence		Basis for new position
238
+ * @ret rc		Return status code
239
+ */
240
+int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
241
+	struct io_buffer *iobuf;
242
+	struct xfer_metadata meta = {
243
+		.offset = offset,
244
+		.whence = whence,
245
+	};
246
+
247
+	DBGC ( xfer, "XFER %p seek %s+%ld\n", xfer,
248
+	       whence_text ( whence ), offset );
249
+
250
+	/* Allocate and send a zero-length data buffer */
251
+	iobuf = xfer_alloc_iob ( xfer, 0 );
252
+	if ( ! iobuf )
253
+		return -ENOMEM;
254
+	return xfer_deliver_iob_meta ( xfer, iobuf, &meta );
255
+}
256
+
256
 /****************************************************************************
257
 /****************************************************************************
257
  *
258
  *
258
  * Helper methods
259
  * Helper methods
286
 	return 0;
287
 	return 0;
287
 }
288
 }
288
 
289
 
289
-/**
290
- * Ignore seek() event
291
- *
292
- * @v xfer		Data transfer interface
293
- * @v offset		Offset to new position
294
- * @v whence		Basis for new position
295
- * @ret rc		Return status code
296
- */
297
-int ignore_xfer_seek ( struct xfer_interface *xfer __unused,
298
-		       off_t offset __unused, int whence __unused ) {
299
-	return 0;
300
-}
301
-
302
 /**
290
 /**
303
  * Unlimited flow control window
291
  * Unlimited flow control window
304
  *
292
  *
401
 struct xfer_interface_operations null_xfer_ops = {
389
 struct xfer_interface_operations null_xfer_ops = {
402
 	.close		= ignore_xfer_close,
390
 	.close		= ignore_xfer_close,
403
 	.vredirect	= ignore_xfer_vredirect,
391
 	.vredirect	= ignore_xfer_vredirect,
404
-	.seek		= ignore_xfer_seek,
405
 	.window		= unlimited_xfer_window,
392
 	.window		= unlimited_xfer_window,
406
 	.alloc_iob	= default_xfer_alloc_iob,
393
 	.alloc_iob	= default_xfer_alloc_iob,
407
 	.deliver_iob	= xfer_deliver_as_raw,
394
 	.deliver_iob	= xfer_deliver_as_raw,

+ 7
- 0
src/image/embed.S Näytä tiedosto

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 Näytä tiedosto

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 Näytä tiedosto

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
+

+ 0
- 2
src/include/gpxe/filter.h Näytä tiedosto

41
 extern void filter_close ( struct xfer_interface *xfer, int rc );
41
 extern void filter_close ( struct xfer_interface *xfer, int rc );
42
 extern int filter_vredirect ( struct xfer_interface *xfer, int type,
42
 extern int filter_vredirect ( struct xfer_interface *xfer, int type,
43
 			      va_list args );
43
 			      va_list args );
44
-extern int filter_seek ( struct xfer_interface *xfer, off_t offset,
45
-			 int whence );
46
 extern size_t filter_window ( struct xfer_interface *xfer );
44
 extern size_t filter_window ( struct xfer_interface *xfer );
47
 extern struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
45
 extern struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
48
 					     size_t len );
46
 					     size_t len );

+ 16
- 22
src/include/gpxe/xfer.h Näytä tiedosto

32
 	 */
32
 	 */
33
 	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
33
 	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
34
 			      va_list args );
34
 			      va_list args );
35
-	/** Seek to position
36
-	 *
37
-	 * @v xfer		Data transfer interface
38
-	 * @v offset		Offset to new position
39
-	 * @v whence		Basis for new position
40
-	 * @ret rc		Return status code
41
-	 *
42
-	 * @c whence must be one of @c SEEK_SET or @c SEEK_CUR.
43
-	 */
44
-	int ( * seek ) ( struct xfer_interface *xfer, off_t offset,
45
-			 int whence );
46
 	/** Check flow control window
35
 	/** Check flow control window
47
 	 *
36
 	 *
48
 	 * @v xfer		Data transfer interface
37
 	 * @v xfer		Data transfer interface
71
 	 *
60
 	 *
72
 	 * @v xfer		Data transfer interface
61
 	 * @v xfer		Data transfer interface
73
 	 * @v iobuf		Datagram I/O buffer
62
 	 * @v iobuf		Datagram I/O buffer
74
-	 * @v meta		Data transfer metadata, or NULL
63
+	 * @v meta		Data transfer metadata
75
 	 * @ret rc		Return status code
64
 	 * @ret rc		Return status code
76
 	 *
65
 	 *
77
 	 * A data transfer interface that wishes to support only raw
66
 	 * A data transfer interface that wishes to support only raw
104
 	struct xfer_interface_operations *op;
93
 	struct xfer_interface_operations *op;
105
 };
94
 };
106
 
95
 
96
+/** Basis positions for seek() events */
97
+enum seek_whence {
98
+	SEEK_CUR = 0,
99
+	SEEK_SET,
100
+};
101
+
107
 /** Data transfer metadata */
102
 /** Data transfer metadata */
108
 struct xfer_metadata {
103
 struct xfer_metadata {
104
+	/** Position of data within stream */
105
+	off_t offset;
106
+	/** Basis for data position
107
+	 *
108
+	 * Must be one of @c SEEK_CUR or @c SEEK_SET.
109
+	 */
110
+	int whence;
109
 	/** Source socket address, or NULL */
111
 	/** Source socket address, or NULL */
110
 	struct sockaddr *src;
112
 	struct sockaddr *src;
111
 	/** Destination socket address, or NULL */
113
 	/** Destination socket address, or NULL */
114
 	struct net_device *netdev;
116
 	struct net_device *netdev;
115
 };
117
 };
116
 
118
 
117
-/** Basis positions for seek() events */
118
-enum seek_whence {
119
-	SEEK_SET = 0,
120
-	SEEK_CUR,
121
-};
122
-
123
 /**
119
 /**
124
  * Describe seek basis
120
  * Describe seek basis
125
  *
121
  *
128
 static inline __attribute__ (( always_inline )) const char *
124
 static inline __attribute__ (( always_inline )) const char *
129
 whence_text ( int whence ) {
125
 whence_text ( int whence ) {
130
 	switch ( whence ) {
126
 	switch ( whence ) {
131
-	case SEEK_SET:	return "SET";
132
 	case SEEK_CUR:	return "CUR";
127
 	case SEEK_CUR:	return "CUR";
128
+	case SEEK_SET:	return "SET";
133
 	default:	return "INVALID";
129
 	default:	return "INVALID";
134
 	}
130
 	}
135
 }
131
 }
141
 extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
137
 extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
142
 			    va_list args );
138
 			    va_list args );
143
 extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... );
139
 extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... );
144
-extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
145
 extern size_t xfer_window ( struct xfer_interface *xfer );
140
 extern size_t xfer_window ( struct xfer_interface *xfer );
146
 extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
141
 extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
147
 					   size_t len );
142
 					   size_t len );
156
 			  const char *format, va_list args );
151
 			  const char *format, va_list args );
157
 extern int xfer_printf ( struct xfer_interface *xfer,
152
 extern int xfer_printf ( struct xfer_interface *xfer,
158
 			 const char *format, ... );
153
 			 const char *format, ... );
154
+extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
159
 
155
 
160
 extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
156
 extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
161
 extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
157
 extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
162
 				   int type, va_list args );
158
 				   int type, va_list args );
163
-extern int ignore_xfer_seek ( struct xfer_interface *xfer, off_t offset,
164
-			      int whence );
165
 extern size_t unlimited_xfer_window ( struct xfer_interface *xfer );
159
 extern size_t unlimited_xfer_window ( struct xfer_interface *xfer );
166
 extern size_t no_xfer_window ( struct xfer_interface *xfer );
160
 extern size_t no_xfer_window ( struct xfer_interface *xfer );
167
 extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,
161
 extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,

+ 0
- 1
src/interface/pxe/pxe_udp.c Näytä tiedosto

103
 static struct xfer_interface_operations pxe_udp_xfer_operations = {
103
 static struct xfer_interface_operations pxe_udp_xfer_operations = {
104
 	.close		= ignore_xfer_close,
104
 	.close		= ignore_xfer_close,
105
 	.vredirect	= ignore_xfer_vredirect,
105
 	.vredirect	= ignore_xfer_vredirect,
106
-	.seek		= ignore_xfer_seek,
107
 	.window		= unlimited_xfer_window,
106
 	.window		= unlimited_xfer_window,
108
 	.alloc_iob	= default_xfer_alloc_iob,
107
 	.alloc_iob	= default_xfer_alloc_iob,
109
 	.deliver_iob	= pxe_udp_deliver_iob,
108
 	.deliver_iob	= pxe_udp_deliver_iob,

+ 0
- 1
src/net/tcp.c Näytä tiedosto

1022
 static struct xfer_interface_operations tcp_xfer_operations = {
1022
 static struct xfer_interface_operations tcp_xfer_operations = {
1023
 	.close		= tcp_xfer_close,
1023
 	.close		= tcp_xfer_close,
1024
 	.vredirect	= ignore_xfer_vredirect,
1024
 	.vredirect	= ignore_xfer_vredirect,
1025
-	.seek		= ignore_xfer_seek,
1026
 	.window		= tcp_xfer_window,
1025
 	.window		= tcp_xfer_window,
1027
 	.alloc_iob	= default_xfer_alloc_iob,
1026
 	.alloc_iob	= default_xfer_alloc_iob,
1028
 	.deliver_iob	= tcp_xfer_deliver_iob,
1027
 	.deliver_iob	= tcp_xfer_deliver_iob,

+ 0
- 3
src/net/tcp/ftp.c Näytä tiedosto

299
 static struct xfer_interface_operations ftp_control_operations = {
299
 static struct xfer_interface_operations ftp_control_operations = {
300
 	.close		= ftp_control_close,
300
 	.close		= ftp_control_close,
301
 	.vredirect	= xfer_vopen,
301
 	.vredirect	= xfer_vopen,
302
-	.seek		= ignore_xfer_seek,
303
 	.window		= unlimited_xfer_window,
302
 	.window		= unlimited_xfer_window,
304
 	.alloc_iob	= default_xfer_alloc_iob,
303
 	.alloc_iob	= default_xfer_alloc_iob,
305
 	.deliver_iob	= xfer_deliver_as_raw,
304
 	.deliver_iob	= xfer_deliver_as_raw,
364
 static struct xfer_interface_operations ftp_data_operations = {
363
 static struct xfer_interface_operations ftp_data_operations = {
365
 	.close		= ftp_data_closed,
364
 	.close		= ftp_data_closed,
366
 	.vredirect	= xfer_vopen,
365
 	.vredirect	= xfer_vopen,
367
-	.seek		= ignore_xfer_seek,
368
 	.window		= unlimited_xfer_window,
366
 	.window		= unlimited_xfer_window,
369
 	.alloc_iob	= default_xfer_alloc_iob,
367
 	.alloc_iob	= default_xfer_alloc_iob,
370
 	.deliver_iob	= ftp_data_deliver_iob,
368
 	.deliver_iob	= ftp_data_deliver_iob,
397
 static struct xfer_interface_operations ftp_xfer_operations = {
395
 static struct xfer_interface_operations ftp_xfer_operations = {
398
 	.close		= ftp_xfer_closed,
396
 	.close		= ftp_xfer_closed,
399
 	.vredirect	= ignore_xfer_vredirect,
397
 	.vredirect	= ignore_xfer_vredirect,
400
-	.seek		= ignore_xfer_seek,
401
 	.window		= unlimited_xfer_window,
398
 	.window		= unlimited_xfer_window,
402
 	.alloc_iob	= default_xfer_alloc_iob,
399
 	.alloc_iob	= default_xfer_alloc_iob,
403
 	.deliver_iob	= xfer_deliver_as_raw,
400
 	.deliver_iob	= xfer_deliver_as_raw,

+ 0
- 2
src/net/tcp/http.c Näytä tiedosto

426
 static struct xfer_interface_operations http_socket_operations = {
426
 static struct xfer_interface_operations http_socket_operations = {
427
 	.close		= http_socket_close,
427
 	.close		= http_socket_close,
428
 	.vredirect	= xfer_vopen,
428
 	.vredirect	= xfer_vopen,
429
-	.seek		= ignore_xfer_seek,
430
 	.window		= unlimited_xfer_window,
429
 	.window		= unlimited_xfer_window,
431
 	.alloc_iob	= default_xfer_alloc_iob,
430
 	.alloc_iob	= default_xfer_alloc_iob,
432
 	.deliver_iob	= http_socket_deliver_iob,
431
 	.deliver_iob	= http_socket_deliver_iob,
453
 static struct xfer_interface_operations http_xfer_operations = {
452
 static struct xfer_interface_operations http_xfer_operations = {
454
 	.close		= http_xfer_close,
453
 	.close		= http_xfer_close,
455
 	.vredirect	= ignore_xfer_vredirect,
454
 	.vredirect	= ignore_xfer_vredirect,
456
-	.seek		= ignore_xfer_seek,
457
 	.window		= unlimited_xfer_window,
455
 	.window		= unlimited_xfer_window,
458
 	.alloc_iob	= default_xfer_alloc_iob,
456
 	.alloc_iob	= default_xfer_alloc_iob,
459
 	.deliver_iob	= xfer_deliver_as_raw,
457
 	.deliver_iob	= xfer_deliver_as_raw,

+ 1
- 2
src/net/tcp/iscsi.c Näytä tiedosto

684
 	/* Process challenge an octet at a time */
684
 	/* Process challenge an octet at a time */
685
 	for ( ; ( value[0] && value[1] ) ; value += 2 ) {
685
 	for ( ; ( value[0] && value[1] ) ; value += 2 ) {
686
 		memcpy ( buf, value, 2 );
686
 		memcpy ( buf, value, 2 );
687
-		buf[3] = 0;
687
+		buf[2] = 0;
688
 		byte = strtoul ( buf, &endp, 16 );
688
 		byte = strtoul ( buf, &endp, 16 );
689
 		if ( *endp != '\0' ) {
689
 		if ( *endp != '\0' ) {
690
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
690
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
1322
 static struct xfer_interface_operations iscsi_socket_operations = {
1322
 static struct xfer_interface_operations iscsi_socket_operations = {
1323
 	.close		= iscsi_socket_close,
1323
 	.close		= iscsi_socket_close,
1324
 	.vredirect	= iscsi_vredirect,
1324
 	.vredirect	= iscsi_vredirect,
1325
-	.seek		= ignore_xfer_seek,
1326
 	.window		= unlimited_xfer_window,
1325
 	.window		= unlimited_xfer_window,
1327
 	.alloc_iob	= default_xfer_alloc_iob,
1326
 	.alloc_iob	= default_xfer_alloc_iob,
1328
 	.deliver_iob	= xfer_deliver_as_raw,
1327
 	.deliver_iob	= xfer_deliver_as_raw,

+ 0
- 2
src/net/tls.c Näytä tiedosto

1460
 static struct xfer_interface_operations tls_plainstream_operations = {
1460
 static struct xfer_interface_operations tls_plainstream_operations = {
1461
 	.close		= tls_plainstream_close,
1461
 	.close		= tls_plainstream_close,
1462
 	.vredirect	= ignore_xfer_vredirect,
1462
 	.vredirect	= ignore_xfer_vredirect,
1463
-	.seek		= filter_seek,
1464
 	.window		= tls_plainstream_window,
1463
 	.window		= tls_plainstream_window,
1465
 	.alloc_iob	= default_xfer_alloc_iob,
1464
 	.alloc_iob	= default_xfer_alloc_iob,
1466
 	.deliver_iob	= xfer_deliver_as_raw,
1465
 	.deliver_iob	= xfer_deliver_as_raw,
1600
 static struct xfer_interface_operations tls_cipherstream_operations = {
1599
 static struct xfer_interface_operations tls_cipherstream_operations = {
1601
 	.close		= tls_cipherstream_close,
1600
 	.close		= tls_cipherstream_close,
1602
 	.vredirect	= xfer_vopen,
1601
 	.vredirect	= xfer_vopen,
1603
-	.seek		= filter_seek,
1604
 	.window		= filter_window,
1602
 	.window		= filter_window,
1605
 	.alloc_iob	= default_xfer_alloc_iob,
1603
 	.alloc_iob	= default_xfer_alloc_iob,
1606
 	.deliver_iob	= xfer_deliver_as_raw,
1604
 	.deliver_iob	= xfer_deliver_as_raw,

+ 0
- 1
src/net/udp.c Näytä tiedosto

415
 static struct xfer_interface_operations udp_xfer_operations = {
415
 static struct xfer_interface_operations udp_xfer_operations = {
416
 	.close		= udp_xfer_close,
416
 	.close		= udp_xfer_close,
417
 	.vredirect	= ignore_xfer_vredirect,
417
 	.vredirect	= ignore_xfer_vredirect,
418
-	.seek		= ignore_xfer_seek,
419
 	.window		= unlimited_xfer_window,
418
 	.window		= unlimited_xfer_window,
420
 	.alloc_iob	= udp_alloc_iob,
419
 	.alloc_iob	= udp_alloc_iob,
421
 	.deliver_iob	= udp_xfer_deliver_iob,
420
 	.deliver_iob	= udp_xfer_deliver_iob,

+ 9
- 7
src/net/udp/dhcp.c Näytä tiedosto

368
  * @v max_len		Field length
368
  * @v max_len		Field length
369
  * @v tag		DHCP option tag, or 0
369
  * @v tag		DHCP option tag, or 0
370
  *
370
  *
371
- * If @c tag is non-zero, the field will be treated as a
372
- * NUL-terminated string representing the value of the specified DHCP
373
- * option.  If @c tag is zero, the field will be treated as a block of
374
- * DHCP options, and simply appended to the existing options in the
375
- * option block.
371
+ * If @c tag is non-zero (and the field is not empty), the field will
372
+ * be treated as a NUL-terminated string representing the value of the
373
+ * specified DHCP option.  If @c tag is zero, the field will be
374
+ * treated as a block of DHCP options, and simply appended to the
375
+ * existing options in the option block.
376
  *
376
  *
377
  * The caller must ensure that there is enough space in the options
377
  * The caller must ensure that there is enough space in the options
378
  * block to perform the merge.
378
  * block to perform the merge.
385
 	struct dhcp_option *end;
385
 	struct dhcp_option *end;
386
 
386
 
387
 	if ( tag ) {
387
 	if ( tag ) {
388
-		set_dhcp_option ( options, tag, data, strlen ( data ) );
388
+		len = strlen ( data );
389
+		if ( len )
390
+			set_dhcp_option ( options, tag, data, len );
389
 	} else {
391
 	} else {
390
 		len = dhcp_field_len ( data, max_len );
392
 		len = dhcp_field_len ( data, max_len );
391
 		dest = ( options->data + options->len - 1 );
393
 		dest = ( options->data + options->len - 1 );
925
 static struct xfer_interface_operations dhcp_xfer_operations = {
927
 static struct xfer_interface_operations dhcp_xfer_operations = {
926
 	.close		= ignore_xfer_close,
928
 	.close		= ignore_xfer_close,
927
 	.vredirect	= xfer_vopen,
929
 	.vredirect	= xfer_vopen,
928
-	.seek		= ignore_xfer_seek,
929
 	.window		= unlimited_xfer_window,
930
 	.window		= unlimited_xfer_window,
931
+	.alloc_iob	= default_xfer_alloc_iob,
930
 	.deliver_iob	= xfer_deliver_as_raw,
932
 	.deliver_iob	= xfer_deliver_as_raw,
931
 	.deliver_raw	= dhcp_deliver_raw,
933
 	.deliver_raw	= dhcp_deliver_raw,
932
 };
934
 };

+ 0
- 1
src/net/udp/dns.c Näytä tiedosto

435
 static struct xfer_interface_operations dns_socket_operations = {
435
 static struct xfer_interface_operations dns_socket_operations = {
436
 	.close		= dns_xfer_close,
436
 	.close		= dns_xfer_close,
437
 	.vredirect	= xfer_vopen,
437
 	.vredirect	= xfer_vopen,
438
-	.seek		= ignore_xfer_seek,
439
 	.window		= unlimited_xfer_window,
438
 	.window		= unlimited_xfer_window,
440
 	.alloc_iob	= default_xfer_alloc_iob,
439
 	.alloc_iob	= default_xfer_alloc_iob,
441
 	.deliver_iob	= xfer_deliver_as_raw,
440
 	.deliver_iob	= xfer_deliver_as_raw,

+ 5
- 5
src/net/udp/tftp.c Näytä tiedosto

703
 static int tftp_rx_data ( struct tftp_request *tftp,
703
 static int tftp_rx_data ( struct tftp_request *tftp,
704
 			  struct io_buffer *iobuf ) {
704
 			  struct io_buffer *iobuf ) {
705
 	struct tftp_data *data = iobuf->data;
705
 	struct tftp_data *data = iobuf->data;
706
+	struct xfer_metadata meta;
706
 	int block;
707
 	int block;
707
 	off_t offset;
708
 	off_t offset;
708
 	size_t data_len;
709
 	size_t data_len;
729
 	}
730
 	}
730
 
731
 
731
 	/* Deliver data */
732
 	/* Deliver data */
732
-	xfer_seek ( &tftp->xfer, offset, SEEK_SET );
733
-	rc = xfer_deliver_iob ( &tftp->xfer, iobuf );
733
+	memset ( &meta, 0, sizeof ( meta ) );
734
+	meta.whence = SEEK_SET;
735
+	meta.offset = offset;
736
+	rc = xfer_deliver_iob_meta ( &tftp->xfer, iobuf, &meta );
734
 	iobuf = NULL;
737
 	iobuf = NULL;
735
 	if ( rc != 0 ) {
738
 	if ( rc != 0 ) {
736
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
739
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
909
 static struct xfer_interface_operations tftp_socket_operations = {
912
 static struct xfer_interface_operations tftp_socket_operations = {
910
 	.close		= ignore_xfer_close,
913
 	.close		= ignore_xfer_close,
911
 	.vredirect	= xfer_vopen,
914
 	.vredirect	= xfer_vopen,
912
-	.seek		= ignore_xfer_seek,
913
 	.window		= unlimited_xfer_window,
915
 	.window		= unlimited_xfer_window,
914
 	.alloc_iob	= default_xfer_alloc_iob,
916
 	.alloc_iob	= default_xfer_alloc_iob,
915
 	.deliver_iob	= tftp_socket_deliver_iob,
917
 	.deliver_iob	= tftp_socket_deliver_iob,
937
 static struct xfer_interface_operations tftp_mc_socket_operations = {
939
 static struct xfer_interface_operations tftp_mc_socket_operations = {
938
 	.close		= ignore_xfer_close,
940
 	.close		= ignore_xfer_close,
939
 	.vredirect	= xfer_vopen,
941
 	.vredirect	= xfer_vopen,
940
-	.seek		= ignore_xfer_seek,
941
 	.window		= unlimited_xfer_window,
942
 	.window		= unlimited_xfer_window,
942
 	.alloc_iob	= default_xfer_alloc_iob,
943
 	.alloc_iob	= default_xfer_alloc_iob,
943
 	.deliver_iob	= tftp_mc_socket_deliver_iob,
944
 	.deliver_iob	= tftp_mc_socket_deliver_iob,
964
 static struct xfer_interface_operations tftp_xfer_operations = {
965
 static struct xfer_interface_operations tftp_xfer_operations = {
965
 	.close		= tftp_xfer_close,
966
 	.close		= tftp_xfer_close,
966
 	.vredirect	= ignore_xfer_vredirect,
967
 	.vredirect	= ignore_xfer_vredirect,
967
-	.seek		= ignore_xfer_seek,
968
 	.window		= unlimited_xfer_window,
968
 	.window		= unlimited_xfer_window,
969
 	.alloc_iob	= default_xfer_alloc_iob,
969
 	.alloc_iob	= default_xfer_alloc_iob,
970
 	.deliver_iob	= xfer_deliver_as_raw,
970
 	.deliver_iob	= xfer_deliver_as_raw,

+ 30
- 0
src/usr/autoboot.c Näytä tiedosto

22
 #include <gpxe/netdevice.h>
22
 #include <gpxe/netdevice.h>
23
 #include <gpxe/dhcp.h>
23
 #include <gpxe/dhcp.h>
24
 #include <gpxe/image.h>
24
 #include <gpxe/image.h>
25
+#include <gpxe/embedded.h>
25
 #include <usr/ifmgmt.h>
26
 #include <usr/ifmgmt.h>
26
 #include <usr/route.h>
27
 #include <usr/route.h>
27
 #include <usr/dhcpmgmt.h>
28
 #include <usr/dhcpmgmt.h>
45
 	return NULL;
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
  * Boot using filename
74
  * Boot using filename
50
  *
75
  *
115
 		return rc;
140
 		return rc;
116
 	route();
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
 	/* Try to download and boot whatever we are given as a filename */
148
 	/* Try to download and boot whatever we are given as a filename */
119
 	dhcp_snprintf ( buf, sizeof ( buf ),
149
 	dhcp_snprintf ( buf, sizeof ( buf ),
120
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
150
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );

Loading…
Peruuta
Tallenna