Переглянути джерело

Quickly hacked to use a buffer rather than a processor.

These don't yet take advantage of the buffer functionality.
tags/v0.9.3
Michael Brown 19 роки тому
джерело
коміт
75a5374d79
2 змінених файлів з 41 додано та 39 видалено
  1. 21
    16
      src/proto/slam.c
  2. 20
    23
      src/proto/tftm.c

+ 21
- 16
src/proto/slam.c Переглянути файл

@@ -2,6 +2,16 @@
2 2
 #include "proto.h"
3 3
 #include "nic.h"
4 4
 
5
+/*
6
+ * IMPORTANT
7
+ *
8
+ * This file should be rewritten to avoid the use of a bitmap.  Our
9
+ * buffer routines can cope with being handed blocks in an arbitrary
10
+ * order, duplicate blocks, etc.  This code could be substantially
11
+ * simplified by taking advantage of these features.
12
+ *
13
+ */
14
+
5 15
 #define SLAM_PORT 10000
6 16
 #define SLAM_MULTICAST_IP ((239<<24)|(255<<16)|(1<<8)|(1<<0))
7 17
 #define SLAM_MULTICAST_PORT 10000
@@ -82,6 +92,7 @@ struct slam_state {
82 92
 
83 93
 	unsigned long received_packets;
84 94
 
95
+	struct buffer *buffer;
85 96
 	unsigned char *image;
86 97
 	unsigned char *bitmap;
87 98
 } state;
@@ -104,10 +115,8 @@ struct slam_info {
104 115
 	struct sockaddr_in server;
105 116
 	struct sockaddr_in local;
106 117
 	struct sockaddr_in multicast;
107
-	int ( * process ) ( unsigned char *data,
108
-			    unsigned int blocknum,
109
-			    unsigned int len, int eof );
110 118
 	int sent_nack;
119
+	struct buffer *buffer;
111 120
 };
112 121
 
113 122
 #define SLAM_TIMEOUT 0
@@ -304,12 +313,11 @@ static unsigned char *reinit_slam_state(
304 313
 		printf("ALERT: slam blocksize to large\n");
305 314
 		return 0;
306 315
 	}
307
-	if (state.bitmap) {
308
-		forget(state.bitmap);
309
-	}
310 316
 	bitmap_len   = (state.total_packets + 1 + 7)/8;
311
-	state.bitmap = allot(bitmap_len);
312
-	state.image  = allot(total_bytes);
317
+	state.image  = phys_to_virt ( state.buffer->start );
318
+	/* We don't use the buffer routines properly yet; fake it */
319
+	state.buffer->fill = total_bytes;
320
+	state.bitmap = state.image + total_bytes;
313 321
 	if ((unsigned long)state.image < 1024*1024) {
314 322
 		printf("ALERT: slam filesize to large for available memory\n");
315 323
 		return 0;
@@ -440,6 +448,7 @@ static int proto_slam(struct slam_info *info)
440 448
 	long timeout;
441 449
 
442 450
 	init_slam_state();
451
+	state.buffer = info->buffer;
443 452
 
444 453
 	retry = -1;
445 454
 	rx_qdrain();
@@ -504,15 +513,11 @@ static int proto_slam(struct slam_info *info)
504 513
 	leave_group(IGMP_SERVER);
505 514
 	/* FIXME don't overwrite myself */
506 515
 	/* load file to correct location */
507
-	return info->process(state.image, 1, state.total_bytes, 1);
516
+	return 1;
508 517
 }
509 518
 
