From 7558941ebce6bd1e085cde875133745e4824cedd Mon Sep 17 00:00:00 2001 From: Ethan Benson Date: Mon, 26 Sep 2005 06:41:14 +0000 Subject: [PATCH] Replace netboot bootpath parser. * second/file.c: Replace bootpath parser for netboot cases, the new one should (hopefully) correctly handle most/all netboot situations. (Nathan Lynch) git-archimport-id: erbenson@alaska.net--public/yaboot--devel--1.3--patch-88 --- 0arch-timestamps0 | 43 +++++++------- ChangeLog | 15 +++++ second/file.c | 146 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 163 insertions(+), 41 deletions(-) diff --git a/0arch-timestamps0 b/0arch-timestamps0 index aabe9b6..10e5019 100644 --- a/0arch-timestamps0 +++ b/0arch-timestamps0 @@ -1,7 +1,7 @@ -./0arch-timestamps0 1127716375 1127716584 +./0arch-timestamps0 1127716589 1127716862 ./BUGS 1109049412 1000991730 ./COPYING 1109049412 1000991730 -./ChangeLog 1127716501 1127716581 +./ChangeLog 1127716742 1127716860 ./Config 1109049412 1002101497 ./INSTALL 1109049412 1000991730 ./README 1109049412 1044766458 @@ -21,18 +21,18 @@ ./doc/examples/simpleboot.chrp 1109049412 1068017750 ./doc/examples/yaboot.conf.multi-boot 1109049412 1006348765 ./doc/examples/yaboot.conf.rs6000 1109049412 1006348765 -./doc/examples 1127716584 1068017750 +./doc/examples 1127716657 1068017750 ./doc/yaboot-howto.de.sgml 1109049413 1096186109 ./doc/yaboot-howto.sgml 1109049413 1096186082 -./doc 1127716584 1096186109 +./doc 1127716657 1096186109 ./etc/yaboot.conf 1109049413 1006348765 -./etc 1127716584 1007269243 +./etc 1127716657 1007269243 ./first/ofboot 1118285749 1065311880 -./first 1127716584 1071492158 +./first 1127716657 1071492158 ./include/asm/elf.h 1109049413 1000991730 ./include/asm/ppc_asm.tmpl 1109049413 1000991730 ./include/asm/processor.h 1109049413 1000991730 -./include/asm 1127716584 1007269243 +./include/asm 1127716657 1007269243 ./include/bootinfo.h 1109049413 1007200690 ./include/byteorder.h 1109049413 1000991730 ./include/cfg.h 1109049413 1007200690 @@ -41,12 +41,12 @@ ./include/debug.h 1109049413 1007200690 ./include/errors.h 1109049413 1007200690 ./include/et/com_err.h 1109049413 1000991731 -./include/et 1127716584 1007269243 +./include/et 1127716657 1007269243 ./include/ext2fs/bitops.h 1109049413 1003927524 ./include/ext2fs/ext2_err.h 1109049413 1003927524 ./include/ext2fs/ext2_io.h 1109049413 1003927524 ./include/ext2fs/ext2fs.h 1109049413 1003927524 -./include/ext2fs 1127716584 1007269243 +./include/ext2fs 1127716657 1007269243 ./include/file.h 1109049413 1007200690 ./include/fs.h 1109049413 1007200690 ./include/linux/elf.h 1109049413 1000991731 @@ -54,12 +54,12 @@ ./include/linux/iso_fs.h 1109049413 1000991731 ./include/linux/stat.h 1109049413 1000991731 ./include/linux/types.h 1109049413 1000991731 -./include/linux 1127716584 1007269243 +./include/linux 1127716657 1007269243 ./include/mac-part.h 1109049413 1007200690 ./include/md5.h 1109049413 1000991730 ./include/prom.h 1109049413 1007200690 ./include/reiserfs/reiserfs.h 1109049413 1025684115 -./include/reiserfs 1127716584 1025684115 +./include/reiserfs 1127716657 1025684115 ./include/setjm2.h 1109049413 1000991730 ./include/setjmp.h 1109049413 1000991730 ./include/stdlib.h 1109049413 1000991730 @@ -67,12 +67,12 @@ ./include/swab.h 1109049413 1000991730 ./include/types.h 1109049413 1000991730 ./include/xfs/xfs.h 1109049413 1002101334 -./include/xfs 1127716584 1007269244 +./include/xfs 1127716658 1007269244 ./include/yaboot.h 1109049413 1007200690 ./include/amiga-part.h 1116558586 1116558522 ./include/fdisk-part.h 1120953080 1120952841 ./include/partition.h 1120953080 1120952841 -./include 1127716584 1120952841 +./include 1127716657 1120952841 ./lib/ctype.c 1109049413 1000991731 ./lib/libext2fs.a 1109049413 1003927524 ./lib/malloc.c 1122610545 1007200690 @@ -81,7 +81,7 @@ ./lib/strtol.c 1109049413 1000991731 ./lib/vsprintf.c 1109049413 1000991731 ./lib/strstr.c 1119929028 1116476589 -./lib 1127716584 1116476589 +./lib 1127716658 1116476589 ./man/bootstrap.8 1116558691 1000991731 ./man/mkofboot.8 1116558691 1006348765 ./man/ofpath.8 1116558691 1000991731 @@ -89,7 +89,7 @@ ./man/yabootconfig.8 1116558691 1027929577 ./man/ybin.8 1116558691 1006348765 ./man/yaboot.8 1125032949 1090699543 -./man 1127716584 1116476667 +./man 1127716658 1116476667 ./man.patch 1116558699 1006348761 ./second/cache.S 1127716272 1007200690 ./second/cfg.c 1127716272 1007200690 @@ -104,19 +104,18 @@ ./second/md5.c 1127716272 1032059532 ./second/prom.c 1127716272 1067937197 ./second/setjmp.S 1127716272 1000991732 -./second/file.c 1127716272 1122611207 ./second/partition.c 1127716272 1122611207 ./second/fs_of.c 1127716272 1123038648 -./second/yaboot.c.orig 1127716492 1122611207 -./second/yaboot.c 1127716492 1127716492 -./second 1127716584 1127716492 +./second/yaboot.c 1127716589 1127716492 +./second/file.c 1127716734 1127716734 +./second 1127716862 1127716734 ./util/elfextract.c 1109049413 1007303237 ./util/addnote.c 1109049413 1107321884 -./util 1127716584 1107321884 +./util 1127716658 1107321884 ./ybin/mkofboot 1127716369 1073219938 ./ybin/ofpath 1120448537 1120448442 ./ybin/yabootconfig 1117166139 1089576743 ./ybin/ybin 1120448039 1120447943 -./ybin 1127716584 1120448442 +./ybin 1127716658 1120448442 ./Makefile 1127716376 1127716319 -. 1127716584 1127716581 +. 1127716862 1127716860 diff --git a/ChangeLog b/ChangeLog index 4833025..9199391 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,21 @@ # arch-tag: automatic-ChangeLog--erbenson@alaska.net--public/yaboot--devel--1.3 # +2005-09-26 06:41:14 GMT Ethan Benson patch-88 + + Summary: + Replace netboot bootpath parser. + Revision: + yaboot--devel--1.3--patch-88 + + * second/file.c: Replace bootpath parser for netboot cases, the new + one should (hopefully) correctly handle most/all netboot + situations. (Nathan Lynch) + + modified files: + 0arch-timestamps0 ChangeLog second/file.c + + 2005-09-26 06:36:30 GMT Ethan Benson patch-87 Summary: diff --git a/second/file.c b/second/file.c index ed70376..8f86a6e 100644 --- a/second/file.c +++ b/second/file.c @@ -38,6 +38,112 @@ extern char bootdevice[1024]; +static char *netdev_path_to_filename(const char *path) +{ + char *tmp, *args, *filename; + size_t len; + + DEBUG_F("path = %s\n", path); + + if (!path) + return NULL; + + args = strrchr(path, ':'); + if (!args) + return NULL; + + /* The obp-tftp device arguments should be at the end of + * the argument list. Skip over any extra arguments (promiscuous, + * speed, duplex, bootp, rarp). + */ + + tmp = strstr(args, "promiscuous"); + if (tmp && tmp > args) + args = tmp + strlen("promiscuous"); + + tmp = strstr(args, "speed="); + if (tmp && tmp > args) + args = tmp + strlen("speed="); + + tmp = strstr(args, "duplex="); + if (tmp && tmp > args) + args = tmp + strlen("duplex="); + + tmp = strstr(args, "bootp"); + if (tmp && tmp > args) + args = tmp + strlen("bootp"); + + tmp = strstr(args, "rarp"); + if (tmp && tmp > args) + args = tmp + strlen("rarp"); + + args = strchr(args, ','); + if (!args) + return NULL; + + tmp = args; + tmp--; + /* If the preceding character is ':' then there were no + * non-obp-tftp arguments and we know we're right up to the + * filename. Otherwise, we must advance args once more. + */ + args++; + if (*tmp != ':') { + args = strchr(args, ','); + if (!args) + return NULL; + args++; + } + + /* filename may be empty; e.g. enet:192.168.1.1,,192.168.1.2 */ + if (*args == ',') { + DEBUG_F("null filename\n"); + return NULL; + } + + /* Now see whether there are more args following the filename. */ + tmp = strchr(args, ','); + if (!tmp) + len = strlen(args) + 1; + else + len = tmp - args + 1; + + filename = malloc(len); + if (!filename) + return NULL; + + strncpy(filename, args, len); + filename[len - 1] = '\0'; + + DEBUG_F("filename = %s\n", filename); + return filename; +} + +static char *netdev_path_to_dev(const char *path) +{ + char *dev, *tmp; + size_t len; + + DEBUG_F("path = %s\n", path); + + if (!path) + return NULL; + + tmp = strchr(path, ':'); + if (!tmp) + return strdup(path); + tmp++; + + len = tmp - path + 1; + + dev = malloc(len); + if (dev) { + strncpy(dev, path, len); + dev[len - 1] = '\0'; + } + return dev; +} + /* This function follows the device path in the devtree and separates the device name, partition number, and other datas (mostly file name) the string passed in parameters is changed since 0 are put in place @@ -71,6 +177,7 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, char *ptr; char *ipath = NULL; char *defdev = NULL; + int device_kind; result->dev = NULL; result->part = -1; @@ -81,22 +188,21 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, else if (!(ipath = strdup(imagepath))) return 0; - if (defdevice) + if (defdevice) { defdev = strdup(defdevice); + device_kind = prom_get_devtype(defdev); + } else + device_kind = prom_get_devtype(ipath); - if (defdev) { - if (!strstr(defdev, "ethernet") && !strstr(defdev, "enet")) { - if ((ptr = strrchr(defdev, ':')) != NULL) - *ptr = 0; /* remove trailing : from defdevice if necessary */ - } - } else { - return 0; + if (device_kind != FILE_DEVICE_NET && strchr(defdev, ':') != NULL) { + if ((ptr = strrchr(defdev, ':')) != NULL) + *ptr = 0; /* remove trailing : from defdevice if necessary */ } - /* if there is no : then there is no filename or partition. must - use strrchr() since enet:,10.0.0.1,file is legal */ - - if (strchr(ipath, ':') != NULL) { + /* This will not properly handle an obp-tftp argument list + * with elements after the filename; that is handled below. + */ + if (device_kind != FILE_DEVICE_NET && strchr(ipath, ':') != NULL) { if ((ptr = strrchr(ipath, ',')) != NULL) { char *colon = strrchr(ipath, ':'); /* If a ':' occurs *after* a ',', then we assume that there is @@ -109,13 +215,15 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, } } - if (strstr(ipath, "ethernet") || strstr(ipath, "enet")) - if ((ptr = strstr(ipath, "bootp")) != NULL) { /* `n' key booting boots enet:bootp */ - *ptr = 0; - result->dev = strdup(ipath); - } else - result->dev = strdup(ipath); - else if ((ptr = strchr(ipath, ':')) != NULL) { + if (device_kind == FILE_DEVICE_NET) { + if (strchr(ipath, ':')) + result->file = netdev_path_to_filename(ipath); + else + result->file = strdup(ipath); + + if (!defdev) + result->dev = netdev_path_to_dev(ipath); + } else if ((ptr = strchr(ipath, ':')) != NULL) { *ptr = 0; result->dev = strdup(ipath); if (*(ptr+1)) -- 2.39.2