diff options
author | Scott Wood <scottwood@freescale.com> | 2007-09-24 16:09:49 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-10-02 21:48:43 -0400 |
commit | fec6047047fda307e47b9e87697144a89528c752 (patch) | |
tree | 7a02ba60a237d42c6883378b0314cbb2feea87f5 /arch/powerpc | |
parent | 27ff35d9026b5d41d66ed95b65d7819db4cf5fb1 (diff) |
[POWERPC] bootwrapper: Add PlanetCore firmware support
This is a library that board code can use to extract information from the
PlanetCore configuration keys. PlanetCore is used on various boards from
Embedded Planet.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/boot/Makefile | 2 | ||||
-rw-r--r-- | arch/powerpc/boot/planetcore.c | 166 | ||||
-rw-r--r-- | arch/powerpc/boot/planetcore.h | 49 |
3 files changed, 216 insertions, 1 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index b63e423428c7..a6bba9a69e66 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile | |||
@@ -45,7 +45,7 @@ src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ | |||
45 | ns16550.c serial.c simple_alloc.c div64.S util.S \ | 45 | ns16550.c serial.c simple_alloc.c div64.S util.S \ |
46 | gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ | 46 | gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ |
47 | 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ | 47 | 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ |
48 | cpm-serial.c stdlib.c mpc52xx-psc.c | 48 | cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c |
49 | src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \ | 49 | src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \ |
50 | cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ | 50 | cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ |
51 | ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \ | 51 | ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \ |
diff --git a/arch/powerpc/boot/planetcore.c b/arch/powerpc/boot/planetcore.c new file mode 100644 index 000000000000..0d8558a475bb --- /dev/null +++ b/arch/powerpc/boot/planetcore.c | |||
@@ -0,0 +1,166 @@ | |||
1 | /* | ||
2 | * PlanetCore configuration data support functions | ||
3 | * | ||
4 | * Author: Scott Wood <scottwood@freescale.com> | ||
5 | * | ||
6 | * Copyright (c) 2007 Freescale Semiconductor, Inc. | ||
7 | * | ||
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. | ||
11 | */ | ||
12 | |||
13 | #include "stdio.h" | ||
14 | #include "stdlib.h" | ||
15 | #include "ops.h" | ||
16 | #include "planetcore.h" | ||
17 | #include "io.h" | ||
18 | |||
19 | /* PlanetCore passes information to the OS in the form of | ||
20 | * a table of key=value strings, separated by newlines. | ||
21 | * | ||
22 | * The list is terminated by an empty string (i.e. two | ||
23 | * consecutive newlines). | ||
24 | * | ||
25 | * To make it easier to parse, we first convert all the | ||
26 | * newlines into null bytes. | ||
27 | */ | ||
28 | |||
29 | void planetcore_prepare_table(char *table) | ||
30 | { | ||
31 | do { | ||
32 | if (*table == '\n') | ||
33 | *table = 0; | ||
34 | |||
35 | table++; | ||
36 | } while (*(table - 1) || *table != '\n'); | ||
37 | |||
38 | *table = 0; | ||
39 | } | ||
40 | |||
41 | const char *planetcore_get_key(const char *table, const char *key) | ||
42 | { | ||
43 | int keylen = strlen(key); | ||
44 | |||
45 | do { | ||
46 | if (!strncmp(table, key, keylen) && table[keylen] == '=') | ||
47 | return table + keylen + 1; | ||
48 | |||
49 | table += strlen(table) + 1; | ||
50 | } while (strlen(table) != 0); | ||
51 | |||
52 | return NULL; | ||
53 | } | ||
54 | |||
55 | int planetcore_get_decimal(const char *table, const char *key, u64 *val) | ||
56 | { | ||
57 | const char *str = planetcore_get_key(table, key); | ||
58 | if (!str) | ||
59 | return 0; | ||
60 | |||
61 | *val = strtoull(str, NULL, 10); | ||
62 | return 1; | ||
63 | } | ||
64 | |||
65 | int planetcore_get_hex(const char *table, const char *key, u64 *val) | ||
66 | { | ||
67 | const char *str = planetcore_get_key(table, key); | ||
68 | if (!str) | ||
69 | return 0; | ||
70 | |||
71 | *val = strtoull(str, NULL, 16); | ||
72 | return 1; | ||
73 | } | ||
74 | |||
75 | static u64 mac_table[4] = { | ||
76 | 0x000000000000, | ||
77 | 0x000000800000, | ||
78 | 0x000000400000, | ||
79 | 0x000000c00000, | ||
80 | }; | ||
81 | |||
82 | void planetcore_set_mac_addrs(const char *table) | ||
83 | { | ||
84 | u8 addr[4][6]; | ||
85 | u64 int_addr; | ||
86 | u32 i; | ||
87 | int j; | ||
88 | |||
89 | if (!planetcore_get_hex(table, PLANETCORE_KEY_MAC_ADDR, &int_addr)) | ||
90 | return; | ||
91 | |||
92 | for (i = 0; i < 4; i++) { | ||
93 | u64 this_dev_addr = (int_addr & ~0x000000c00000) | | ||
94 | mac_table[i]; | ||
95 | |||
96 | for (j = 5; j >= 0; j--) { | ||
97 | addr[i][j] = this_dev_addr & 0xff; | ||
98 | this_dev_addr >>= 8; | ||
99 | } | ||
100 | |||
101 | dt_fixup_mac_address(i, addr[i]); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static char prop_buf[MAX_PROP_LEN]; | ||
106 | |||
107 | void planetcore_set_stdout_path(const char *table) | ||
108 | { | ||
109 | char *path; | ||
110 | const char *label; | ||
111 | void *node, *chosen; | ||
112 | |||
113 | label = planetcore_get_key(table, PLANETCORE_KEY_SERIAL_PORT); | ||
114 | if (!label) | ||
115 | return; | ||
116 | |||
117 | node = find_node_by_prop_value_str(NULL, "linux,planetcore-label", | ||
118 | label); | ||
119 | if (!node) | ||
120 | return; | ||
121 | |||
122 | path = get_path(node, prop_buf, MAX_PROP_LEN); | ||
123 | if (!path) | ||
124 | return; | ||
125 | |||
126 | chosen = finddevice("/chosen"); | ||
127 | if (!chosen) | ||
128 | chosen = create_node(NULL, "chosen"); | ||
129 | if (!chosen) | ||
130 | return; | ||
131 | |||
132 | setprop_str(chosen, "linux,stdout-path", path); | ||
133 | } | ||
134 | |||
135 | void planetcore_set_serial_speed(const char *table) | ||
136 | { | ||
137 | void *chosen, *stdout; | ||
138 | u64 baud; | ||
139 | u32 baud32; | ||
140 | int len; | ||
141 | |||
142 | chosen = finddevice("/chosen"); | ||
143 | if (!chosen) | ||
144 | return; | ||
145 | |||
146 | len = getprop(chosen, "linux,stdout-path", prop_buf, MAX_PROP_LEN); | ||
147 | if (len <= 0) | ||
148 | return; | ||
149 | |||
150 | stdout = finddevice(prop_buf); | ||
151 | if (!stdout) { | ||
152 | printf("planetcore_set_serial_speed: " | ||
153 | "Bad /chosen/linux,stdout-path.\r\n"); | ||
154 | |||
155 | return; | ||
156 | } | ||
157 | |||
158 | if (!planetcore_get_decimal(table, PLANETCORE_KEY_SERIAL_BAUD, | ||
159 | &baud)) { | ||
160 | printf("planetcore_set_serial_speed: No SB tag.\r\n"); | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | baud32 = baud; | ||
165 | setprop(stdout, "current-speed", &baud32, 4); | ||
166 | } | ||
diff --git a/arch/powerpc/boot/planetcore.h b/arch/powerpc/boot/planetcore.h new file mode 100644 index 000000000000..0d4094f1771c --- /dev/null +++ b/arch/powerpc/boot/planetcore.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef _PPC_BOOT_PLANETCORE_H_ | ||
2 | #define _PPC_BOOT_PLANETCORE_H_ | ||
3 | |||
4 | #include "types.h" | ||
5 | |||
6 | #define PLANETCORE_KEY_BOARD_TYPE "BO" | ||
7 | #define PLANETCORE_KEY_BOARD_REV "BR" | ||
8 | #define PLANETCORE_KEY_MB_RAM "D1" | ||
9 | #define PLANETCORE_KEY_MAC_ADDR "EA" | ||
10 | #define PLANETCORE_KEY_FLASH_SPEED "FS" | ||
11 | #define PLANETCORE_KEY_IP_ADDR "IP" | ||
12 | #define PLANETCORE_KEY_KB_NVRAM "NV" | ||
13 | #define PLANETCORE_KEY_PROCESSOR "PR" | ||
14 | #define PLANETCORE_KEY_PROC_VARIANT "PV" | ||
15 | #define PLANETCORE_KEY_SERIAL_BAUD "SB" | ||
16 | #define PLANETCORE_KEY_SERIAL_PORT "SP" | ||
17 | #define PLANETCORE_KEY_SWITCH "SW" | ||
18 | #define PLANETCORE_KEY_TEMP_OFFSET "TC" | ||
19 | #define PLANETCORE_KEY_TARGET_IP "TIP" | ||
20 | #define PLANETCORE_KEY_CRYSTAL_HZ "XT" | ||
21 | |||
22 | /* Prepare the table for processing, by turning all newlines | ||
23 | * into NULL bytes. | ||
24 | */ | ||
25 | void planetcore_prepare_table(char *table); | ||
26 | |||
27 | /* Return the value associated with a given key in text, | ||
28 | * decimal, or hex format. | ||
29 | * | ||
30 | * Returns zero/NULL on failure, non-zero on success. | ||
31 | */ | ||
32 | const char *planetcore_get_key(const char *table, const char *key); | ||
33 | int planetcore_get_decimal(const char *table, const char *key, u64 *val); | ||
34 | int planetcore_get_hex(const char *table, const char *key, u64 *val); | ||
35 | |||
36 | /* Updates the device tree local-mac-address properties based | ||
37 | * on the EA tag. | ||
38 | */ | ||
39 | void planetcore_set_mac_addrs(const char *table); | ||
40 | |||
41 | /* Sets the linux,stdout-path in the /chosen node. This requires the | ||
42 | * linux,planetcore-label property in each serial node. | ||
43 | */ | ||
44 | void planetcore_set_stdout_path(const char *table); | ||
45 | |||
46 | /* Sets the current-speed property in the serial node. */ | ||
47 | void planetcore_set_serial_speed(const char *table); | ||
48 | |||
49 | #endif | ||