Currently, yaboot works properly when there is a tftp boot server serving
the broadcast requests sent in the network.
If the user specifies siaddr, ciaddr, and other arguments in the command
line, it is not handled appropriately.
This patch changes that behavior and make yaboot work properly in both cases.
The semantics specified in section 4.1 of
http://playground.sun.com/1275/practice/obp-tftp/tftp1_0.pdf is followed.
([bootp,]siaddr,filename,ciaddr,giaddr,bootp-retries,tftp-retries)
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
---
struct boot_fspec_t {
char* dev; /* OF device path */
int part; /* Partition number or -1 */
struct boot_fspec_t {
char* dev; /* OF device path */
int part; /* Partition number or -1 */
+ char* siaddr; /* Server address */
char* file; /* File path */
char* file; /* File path */
+ char* ciaddr; /* Client address */
+ char* giaddr; /* Gateway address */
+ char* bootp_retries; /* Bootp retries */
+ char* tftp_retries; /* TFTP retries */
+ char* addl_params; /* copy all additional parameters */
extern char bootdevice[];
extern char bootdevice[];
-static char *netdev_path_to_filename(const char *path)
+/*
+ * Copy the string from source to dest till newline or comma(,) is seen
+ * in the source.
+ * Move source and dest pointers respectively.
+ * Returns pointer to the start of the string that has just been copied.
+ */
+static char *
+scopy(char **dest, char **source)
- char *tmp, *args, *filename;
- size_t len;
-
- DEBUG_F("path = %s\n", path);
- args = strrchr(path, ':');
+ while (**source != ',' && **source != '\0')
+ *(*dest)++ = *(*source)++;
+ if (**source != '\0')
+ *(*source)++;
+ **dest = '\0';
+ *(*dest)++;
+ return ret;
+}
+
+/*
+ * Extract all the arguments provided in the imagepath and fill it in result.
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+extract_args_from_netdev_path(char *imagepath, struct boot_fspec_t *result)
+{
+ char *tmp, *args, *str, *start;
+
+ DEBUG_F("imagepath = %s\n", imagepath);
+
+ if (!imagepath)
+ return 1;
+
+ args = strrchr(imagepath, ':');
+ return 1;
+
+ start = args; /* used to see if we read any optional parameters */
/* The obp-tftp device arguments should be at the end of
* the argument list. Skip over any extra arguments (promiscuous,
/* The obp-tftp device arguments should be at the end of
* the argument list. Skip over any extra arguments (promiscuous,
if (tmp && tmp > args)
args = tmp + strlen("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 != ':') {
+ if (args != start) /* we read some parameters, so go past the next comma(,) */
args = strchr(args, ',');
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;
+ str = malloc(strlen(args) + 1); /*long enough to hold all strings */
+ if (!str)
+ return 0;
- filename = malloc(len);
- if (!filename)
- return NULL;
+ if (args[-1] != ':')
+ args++; /* If comma(,) is not immediately followed by ':' then go past the , */
- strncpy(filename, args, len);
- filename[len - 1] = '\0';
+ /*
+ * read the arguments in order: siaddr,filename,ciaddr,giaddr,
+ * bootp-retries,tftp-retries,addl_prameters
+ */
+ result->siaddr = scopy(&str, &args);
+ result->file = scopy(&str, &args);
+ result->ciaddr = scopy(&str, &args);
+ result->giaddr = scopy(&str, &args);
+ result->bootp_retries = scopy(&str, &args);
+ result->tftp_retries = scopy(&str, &args);
+ if (*args) {
+ result->addl_params = strdup(args);
+ if (!result->addl_params)
+ return 0;
+ }
- DEBUG_F("filename = %s\n", filename);
- return filename;
+ DEBUG_F("siaddr = <%s>\n", result->siaddr);
+ DEBUG_F("file = <%s>\n", result->file);
+ DEBUG_F("ciaddr = <%s>\n", result->ciaddr);
+ DEBUG_F("giaddr = <%s>\n", result->giaddr);
+ DEBUG_F("bootp_retries = <%s>\n", result->bootp_retries);
+ DEBUG_F("tftp_retries = <%s>\n", result->tftp_retries);
+ DEBUG_F("addl_params = <%s>\n", result->addl_params);
+ return 1;
}
static char *netdev_path_to_dev(const char *path)
}
static char *netdev_path_to_dev(const char *path)
- enet:,/tftpboot/vmlinux
- enet:bootp
- enet:0
- enet:,/tftpboot/vmlinux
- enet:bootp
- enet:0
+ - arguments for obp-tftp open as specified in section 4.1 of
+ http://playground.sun.com/1275/practice/obp-tftp/tftp1_0.pdf
+ [bootp,]siaddr,filename,ciaddr,giaddr,bootp-retries,tftp-retries
+ ex: enet:bootp,10.0.0.11,bootme,10.0.0.12,10.0.0.1,5,5
Supported only if defdevice == NULL
- disc
- any other device path lacking a :
Supported only if defdevice == NULL
- disc
- any other device path lacking a :
char *defdev = NULL;
int device_kind = -1;
char *defdev = NULL;
int device_kind = -1;
+ DEBUG_F("imagepath = %s; defdevice %s; defpart %d, deffile %s\n",
+ imagepath, defdevice, defpart, deffile);
+
result->dev = NULL;
result->part = -1;
result->file = NULL;
result->dev = NULL;
result->part = -1;
result->file = NULL;
}
if (device_kind == FILE_DEVICE_NET) {
}
if (device_kind == FILE_DEVICE_NET) {
- if (strchr(ipath, ':'))
- result->file = netdev_path_to_filename(ipath);
- else
+ if (strchr(ipath, ':')) {
+ if (extract_args_from_netdev_path(ipath, result) == 0)
+ return 0;
+ } else
result->file = strdup(ipath);
if (!defdev)
result->file = strdup(ipath);
if (!defdev)
struct partition_t* part, struct boot_fspec_t* fspec)
{
static char buffer[1024];
struct partition_t* part, struct boot_fspec_t* fspec)
{
static char buffer[1024];
char *p;
DEBUG_ENTER;
DEBUG_OPEN;
char *p;
DEBUG_ENTER;
DEBUG_OPEN;
- strncpy(buffer, fspec->dev, 768);
if (fspec->file && strlen(fspec->file)) {
if (fspec->file && strlen(fspec->file)) {
filename = strdup(fspec->file);
for (p = filename; *p; p++)
if (*p == '/')
*p = '\\';
filename = strdup(fspec->file);
for (p = filename; *p; p++)
if (*p == '/')
*p = '\\';
- strcat(buffer, filename);
- free(filename);
+ DEBUG_F("siaddr <%s>; filename <%s>; ciaddr <%s>; giaddr <%s>;\n",
+ fspec->siaddr, filename, fspec->ciaddr, fspec->giaddr);
+ strncpy(buffer, fspec->dev, 768);
+ strcat(buffer, fspec->siaddr);
+ strcat(buffer, ",");
+ strcat(buffer, filename);
+ strcat(buffer, ",");
+ strcat(buffer, fspec->ciaddr);
+ strcat(buffer, ",");
+ strcat(buffer, fspec->giaddr);
+ strcat(buffer, ",");
+ strcat(buffer, fspec->bootp_retries);
+ strcat(buffer, ",");
+ strcat(buffer, fspec->tftp_retries);
+ strcat(buffer, ",");
+ strcat(buffer, fspec->addl_params);
+
DEBUG_F("Opening: \"%s\"\n", buffer);
file->of_device = prom_open(buffer);
DEBUG_F("Opening: \"%s\"\n", buffer);
file->of_device = prom_open(buffer);
}
strncpy(msgpath, filename, sizeof(msgpath));
}
strncpy(msgpath, filename, sizeof(msgpath));
+ msgfile = boot; /* Copy all the original paramters */
if (!parse_device_path(msgpath, defdev, defpart, "/etc/yaboot.msg", &msgfile)) {
prom_printf("%s: Unable to parse\n", msgpath);
goto done;
if (!parse_device_path(msgpath, defdev, defpart, "/etc/yaboot.msg", &msgfile)) {
prom_printf("%s: Unable to parse\n", msgpath);
goto done;
if (!label && password)
check_password ("To boot a custom image you must enter the password.");
if (!label && password)
check_password ("To boot a custom image you must enter the password.");
+ params->kernel = boot; /* Copy all the original paramters */
if (!parse_device_path(imagepath, defdevice, defpart,
"/vmlinux", ¶ms->kernel)) {
prom_printf("%s: Unable to parse\n", imagepath);
if (!parse_device_path(imagepath, defdevice, defpart,
"/vmlinux", ¶ms->kernel)) {
prom_printf("%s: Unable to parse\n", imagepath);
strncpy(initrdpath, p, 1024);
DEBUG_F("Parsing initrd path <%s>\n", initrdpath);
strncpy(initrdpath, p, 1024);
DEBUG_F("Parsing initrd path <%s>\n", initrdpath);
+ params->rd = boot; /* Copy all the original paramters */
if (!parse_device_path(initrdpath, defdevice, defpart,
"/root.bin", ¶ms->rd)) {
prom_printf("%s: Unable to parse\n", imagepath);
if (!parse_device_path(initrdpath, defdevice, defpart,
"/root.bin", ¶ms->rd)) {
prom_printf("%s: Unable to parse\n", imagepath);
if (p && *p) {
DEBUG_F("Parsing sysmap path <%s>\n", p);
strncpy(sysmappath, p, 1024);
if (p && *p) {
DEBUG_F("Parsing sysmap path <%s>\n", p);
strncpy(sysmappath, p, 1024);
+ params->sysmap = boot; /* Copy all the original paramters */
if (!parse_device_path(sysmappath, defdevice, defpart,
"/boot/System.map", ¶ms->sysmap)) {
prom_printf("%s: Unable to parse\n", imagepath);
if (!parse_device_path(sysmappath, defdevice, defpart,
"/boot/System.map", ¶ms->sysmap)) {
prom_printf("%s: Unable to parse\n", imagepath);