510
-static int url_slam ( char *url __unused,
511
-		      struct sockaddr_in *server,
512
-		      char *file,
513
-		      int ( * process ) ( unsigned char *data,
514
-					  unsigned int blocknum,
515
-					  unsigned int len, int eof ) ) {
519
+static int url_slam ( char *url __unused, struct sockaddr_in *server,
520
+		      char *file, struct buffer *buffer ) {
516 521
 	struct slam_info info;
517 522
 	/* Set the defaults */
518 523
 	info.server = *server;
@@ -520,7 +525,7 @@ static int url_slam ( char *url __unused,
520 525
 	info.multicast.sin_port      = SLAM_MULTICAST_PORT;
521 526
 	info.local.sin_addr.s_addr   = arptable[ARP_CLIENT].ipaddr.s_addr;
522 527
 	info.local.sin_port          = SLAM_LOCAL_PORT;
523
-	info.process                 = process;
528
+	info.buffer                  = buffer;
524 529
 	info.sent_nack = 0;
525 530
 	if (file[0]) {
526 531
 		printf("\nBad url\n");

+ 20
- 23
src/proto/tftm.c Переглянути файл

@@ -35,6 +35,16 @@
35 35
 *    Indent Options: indent -kr -i8
36 36
 ***************************************************************************/
37 37
 
38
+/*
39
+ * IMPORTANT
40
+ *
41
+ * This file should be rewritten to avoid the use of a bitmap.  Our
42
+ * buffer routines can cope with being handed blocks in an arbitrary
43
+ * order, duplicate blocks, etc.  This code could be substantially
44
+ * simplified by taking advantage of these features.
45
+ *
46
+ */
47
+
38 48
 #include "etherboot.h"
39 49
 #include "proto.h"
40 50
 #include "nic.h"
@@ -43,9 +53,6 @@ struct tftm_info {
43 53
 	struct sockaddr_in server;
44 54
 	struct sockaddr_in local;
45 55
 	struct sockaddr_in multicast;
46
-	int ( * process ) ( unsigned char *data,
47
-			    unsigned int blocknum,
48
-			    unsigned int len, int eof );
49 56
 	int sent_nack;
50 57
 	const char *name;	/* Filename */
51 58
 };
@@ -56,6 +63,7 @@ struct tftm_state {
56 63
 	unsigned long total_packets;
57 64
 	char ismaster;
58 65
 	unsigned long received_packets;
66
+	struct buffer *buffer;
59 67
 	unsigned char *image;
60 68
 	unsigned char *bitmap;
61 69
 	char recvd_oack;
@@ -221,17 +229,11 @@ static int proto_tftm(struct tftm_info *info)
221 229
 					bitmap_len =
222 230
 					    (state.total_packets + 7) / 8;
223 231
 					if (!state.image) {
224
-						state.bitmap =
225
-						    allot(bitmap_len);
226
-						state.image =
227
-						    allot(filesize);
228
-
229
-						if ((unsigned long) state.
230
-						    image < 1024 * 1024) {
231
-							printf
232
-							    ("ALERT: tftp filesize to large for available memory\n");
233
-							return 0;
234
-						}
232
+						state.image = phys_to_virt ( state.buffer->start );
233
+						state.bitmap = state.image + filesize;
234
+						/* We don't yet use the buffer routines; fake it */
235
+						state.buffer->fill = filesize;
236
+
235 237
 						memset(state.bitmap, 0,
236 238
 						       bitmap_len);
237 239
 					}
@@ -360,7 +362,6 @@ static int proto_tftm(struct tftm_info *info)
360 362
 					     TFTP_MIN_PACKET, &tp); /* ack */
361 363
 			}
362 364
 			/* We are done get out */
363
-			forget(state.bitmap);
364 365
 			break;
365 366
 		}
366 367
 
@@ -376,15 +377,11 @@ static int proto_tftm(struct tftm_info *info)
376 377
 	}
377 378
 	/* Leave the multicast group */
378 379
 	leave_group(IGMP_SERVER);
379
-	return info->process(state.image, 1, filesize, 1);
380
+	return 1;
380 381
 }
381 382
 
382
-static int url_tftm ( char *url __unused,
383
-		      struct sockaddr_in *server,
384
-		      char *file,
385
-		      int ( * process ) ( unsigned char *data,
386
-					  unsigned int blocknum,
387
-					  unsigned int len, int eof ) ) {
383
+static int url_tftm ( char *url __unused, struct sockaddr_in *server,
384
+		      char *file, struct buffer *buffer ) {
388 385
 
389 386
 	int ret;
390 387
 	struct tftm_info info;
@@ -394,7 +391,6 @@ static int url_tftm ( char *url __unused,
394 391
 	info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
395 392
 	info.local.sin_port = TFTM_PORT; /* Does not matter. */
396 393
 	info.multicast = info.local;
397
-	info.process = process;
398 394
 	state.ismaster = 0;
399 395
 	info.name = file;
400 396
 
@@ -402,6 +398,7 @@ static int url_tftm ( char *url __unused,
402 398
 	state.total_bytes = 0;
403 399
 	state.total_packets = 0;
404 400
 	state.received_packets = 0;
401
+	state.buffer = buffer;
405 402
 	state.image = 0;
406 403
 	state.bitmap = 0;
407 404
 	state.recvd_oack = 0;

Завантаження…
Відмінити
Зберегти