2 * PlanetCore configuration data support functions
4 * Author: Scott Wood <scottwood@freescale.com>
6 * Copyright (c) 2007 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
16 #include "planetcore.h"
19 /* PlanetCore passes information to the OS in the form of
20 * a table of key=value strings, separated by newlines.
22 * The list is terminated by an empty string (i.e. two
23 * consecutive newlines).
25 * To make it easier to parse, we first convert all the
26 * newlines into null bytes.
29 void planetcore_prepare_table(char *table)
36 } while (*(table - 1) || *table != '\n');
41 const char *planetcore_get_key(const char *table, const char *key)
43 int keylen = strlen(key);
46 if (!strncmp(table, key, keylen) && table[keylen] == '=')
47 return table + keylen + 1;
49 table += strlen(table) + 1;
50 } while (strlen(table) != 0);
55 int planetcore_get_decimal(const char *table, const char *key, u64 *val)
57 const char *str = planetcore_get_key(table, key);
61 *val = strtoull(str, NULL, 10);
65 int planetcore_get_hex(const char *table, const char *key, u64 *val)
67 const char *str = planetcore_get_key(table, key);
71 *val = strtoull(str, NULL, 16);
75 static u64 mac_table[4] = {
82 void planetcore_set_mac_addrs(const char *table)
89 if (!planetcore_get_hex(table, PLANETCORE_KEY_MAC_ADDR, &int_addr))
92 for (i = 0; i < 4; i++) {
93 u64 this_dev_addr = (int_addr & ~0x000000c00000) |
96 for (j = 5; j >= 0; j--) {
97 addr[i][j] = this_dev_addr & 0xff;
101 dt_fixup_mac_address(i, addr[i]);
105 static char prop_buf[MAX_PROP_LEN];
107 void planetcore_set_stdout_path(const char *table)
113 label = planetcore_get_key(table, PLANETCORE_KEY_SERIAL_PORT);
117 node = find_node_by_prop_value_str(NULL, "linux,planetcore-label",
122 path = get_path(node, prop_buf, MAX_PROP_LEN);
126 chosen = finddevice("/chosen");
128 chosen = create_node(NULL, "chosen");
132 setprop_str(chosen, "linux,stdout-path", path);