瀏覽代碼

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

tags/v0.9.3
Michael Brown 16 年之前
父節點
當前提交
122abb50af

+ 56
- 54
src/Makefile 查看文件

@@ -1,3 +1,7 @@
1
+# Location to place generated files
2
+#
3
+BIN		:= bin
4
+
1 5
 # Initialise variables that get added to throughout the various Makefiles
2 6
 #
3 7
 MAKEDEPS	:= Makefile .toolcheck .echocheck
@@ -9,34 +13,34 @@ ROMS		:=
9 13
 MEDIA		:=
10 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 45
 # If invoked with no build target, print out a helpfully suggestive
42 46
 # message.
@@ -64,34 +68,28 @@ noargs : blib $(BIN)/NIC $(BIN)/gpxe.dsk $(BIN)/gpxe.iso $(BIN)/gpxe.usb
64 68
 	@$(ECHO)
65 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 94
 # Common flags
97 95
 #
@@ -103,6 +101,10 @@ CFLAGS		+= $(EXTRA_CFLAGS)
103 101
 ASFLAGS		+= $(EXTRA_ASFLAGS)
104 102
 LDFLAGS		+= $(EXTRA_LDFLAGS)
105 103
 
104
+# Embedded image, if present
105
+#
106
+EMBEDDED_IMAGE	?= /dev/null
107
+
106 108
 ifneq ($(NO_WERROR),1)
107 109
 CFLAGS		+= -Werror
108 110
 endif

+ 11
- 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
 #
@@ -356,6 +364,9 @@ $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
356 364
 		-Map $(BIN)/$*.tmp.map
357 365
 	$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
358 366
 
367
+# Keep intermediate object file (useful for debugging)
368
+.SECONDARY : $(BIN)/%.tmp
369
+
359 370
 # Show a linker map for the specified target
360 371
 #
361 372
 $(BIN)/%.map : $(BIN)/%.tmp

+ 24
- 45
src/core/downloader.c 查看文件

