X-Git-Url: http://git.ozlabs.org/?p=yaboot.git;a=blobdiff_plain;f=second%2Fprom.c;h=4ad727761b47a58f2a6b47869df912dd3de04df4;hp=5ec06b88e7e1426b33e5a04050e4e4c3c607cea3;hb=66ffb9d32d2acb3613594ef492d341b5bacf02e5;hpb=a2b7bb030d78c61ef150f8c9f6926c9558a6f1b5 diff --git a/second/prom.c b/second/prom.c index 5ec06b8..4ad7277 100644 --- a/second/prom.c +++ b/second/prom.c @@ -33,6 +33,7 @@ #include "asm/processor.h" #include "errors.h" #include "debug.h" +#include "string.h" #define READ_BLOCKS_USE_READ 1 @@ -153,6 +154,18 @@ prom_getprop (prom_handle pack, char *name, void *mem, int len) return (int)call_prom ("getprop", 4, 1, pack, name, mem, len); } +int +prom_getproplen(prom_handle pack, const char *name) +{ + return (int)call_prom("getproplen", 2, 1, pack, name); +} + +int +prom_setprop (prom_handle pack, char *name, void *mem, int len) +{ + return (int)call_prom ("setprop", 4, 1, pack, name, mem, len); +} + int prom_get_chosen (char *name, void *mem, int len) { @@ -167,6 +180,14 @@ prom_get_options (char *name, void *mem, int len) return prom_getprop (prom_options, name, mem, len); } +int +prom_set_options (char *name, void *mem, int len) +{ + if (prom_options == (void *)-1) + return -1; + return prom_setprop (prom_options, name, mem, len); +} + int prom_get_devtype (char *device) { @@ -174,6 +195,9 @@ prom_get_devtype (char *device) int result; char tmp[64]; + if (strstr(device, TOK_ISCSI)) + device = strcpy(tmp, "/vdevice/gscsi/disk"); + /* Find OF device phandle */ dev = prom_finddevice(device); if (dev == PROM_INVALID_HANDLE) { @@ -544,6 +568,25 @@ prom_sleep (int seconds) while (prom_getms() <= end); } +/* if address given is claimed look for other addresses to get the needed + * space before giving up + */ +void * +prom_claim_chunk(void *virt, unsigned int size, unsigned int align) +{ + void *found, *addr; + for(addr=virt; addr <= (void*)PROM_CLAIM_MAX_ADDR; + addr+=(0x100000/sizeof(addr))) { + found = prom_claim(addr, size, 0); + if (found != (void *)-1) { + DEBUG_F("claimed %i at 0x%x (0x%x)\n",size,(int)found,(int)virt); + return(found); + } + } + prom_printf("Claim error, can't allocate %x at 0x%x\n",size,(int)virt); + return((void*)-1); +} + void * prom_claim (void *virt, unsigned int size, unsigned int align) { @@ -631,6 +674,102 @@ prom_pause(void) call_prom("enter", 0, 0); } +/* + * prom_get_netinfo() + * returns the packet with all needed info for netboot + */ +struct bootp_packet * prom_get_netinfo (void) +{ + void *bootp_response = NULL; + char *propname; + struct bootp_packet *packet; + int i = 0, size, offset = 0; + prom_handle chosen; +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + + chosen = prom_finddevice("/chosen"); + if (chosen < 0) { + DEBUG_F("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) + return NULL; + + if (sizeof(*packet) > size - offset) { + prom_printf("Malformed %s property?\n", propname); + return NULL; + } + + bootp_response = malloc(size); + if (!bootp_response) + return NULL; + + if (prom_getprop(chosen, propname, bootp_response, size) < 0) + return NULL; + + packet = bootp_response + offset; + return packet; +} + +/* + * prom_get_mac() + * returns the mac addr of an net card + */ +char * prom_get_mac (struct bootp_packet * packet) +{ + char * conf_path; + int i; + + if (!packet) + return NULL; + + /* 3 chars per byte in chaddr + \0 */ + conf_path = malloc(packet->hlen * 3 + 1); + if (!conf_path) + return NULL; + sprintf(conf_path, "%02x", packet->chaddr[0]); + + for (i = 1; i < packet->hlen; i++) { + char tmp[4]; + sprintf(tmp, "-%02x", packet->chaddr[i]); + strcat(conf_path, tmp); + } + + return conf_path; +} + +/* + * prom_get_ip() + * returns the ip addr of an net card + */ +char * prom_get_ip (struct bootp_packet * packet) +{ + char * conf_path; + + if (!packet) + return NULL; + + /* 8 chars in yiaddr + \0 */ + conf_path = malloc(9); + if (!conf_path) + return NULL; + sprintf(conf_path, "%08x", packet->yiaddr); + + return conf_path; +} + /* * Local variables: * c-file-style: "k&r"