1 // SPDX-License-Identifier: GPL-2.0-only
3 * PlanetCore configuration data support functions
7 * Copyright (c) 2007 Freescale Semiconductor, Inc.
13 #include "planetcore.h"
16 /* PlanetCore passes information to the OS in the form of
17 * a table of key=value strings, separated by newlines.
19 * The list is terminated by an empty string (i.e. two
20 * consecutive newlines).
22 * To make it easier to parse, we first convert all the
23 * newlines into null bytes.
26 void planetcore_prepare_table(char *table)
33 } while (*(table - 1) || *table != '\n');
38 const char *planetcore_get_key(const char *table, const char *key)
40 int keylen = strlen(key);
43 if (!strncmp(table, key, keylen) && table[keylen] == '=')
44 return table + keylen + 1;
46 table += strlen(table) + 1;
47 } while (strlen(table) != 0);
52 int planetcore_get_decimal(const char *table, const char *key, u64 *val)
54 const char *str = planetcore_get_key(table, key);
58 *val = strtoull(str, NULL, 10);
62 int planetcore_get_hex(const char *table, const char *key, u64 *val)
64 const char *str = planetcore_get_key(table, key);
68 *val = strtoull(str, NULL, 16);
72 static u64 mac_table[4] = {
79 void planetcore_set_mac_addrs(const char *table)
86 if (!planetcore_get_hex(table, PLANETCORE_KEY_MAC_ADDR, &int_addr))
89 for (i = 0; i < 4; i++) {
90 u64 this_dev_addr = (int_addr & ~0x000000c00000) |
93 for (j = 5; j >= 0; j--) {
94 addr[i][j] = this_dev_addr & 0xff;
98 dt_fixup_mac_address(i, addr[i]);
102 static char prop_buf[MAX_PROP_LEN];
104 void planetcore_set_stdout_path(const char *table)
110 label = planetcore_get_key(table, PLANETCORE_KEY_SERIAL_PORT);
114 node = find_node_by_prop_value_str(NULL, "linux,planetcore-label",
119 path = get_path(node, prop_buf, MAX_PROP_LEN);
123 chosen = finddevice("/chosen");
125 chosen = create_node(NULL, "chosen");
129 setprop_str(chosen, "linux,stdout-path", path);