@@ -96,6 +96,9 @@ static int downloader_ensure_size ( struct downloader *downloader,
96 96
 	if ( len <= downloader->image->len )
97 97
 		return 0;
98 98
 
99
+	DBGC ( downloader, "Downloader %p extending to %zd bytes\n",
100
+	       downloader, len );
101
+
99 102
 	/* Extend buffer */
100 103
 	new_buffer = urealloc ( downloader->image->data, len );
101 104
 	if ( ! new_buffer ) {
@@ -141,68 +144,44 @@ static struct job_interface_operations downloader_job_operations = {
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 148
  * Handle deliver_raw() event received via data transfer interface
181 149
  *
182 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 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 158
 	struct downloader *downloader =
190 159
 		container_of ( xfer, struct downloader, xfer );
160
+	size_t len;
191 161
 	size_t max;
192 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 169
 	/* Ensure that we have enough buffer space for this data */
170
+	len = iob_len ( iobuf );
195 171
 	max = ( downloader->pos + len );
196 172
 	if ( ( rc = downloader_ensure_size ( downloader, max ) ) != 0 )
197
-		return rc;
173
+		goto done;
198 174
 
199 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 179
 	/* Update current buffer position */
203 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,10 +206,10 @@ static void downloader_xfer_close ( struct xfer_interface *xfer, int rc ) {
227 206
 static struct xfer_interface_operations downloader_xfer_operations = {
228 207
 	.close		= downloader_xfer_close,
229 208
 	.vredirect	= xfer_vopen,
230
-	.seek		= downloader_xfer_seek,
231 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 查看文件

@@ -44,12 +44,6 @@ int filter_vredirect ( struct xfer_interface *xfer, int type,
44 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 47
 size_t filter_window ( struct xfer_interface *xfer ) {
54 48
 	struct xfer_interface *other = filter_other_half ( xfer );
55 49
 

+ 1
- 1
src/core/hw.c 查看文件

@@ -36,8 +36,8 @@ static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
36 36
 static struct xfer_interface_operations hw_xfer_operations = {
37 37
 	.close		= hw_xfer_close,
38 38
 	.vredirect	= ignore_xfer_vredirect,
39
-	.seek		= ignore_xfer_seek,
40 39
 	.window		= unlimited_xfer_window,
40
+	.alloc_iob	= default_xfer_alloc_iob,
41 41
 	.deliver_iob	= xfer_deliver_as_raw,
42 42
 	.deliver_raw	= ignore_xfer_deliver_raw,
43 43
 };

+ 8
- 29
src/core/posix_io.c 查看文件

@@ -103,39 +103,12 @@ static void posix_file_xfer_close ( struct xfer_interface *xfer, int rc ) {
103 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 107
  * Handle deliver_iob() event
135 108
  *
136 109
  * @v xfer		POSIX file data transfer interface
137 110
  * @v iobuf		I/O buffer
138
- * @v meta		Data transfer metadata, or NULL
111
+ * @v meta		Data transfer metadata
139 112
  * @ret rc		Return status code
140 113
  */
141 114
 static int
@@ -145,6 +118,13 @@ posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
145 118
 	struct posix_file *file =
146 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 128
 	list_add_tail ( &iobuf->list, &file->data );
149 129
 	return 0;
150 130
 }
@@ -153,7 +133,6 @@ posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
153 133
 static struct xfer_interface_operations posix_file_xfer_operations = {
154 134
 	.close		= posix_file_xfer_close,
155 135
 	.vredirect	= xfer_vopen,
156
-	.seek		= posix_file_xfer_seek,
157 136
 	.window		= unlimited_xfer_window,
158 137
 	.alloc_iob	= default_xfer_alloc_iob,
159 138
 	.deliver_iob	= posix_file_xfer_deliver_iob,

+ 0
- 1
src/core/resolv.c 查看文件

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

+ 28
- 41
src/core/xfer.c 查看文件

@@ -85,31 +85,6 @@ int xfer_redirect ( struct xfer_interface *xfer, int type, ... ) {
85 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 89
  * Check flow control window
115 90
  *
@@ -153,7 +128,7 @@ struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer, size_t len ) {
153 128
  *
154 129
  * @v xfer		Data transfer interface
155 130
  * @v iobuf		Datagram I/O buffer
156
- * @v meta		Data transfer metadata, or NULL
131
+ * @v meta		Data transfer metadata
157 132
  * @ret rc		Return status code
158 133
  */
159 134
 int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
@@ -184,7 +159,8 @@ int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
184 159
  */
185 160
 int xfer_deliver_iob ( struct xfer_interface *xfer,
186 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,6 +229,31 @@ int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
253 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 259
  * Helper methods
@@ -286,19 +287,6 @@ int ignore_xfer_vredirect ( struct xfer_interface *xfer __unused,
286 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 291
  * Unlimited flow control window
304 292
  *
@@ -401,7 +389,6 @@ int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
401 389
 struct xfer_interface_operations null_xfer_ops = {
402 390
 	.close		= ignore_xfer_close,
403 391
 	.vredirect	= ignore_xfer_vredirect,
404
-	.seek		= ignore_xfer_seek,
405 392
 	.window		= unlimited_xfer_window,
406 393
 	.alloc_iob	= default_xfer_alloc_iob,
407 394
 	.deliver_iob	= xfer_deliver_as_raw,

+ 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
+

+ 0
- 2
src/include/gpxe/filter.h 查看文件

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

+ 16
- 22
src/include/gpxe/xfer.h 查看文件

@@ -32,17 +32,6 @@ struct xfer_interface_operations {
32 32
 	 */
33 33
 	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
34 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 35
 	/** Check flow control window
47 36
 	 *
48 37
 	 * @v xfer		Data transfer interface
@@ -71,7 +60,7 @@ struct xfer_interface_operations {
71 60
 	 *
72 61
 	 * @v xfer		Data transfer interface
73 62
 	 * @v iobuf		Datagram I/O buffer
74
-	 * @v meta		Data transfer metadata, or NULL
63
+	 * @v meta		Data transfer metadata
75 64
 	 * @ret rc		Return status code
76 65
 	 *
77 66
 	 * A data transfer interface that wishes to support only raw
@@ -104,8 +93,21 @@ struct xfer_interface {
104 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 102
 /** Data transfer metadata */
108 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 111
 	/** Source socket address, or NULL */
110 112
 	struct sockaddr *src;
111 113
 	/** Destination socket address, or NULL */
@@ -114,12 +116,6 @@ struct xfer_metadata {
114 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 120
  * Describe seek basis
125 121
  *
@@ -128,8 +124,8 @@ enum seek_whence {
128 124
 static inline __attribute__ (( always_inline )) const char *
129 125
 whence_text ( int whence ) {
130 126
 	switch ( whence ) {
131
-	case SEEK_SET:	return "SET";
132 127
 	case SEEK_CUR:	return "CUR";
128
+	case SEEK_SET:	return "SET";
133 129
 	default:	return "INVALID";
134 130
 	}
135 131
 }
@@ -141,7 +137,6 @@ extern void xfer_close ( struct xfer_interface *xfer, int rc );
141 137
 extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
142 138
 			    va_list args );
143 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 140
 extern size_t xfer_window ( struct xfer_interface *xfer );
146 141
 extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
147 142
 					   size_t len );
@@ -156,12 +151,11 @@ extern int xfer_vprintf ( struct xfer_interface *xfer,
156 151
 			  const char *format, va_list args );
157 152
 extern int xfer_printf ( struct xfer_interface *xfer,
158 153
 			 const char *format, ... );
154
+extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
159 155
 
160 156
 extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
161 157
 extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
162 158
 				   int type, va_list args );
163
-extern int ignore_xfer_seek ( struct xfer_interface *xfer, off_t offset,
164
-			      int whence );
165 159
 extern size_t unlimited_xfer_window ( struct xfer_interface *xfer );
166 160
 extern size_t no_xfer_window ( struct xfer_interface *xfer );
167 161
 extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,

+ 0
- 1
src/interface/pxe/pxe_udp.c 查看文件

@@ -103,7 +103,6 @@ static int pxe_udp_deliver_iob ( struct xfer_interface *xfer,
103 103
 static struct xfer_interface_operations pxe_udp_xfer_operations = {
104 104
 	.close		= ignore_xfer_close,
105 105
 	.vredirect	= ignore_xfer_vredirect,
106
-	.seek		= ignore_xfer_seek,
107 106
 	.window		= unlimited_xfer_window,
108 107
 	.alloc_iob	= default_xfer_alloc_iob,
109 108
 	.deliver_iob	= pxe_udp_deliver_iob,

+ 0
- 1
src/net/tcp.c 查看文件

@@ -1022,7 +1022,6 @@ static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
1022 1022
 static struct xfer_interface_operations tcp_xfer_operations = {
1023 1023
 	.close		= tcp_xfer_close,
1024 1024
 	.vredirect	= ignore_xfer_vredirect,
1025
-	.seek		= ignore_xfer_seek,
1026 1025
 	.window		= tcp_xfer_window,
1027 1026
 	.alloc_iob	= default_xfer_alloc_iob,
1028 1027
 	.deliver_iob	= tcp_xfer_deliver_iob,

+ 0
- 3
src/net/tcp/ftp.c 查看文件

@@ -299,7 +299,6 @@ static int ftp_control_deliver_raw ( struct xfer_interface *control,
299 299
 static struct xfer_interface_operations ftp_control_operations = {
300 300
 	.close		= ftp_control_close,
301 301
 	.vredirect	= xfer_vopen,
302
-	.seek		= ignore_xfer_seek,
303 302
 	.window		= unlimited_xfer_window,
304 303
 	.alloc_iob	= default_xfer_alloc_iob,
305 304
 	.deliver_iob	= xfer_deliver_as_raw,
@@ -364,7 +363,6 @@ static int ftp_data_deliver_iob ( struct xfer_interface *data,
364 363
 static struct xfer_interface_operations ftp_data_operations = {
365 364
 	.close		= ftp_data_closed,
366 365
 	.vredirect	= xfer_vopen,
367
-	.seek		= ignore_xfer_seek,
368 366
 	.window		= unlimited_xfer_window,
369 367
 	.alloc_iob	= default_xfer_alloc_iob,
370 368
 	.deliver_iob	= ftp_data_deliver_iob,
@@ -397,7 +395,6 @@ static void ftp_xfer_closed ( struct xfer_interface *xfer, int rc ) {
397 395
 static struct xfer_interface_operations ftp_xfer_operations = {
398 396
 	.close		= ftp_xfer_closed,
399 397
 	.vredirect	= ignore_xfer_vredirect,
400
-	.seek		= ignore_xfer_seek,
401 398
 	.window		= unlimited_xfer_window,
402 399
 	.alloc_iob	= default_xfer_alloc_iob,
403 400
 	.deliver_iob	= xfer_deliver_as_raw,

+ 0
- 2
src/net/tcp/http.c 查看文件

@@ -426,7 +426,6 @@ static void http_socket_close ( struct xfer_interface *socket, int rc ) {
426 426
 static struct xfer_interface_operations http_socket_operations = {
427 427
 	.close		= http_socket_close,
428 428
 	.vredirect	= xfer_vopen,
429
-	.seek		= ignore_xfer_seek,
430 429
 	.window		= unlimited_xfer_window,
431 430
 	.alloc_iob	= default_xfer_alloc_iob,
432 431
 	.deliver_iob	= http_socket_deliver_iob,
@@ -453,7 +452,6 @@ static void http_xfer_close ( struct xfer_interface *xfer, int rc ) {
453 452
 static struct xfer_interface_operations http_xfer_operations = {
454 453
 	.close		= http_xfer_close,
455 454
 	.vredirect	= ignore_xfer_vredirect,
456
-	.seek		= ignore_xfer_seek,
457 455
 	.window		= unlimited_xfer_window,
458 456
 	.alloc_iob	= default_xfer_alloc_iob,
459 457
 	.deliver_iob	= xfer_deliver_as_raw,

+ 1
- 2
src/net/tcp/iscsi.c 查看文件

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

+ 0
- 2
src/net/tls.c 查看文件

@@ -1460,7 +1460,6 @@ static int tls_plainstream_deliver_raw ( struct xfer_interface *xfer,
1460 1460
 static struct xfer_interface_operations tls_plainstream_operations = {
1461 1461
 	.close		= tls_plainstream_close,
1462 1462
 	.vredirect	= ignore_xfer_vredirect,
1463
-	.seek		= filter_seek,
1464 1463
 	.window		= tls_plainstream_window,
1465 1464
 	.alloc_iob	= default_xfer_alloc_iob,
1466 1465
 	.deliver_iob	= xfer_deliver_as_raw,
@@ -1600,7 +1599,6 @@ static int tls_cipherstream_deliver_raw ( struct xfer_interface *xfer,
1600 1599
 static struct xfer_interface_operations tls_cipherstream_operations = {
1601 1600
 	.close		= tls_cipherstream_close,
1602 1601
 	.vredirect	= xfer_vopen,
1603
-	.seek		= filter_seek,
1604 1602
 	.window		= filter_window,
1605 1603
 	.alloc_iob	= default_xfer_alloc_iob,
1606 1604
 	.deliver_iob	= xfer_deliver_as_raw,

+ 0
- 1
src/net/udp.c 查看文件

@@ -415,7 +415,6 @@ static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
415 415
 static struct xfer_interface_operations udp_xfer_operations = {
416 416
 	.close		= udp_xfer_close,
417 417
 	.vredirect	= ignore_xfer_vredirect,
418
-	.seek		= ignore_xfer_seek,
419 418
 	.window		= unlimited_xfer_window,
420 419
 	.alloc_iob	= udp_alloc_iob,
421 420
 	.deliver_iob	= udp_xfer_deliver_iob,

+ 9
- 7
src/net/udp/dhcp.c 查看文件

@@ -368,11 +368,11 @@ static size_t dhcp_field_len ( const void *data, size_t max_len ) {
368 368
  * @v max_len		Field length
369 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 377
  * The caller must ensure that there is enough space in the options
378 378
  * block to perform the merge.
@@ -385,7 +385,9 @@ static void merge_dhcp_field ( struct dhcp_option_block *options,
385 385
 	struct dhcp_option *end;
386 386
 
387 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 391
 	} else {
390 392
 		len = dhcp_field_len ( data, max_len );
391 393
 		dest = ( options->data + options->len - 1 );
@@ -925,8 +927,8 @@ static int dhcp_deliver_raw ( struct xfer_interface *xfer,
925 927
 static struct xfer_interface_operations dhcp_xfer_operations = {
926 928
 	.close		= ignore_xfer_close,
927 929
 	.vredirect	= xfer_vopen,
928
-	.seek		= ignore_xfer_seek,
929 930
 	.window		= unlimited_xfer_window,
931
+	.alloc_iob	= default_xfer_alloc_iob,
930 932
 	.deliver_iob	= xfer_deliver_as_raw,
931 933
 	.deliver_raw	= dhcp_deliver_raw,
932 934
 };

+ 0
- 1
src/net/udp/dns.c 查看文件

@@ -435,7 +435,6 @@ static void dns_xfer_close ( struct xfer_interface *socket, int rc ) {
435 435
 static struct xfer_interface_operations dns_socket_operations = {
436 436
 	.close		= dns_xfer_close,
437 437
 	.vredirect	= xfer_vopen,
438
-	.seek		= ignore_xfer_seek,
439 438
 	.window		= unlimited_xfer_window,
440 439
 	.alloc_iob	= default_xfer_alloc_iob,
441 440
 	.deliver_iob	= xfer_deliver_as_raw,

+ 5
- 5
src/net/udp/tftp.c 查看文件

@@ -703,6 +703,7 @@ static int tftp_rx_oack ( struct tftp_request *tftp, void *buf, size_t len ) {
703 703
 static int tftp_rx_data ( struct tftp_request *tftp,
704 704
 			  struct io_buffer *iobuf ) {
705 705
 	struct tftp_data *data = iobuf->data;
706
+	struct xfer_metadata meta;
706 707
 	int block;
707 708
 	off_t offset;
708 709
 	size_t data_len;
@@ -729,8 +730,10 @@ static int tftp_rx_data ( struct tftp_request *tftp,
729 730
 	}
730 731
 
731 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 737
 	iobuf = NULL;
735 738
 	if ( rc != 0 ) {
736 739
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
@@ -909,7 +912,6 @@ static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
909 912
 static struct xfer_interface_operations tftp_socket_operations = {
910 913
 	.close		= ignore_xfer_close,
911 914
 	.vredirect	= xfer_vopen,
912
-	.seek		= ignore_xfer_seek,
913 915
 	.window		= unlimited_xfer_window,
914 916
 	.alloc_iob	= default_xfer_alloc_iob,
915 917
 	.deliver_iob	= tftp_socket_deliver_iob,
@@ -937,7 +939,6 @@ static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,
937 939
 static struct xfer_interface_operations tftp_mc_socket_operations = {
938 940
 	.close		= ignore_xfer_close,
939 941
 	.vredirect	= xfer_vopen,
940
-	.seek		= ignore_xfer_seek,
941 942
 	.window		= unlimited_xfer_window,
942 943
 	.alloc_iob	= default_xfer_alloc_iob,
943 944
 	.deliver_iob	= tftp_mc_socket_deliver_iob,
@@ -964,7 +965,6 @@ static void tftp_xfer_close ( struct xfer_interface *xfer, int rc ) {
964 965
 static struct xfer_interface_operations tftp_xfer_operations = {
965 966
 	.close		= tftp_xfer_close,
966 967
 	.vredirect	= ignore_xfer_vredirect,
967
-	.seek		= ignore_xfer_seek,
968 968
 	.window		= unlimited_xfer_window,
969 969
 	.alloc_iob	= default_xfer_alloc_iob,
970 970
 	.deliver_iob	= xfer_deliver_as_raw,

+ 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…
取消
儲存