X-Git-Url: http://git.ozlabs.org/?p=yaboot.git;a=blobdiff_plain;f=second%2Fyaboot.c;h=53643f5c5fff48d56f809712a535e67f2d429810;hp=e75046aeabd1eb94c30406584be3836959e1b318;hb=f3d8af0e0ac4642499d5430c202ac57d1d4c5ceb;hpb=c5340d42bba9a51b5b0e22f2161985213d54f805 diff --git a/second/yaboot.c b/second/yaboot.c index e75046a..53643f5 100644 --- a/second/yaboot.c +++ b/second/yaboot.c @@ -368,6 +368,22 @@ load_config_file(struct boot_fspec_t *fspec) goto bail; } + /* + * set the default cf_option to label that has the same MAC addr + * it only works if there is a label with the MAC addr on yaboot.conf + */ + if (prom_get_devtype(fspec->dev) == FILE_DEVICE_NET) { + /* change the variable bellow to get the MAC dinamicaly */ + char * macaddr = NULL; + int default_mac = 0; + + macaddr = prom_get_mac(prom_get_netinfo()); + default_mac = cfg_set_default_by_mac(macaddr); + if (default_mac >= 1) { + prom_printf("Default label was changed to macaddr label.\n"); + } + } + DEBUG_F("Config file successfully parsed, %d bytes\n", sz); /* Now, we do the initialisations stored in the config file */ @@ -429,35 +445,6 @@ bail: return result; } -/* - * "bootp-response" is the property name which is specified in - * the recommended practice doc for obp-tftp. However, pmac - * provides a "dhcp-response" property and chrp provides a - * "bootpreply-packet" property. The latter appears to begin the - * bootp packet at offset 0x2a in the property for some reason. - */ - -struct bootp_property_offset { - char *name; /* property name */ - int offset; /* offset into property where bootp packet occurs */ -}; -static const struct bootp_property_offset bootp_response_properties[] = { - { .name = "bootp-response", .offset = 0 }, - { .name = "dhcp-response", .offset = 0 }, - { .name = "bootpreply-packet", .offset = 0x2a }, -}; - -struct bootp_packet { - u8 op, htype, hlen, hops; - u32 xid; - u16 secs, flags; - u32 ciaddr, yiaddr, siaddr, giaddr; - unsigned char chaddr[16]; - unsigned char sname[64]; - unsigned char file[128]; - /* vendor options go here if we need them */ -}; - /* * Search for config file by MAC address, then by IP address. * Basically copying pxelinux's algorithm. @@ -465,47 +452,14 @@ struct bootp_packet { */ static int load_my_config_file(struct boot_fspec_t *orig_fspec) { - void *bootp_response = NULL; - char *propname; struct bootp_packet *packet; - int i = 0, size, offset = 0, rc = 0; - prom_handle chosen; + int rc = 0; struct boot_fspec_t fspec = *orig_fspec; -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) - - chosen = prom_finddevice("/chosen"); - if (chosen < 0) { - prom_printf("chosen=%d\n", chosen); - return 0; - } - - for (i = 0; i < ARRAY_SIZE(bootp_response_properties); i++) { - propname = bootp_response_properties[i].name; - size = prom_getproplen(chosen, propname); - if (size <= 0) - continue; - - DEBUG_F("using /chosen/%s\n", propname); - offset = bootp_response_properties[i].offset; - break; - } - - if (size <= 0) - goto out; - - if (sizeof(*packet) > size - offset) { - prom_printf("Malformed %s property?\n", propname); - goto out; - } - - bootp_response = malloc(size); - if (!bootp_response) - goto out; - - if (prom_getprop(chosen, propname, bootp_response, size) < 0) - goto out; + char *cfgpath = (_machine == _MACH_chrp) ? "/etc/" : ""; + int flen; + int minlen; - packet = bootp_response + offset; + packet = prom_get_netinfo(); /* * First, try to match on mac address with the hardware type @@ -517,35 +471,26 @@ static int load_my_config_file(struct boot_fspec_t *orig_fspec) if (!fspec.file) goto out; - if (_machine == _MACH_chrp) - sprintf(fspec.file, "/etc/%02x", packet->htype); - else - sprintf(fspec.file, "%02x", packet->htype); - - for (i = 0; i < packet->hlen; i++) { - char tmp[4]; - sprintf(tmp, "-%02x", packet->chaddr[i]); - strcat(fspec.file, tmp); - } + sprintf(fspec.file, "%s%02x-", cfgpath, packet->htype); + strcat(fspec.file, prom_get_mac(packet)); rc = load_config_file(&fspec); if (rc) goto out; - /* * Now try to match on IP. */ - free(fspec.file); - fspec.file = malloc(9); - sprintf(fspec.file, "%08X", packet->yiaddr); + /* no need to realloc for /etc/ + 8 chars in yiaddr + \0 */ + sprintf(fspec.file, "%s%s", cfgpath, prom_get_ip(packet)); - while (strlen(fspec.file)) { + for (flen = strlen(fspec.file), + minlen = strlen(cfgpath); flen > minlen; flen--) { rc = load_config_file(&fspec); if (rc) goto out; /* Chop one digit off the end, try again */ - fspec.file[strlen(fspec.file) - 1] = '\0'; + fspec.file[flen - 1] = '\0'; } out: @@ -553,7 +498,6 @@ static int load_my_config_file(struct boot_fspec_t *orig_fspec) orig_fspec->file = fspec.file; else free(fspec.file); - free(bootp_response); return rc; } @@ -1289,7 +1233,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) Elf32_Ehdr *e = &(loadinfo->elf.elf32hdr); Elf32_Phdr *p, *ph; int size = sizeof(Elf32_Ehdr) - sizeof(Elf_Ident); - unsigned long addr, loadaddr; + unsigned long loadaddr; /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { @@ -1377,13 +1321,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) loadaddr = loadinfo->load_loc; } - /* On some systems, loadaddr may already be claimed, so try some - * other nearby addresses before giving up. - */ - for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) { - loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0); - if (loadinfo->base != (void *)-1) break; - } + loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0); if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); goto bail; @@ -1433,7 +1371,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) Elf64_Ehdr *e = &(loadinfo->elf.elf64hdr); Elf64_Phdr *p, *ph; int size = sizeof(Elf64_Ehdr) - sizeof(Elf_Ident); - unsigned long addr, loadaddr; + unsigned long loadaddr; /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { @@ -1521,13 +1459,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) loadaddr = e->e_entry; } - /* On some systems, loadaddr may already be claimed, so try some - * other nearby addresses before giving up. - */ - for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) { - loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0); - if (loadinfo->base != (void *)-1) break; - } + loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0); if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); goto bail; @@ -1646,7 +1578,7 @@ setup_display(void) } if (scrn == PROM_INVALID_HANDLE) { - prom_printf("No screen device found !/n"); + prom_printf("No screen device found !\n"); return; } for(i=0;i<16;i++) {