Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com |
| 4 | * Based on code written by: |
| 5 | * Pantelis Antoniou <pantelis.antoniou@gmail.com> and |
| 6 | * Matthew McClintock <msm@freescale.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <linux/ctype.h> |
| 30 | #include <linux/types.h> |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 31 | #include <asm/global_data.h> |
| 32 | #include <fdt.h> |
| 33 | #include <libfdt.h> |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 34 | #include <fdt_support.h> |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 35 | |
| 36 | #define MAX_LEVEL 32 /* how deeply nested we will go */ |
Gerald Van Baren | 5606a36 | 2007-06-25 23:25:28 -0400 | [diff] [blame] | 37 | #define SCRATCHPAD 1024 /* bytes of scratchpad memory */ |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 38 | #ifndef CONFIG_CMD_FDT_MAX_DUMP |
| 39 | #define CONFIG_CMD_FDT_MAX_DUMP 64 |
| 40 | #endif |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Global data (for the gd->bd) |
| 44 | */ |
| 45 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 47 | static int fdt_valid(void); |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 48 | static int fdt_parse_prop(char *const*newval, int count, char *data, int *len); |
Kumar Gala | 1e386af | 2007-11-21 14:07:46 -0600 | [diff] [blame] | 49 | static int fdt_print(const char *pathp, char *prop, int depth); |
Joe Hershberger | fc5abf0 | 2012-08-17 10:34:37 +0000 | [diff] [blame] | 50 | static int is_printable_string(const void *data, int len); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 51 | |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 52 | /* |
Gerald Van Baren | e81ce61 | 2008-06-10 22:15:58 -0400 | [diff] [blame] | 53 | * The working_fdt points to our working flattened device tree. |
| 54 | */ |
| 55 | struct fdt_header *working_fdt; |
| 56 | |
Kumar Gala | 9f4e7e4 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 57 | void set_working_fdt_addr(void *addr) |
| 58 | { |
| 59 | char buf[17]; |
| 60 | |
| 61 | working_fdt = addr; |
| 62 | |
| 63 | sprintf(buf, "%lx", (unsigned long)addr); |
| 64 | setenv("fdtaddr", buf); |
| 65 | } |
| 66 | |
Gerald Van Baren | e81ce61 | 2008-06-10 22:15:58 -0400 | [diff] [blame] | 67 | /* |
Joe Hershberger | fc5abf0 | 2012-08-17 10:34:37 +0000 | [diff] [blame] | 68 | * Get a value from the fdt and format it to be set in the environment |
| 69 | */ |
| 70 | static int fdt_value_setenv(const void *nodep, int len, const char *var) |
| 71 | { |
| 72 | if (is_printable_string(nodep, len)) |
| 73 | setenv(var, (void *)nodep); |
| 74 | else if (len == 4) { |
| 75 | char buf[11]; |
| 76 | |
| 77 | sprintf(buf, "0x%08X", *(uint32_t *)nodep); |
| 78 | setenv(var, buf); |
| 79 | } else if (len%4 == 0 && len <= 20) { |
| 80 | /* Needed to print things like sha1 hashes. */ |
| 81 | char buf[41]; |
| 82 | int i; |
| 83 | |
| 84 | for (i = 0; i < len; i += sizeof(unsigned int)) |
| 85 | sprintf(buf + (i * 2), "%08x", |
| 86 | *(unsigned int *)(nodep + i)); |
| 87 | setenv(var, buf); |
| 88 | } else { |
| 89 | printf("error: unprintable value\n"); |
| 90 | return 1; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | /* |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 96 | * Flattened Device Tree command, see the help for parameter definitions. |
| 97 | */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 98 | static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 99 | { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 100 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 101 | return CMD_RET_USAGE; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 102 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 103 | /* |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 104 | * Set the address of the fdt |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 105 | */ |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 106 | if (argv[1][0] == 'a') { |
Kumar Gala | 9f4e7e4 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 107 | unsigned long addr; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 108 | /* |
| 109 | * Set the address [and length] of the fdt. |
| 110 | */ |
Kumar Gala | 708a18b | 2008-08-15 08:24:35 -0500 | [diff] [blame] | 111 | if (argc == 2) { |
| 112 | if (!fdt_valid()) { |
| 113 | return 1; |
| 114 | } |
| 115 | printf("The address of the fdt is %p\n", working_fdt); |
| 116 | return 0; |
| 117 | } |
| 118 | |
Kumar Gala | 9f4e7e4 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 119 | addr = simple_strtoul(argv[2], NULL, 16); |
| 120 | set_working_fdt_addr((void *)addr); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 121 | |
| 122 | if (!fdt_valid()) { |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | if (argc >= 4) { |
| 127 | int len; |
| 128 | int err; |
| 129 | /* |
| 130 | * Optional new length |
| 131 | */ |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 132 | len = simple_strtoul(argv[3], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 133 | if (len < fdt_totalsize(working_fdt)) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 134 | printf ("New length %d < existing length %d, " |
| 135 | "ignoring.\n", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 136 | len, fdt_totalsize(working_fdt)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 137 | } else { |
| 138 | /* |
| 139 | * Open in place with a new length. |
| 140 | */ |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 141 | err = fdt_open_into(working_fdt, working_fdt, len); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 142 | if (err != 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 143 | printf ("libfdt fdt_open_into(): %s\n", |
| 144 | fdt_strerror(err)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Marek Vasut | aeccfee | 2012-09-05 08:34:44 +0200 | [diff] [blame] | 149 | return CMD_RET_SUCCESS; |
| 150 | } |
| 151 | |
| 152 | if (!working_fdt) { |
| 153 | puts( |
| 154 | "No FDT memory address configured. Please configure\n" |
| 155 | "the FDT address via \"fdt addr <address>\" command.\n" |
| 156 | "Aborting!\n"); |
| 157 | return CMD_RET_FAILURE; |
| 158 | } |
| 159 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 160 | /* |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 161 | * Move the working_fdt |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 162 | */ |
Marek Vasut | aeccfee | 2012-09-05 08:34:44 +0200 | [diff] [blame] | 163 | if (strncmp(argv[1], "mo", 2) == 0) { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 164 | struct fdt_header *newaddr; |
| 165 | int len; |
| 166 | int err; |
| 167 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 168 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 169 | return CMD_RET_USAGE; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Set the address and length of the fdt. |
| 173 | */ |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 174 | working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 175 | if (!fdt_valid()) { |
| 176 | return 1; |
| 177 | } |
| 178 | |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 179 | newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16); |
Gerald Van Baren | 4d22392 | 2007-04-25 22:47:15 -0400 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * If the user specifies a length, use that. Otherwise use the |
| 183 | * current length. |
| 184 | */ |
| 185 | if (argc <= 4) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 186 | len = fdt_totalsize(working_fdt); |
Gerald Van Baren | 4d22392 | 2007-04-25 22:47:15 -0400 | [diff] [blame] | 187 | } else { |
| 188 | len = simple_strtoul(argv[4], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 189 | if (len < fdt_totalsize(working_fdt)) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 190 | printf ("New length 0x%X < existing length " |
| 191 | "0x%X, aborting.\n", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 192 | len, fdt_totalsize(working_fdt)); |
Gerald Van Baren | 4d22392 | 2007-04-25 22:47:15 -0400 | [diff] [blame] | 193 | return 1; |
| 194 | } |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Copy to the new location. |
| 199 | */ |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 200 | err = fdt_open_into(working_fdt, newaddr, len); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 201 | if (err != 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 202 | printf ("libfdt fdt_open_into(): %s\n", |
| 203 | fdt_strerror(err)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 204 | return 1; |
| 205 | } |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 206 | working_fdt = newaddr; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 207 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 208 | /* |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 209 | * Make a new node |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 210 | */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 211 | } else if (strncmp(argv[1], "mk", 2) == 0) { |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 212 | char *pathp; /* path */ |
| 213 | char *nodep; /* new node to add */ |
| 214 | int nodeoffset; /* node offset from libfdt */ |
| 215 | int err; |
| 216 | |
| 217 | /* |
| 218 | * Parameters: Node path, new node to be appended to the path. |
| 219 | */ |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 220 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 221 | return CMD_RET_USAGE; |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 222 | |
| 223 | pathp = argv[2]; |
| 224 | nodep = argv[3]; |
| 225 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 226 | nodeoffset = fdt_path_offset (working_fdt, pathp); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 227 | if (nodeoffset < 0) { |
| 228 | /* |
| 229 | * Not found or something else bad happened. |
| 230 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 231 | printf ("libfdt fdt_path_offset() returned %s\n", |
Gerald Van Baren | 1178d6a | 2007-05-21 23:27:16 -0400 | [diff] [blame] | 232 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 233 | return 1; |
| 234 | } |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 235 | err = fdt_add_subnode(working_fdt, nodeoffset, nodep); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 236 | if (err < 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 237 | printf ("libfdt fdt_add_subnode(): %s\n", |
| 238 | fdt_strerror(err)); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 239 | return 1; |
| 240 | } |
| 241 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 242 | /* |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 243 | * Set the value of a property in the working_fdt. |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 244 | */ |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 245 | } else if (argv[1][0] == 's') { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 246 | char *pathp; /* path */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 247 | char *prop; /* property */ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 248 | int nodeoffset; /* node offset from libfdt */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 249 | static char data[SCRATCHPAD]; /* storage for the property */ |
| 250 | int len; /* new length of the property */ |
| 251 | int ret; /* return value */ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 252 | |
| 253 | /* |
Gerald Van Baren | d91383a | 2008-01-05 14:52:04 -0500 | [diff] [blame] | 254 | * Parameters: Node path, property, optional value. |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 255 | */ |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 256 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 257 | return CMD_RET_USAGE; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 258 | |
| 259 | pathp = argv[2]; |
| 260 | prop = argv[3]; |
Gerald Van Baren | d91383a | 2008-01-05 14:52:04 -0500 | [diff] [blame] | 261 | if (argc == 4) { |
| 262 | len = 0; |
| 263 | } else { |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 264 | ret = fdt_parse_prop(&argv[4], argc - 4, data, &len); |
Gerald Van Baren | d91383a | 2008-01-05 14:52:04 -0500 | [diff] [blame] | 265 | if (ret != 0) |
| 266 | return ret; |
| 267 | } |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 268 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 269 | nodeoffset = fdt_path_offset (working_fdt, pathp); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 270 | if (nodeoffset < 0) { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 271 | /* |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 272 | * Not found or something else bad happened. |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 273 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 274 | printf ("libfdt fdt_path_offset() returned %s\n", |
Gerald Van Baren | 1178d6a | 2007-05-21 23:27:16 -0400 | [diff] [blame] | 275 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 276 | return 1; |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 277 | } |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 278 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 279 | ret = fdt_setprop(working_fdt, nodeoffset, prop, data, len); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 280 | if (ret < 0) { |
| 281 | printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret)); |
| 282 | return 1; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Joe Hershberger | fc5abf0 | 2012-08-17 10:34:37 +0000 | [diff] [blame] | 285 | /******************************************************************** |
| 286 | * Get the value of a property in the working_fdt. |
| 287 | ********************************************************************/ |
| 288 | } else if (argv[1][0] == 'g') { |
| 289 | char *subcmd; /* sub-command */ |
| 290 | char *pathp; /* path */ |
| 291 | char *prop; /* property */ |
| 292 | char *var; /* variable to store result */ |
| 293 | int nodeoffset; /* node offset from libfdt */ |
| 294 | const void *nodep; /* property node pointer */ |
| 295 | int len = 0; /* new length of the property */ |
| 296 | |
| 297 | /* |
| 298 | * Parameters: Node path, property, optional value. |
| 299 | */ |
| 300 | if (argc < 5) |
| 301 | return CMD_RET_USAGE; |
| 302 | |
| 303 | subcmd = argv[2]; |
| 304 | |
| 305 | if (argc < 6 && subcmd[0] != 's') |
| 306 | return CMD_RET_USAGE; |
| 307 | |
| 308 | var = argv[3]; |
| 309 | pathp = argv[4]; |
| 310 | prop = argv[5]; |
| 311 | |
| 312 | nodeoffset = fdt_path_offset(working_fdt, pathp); |
| 313 | if (nodeoffset < 0) { |
| 314 | /* |
| 315 | * Not found or something else bad happened. |
| 316 | */ |
| 317 | printf("libfdt fdt_path_offset() returned %s\n", |
| 318 | fdt_strerror(nodeoffset)); |
| 319 | return 1; |
| 320 | } |
| 321 | |
| 322 | if (subcmd[0] == 'n' || (subcmd[0] == 's' && argc == 5)) { |
| 323 | int reqIndex = -1; |
| 324 | int startDepth = fdt_node_depth( |
| 325 | working_fdt, nodeoffset); |
| 326 | int curDepth = startDepth; |
| 327 | int curIndex = -1; |
| 328 | int nextNodeOffset = fdt_next_node( |
| 329 | working_fdt, nodeoffset, &curDepth); |
| 330 | |
| 331 | if (subcmd[0] == 'n') |
| 332 | reqIndex = simple_strtoul(argv[5], NULL, 16); |
| 333 | |
| 334 | while (curDepth > startDepth) { |
| 335 | if (curDepth == startDepth + 1) |
| 336 | curIndex++; |
| 337 | if (subcmd[0] == 'n' && curIndex == reqIndex) { |
| 338 | const char *nodeName = fdt_get_name( |
| 339 | working_fdt, nextNodeOffset, NULL); |
| 340 | |
| 341 | setenv(var, (char *)nodeName); |
| 342 | return 0; |
| 343 | } |
| 344 | nextNodeOffset = fdt_next_node( |
| 345 | working_fdt, nextNodeOffset, &curDepth); |
| 346 | if (nextNodeOffset < 0) |
| 347 | break; |
| 348 | } |
| 349 | if (subcmd[0] == 's') { |
| 350 | /* get the num nodes at this level */ |
| 351 | char buf[11]; |
| 352 | |
| 353 | sprintf(buf, "%d", curIndex + 1); |
| 354 | setenv(var, buf); |
| 355 | } else { |
| 356 | /* node index not found */ |
| 357 | printf("libfdt node not found\n"); |
| 358 | return 1; |
| 359 | } |
| 360 | } else { |
| 361 | nodep = fdt_getprop( |
| 362 | working_fdt, nodeoffset, prop, &len); |
| 363 | if (len == 0) { |
| 364 | /* no property value */ |
| 365 | setenv(var, ""); |
| 366 | return 0; |
| 367 | } else if (len > 0) { |
| 368 | if (subcmd[0] == 'v') { |
| 369 | int ret; |
| 370 | |
| 371 | ret = fdt_value_setenv(nodep, len, var); |
| 372 | if (ret != 0) |
| 373 | return ret; |
| 374 | } else if (subcmd[0] == 'a') { |
| 375 | /* Get address */ |
| 376 | char buf[11]; |
| 377 | |
Tom Rini | 1db8b53 | 2012-10-29 14:53:18 +0000 | [diff] [blame] | 378 | sprintf(buf, "0x%p", nodep); |
Joe Hershberger | fc5abf0 | 2012-08-17 10:34:37 +0000 | [diff] [blame] | 379 | setenv(var, buf); |
| 380 | } else if (subcmd[0] == 's') { |
| 381 | /* Get size */ |
| 382 | char buf[11]; |
| 383 | |
| 384 | sprintf(buf, "0x%08X", len); |
| 385 | setenv(var, buf); |
| 386 | } else |
| 387 | return CMD_RET_USAGE; |
| 388 | return 0; |
| 389 | } else { |
| 390 | printf("libfdt fdt_getprop(): %s\n", |
| 391 | fdt_strerror(len)); |
| 392 | return 1; |
| 393 | } |
| 394 | } |
| 395 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 396 | /* |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 397 | * Print (recursive) / List (single level) |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 398 | */ |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 399 | } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 400 | int depth = MAX_LEVEL; /* how deep to print */ |
| 401 | char *pathp; /* path */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 402 | char *prop; /* property */ |
| 403 | int ret; /* return value */ |
Kumar Gala | 51ab7f9 | 2007-10-25 16:15:07 -0500 | [diff] [blame] | 404 | static char root[2] = "/"; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 405 | |
| 406 | /* |
| 407 | * list is an alias for print, but limited to 1 level |
| 408 | */ |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 409 | if (argv[1][0] == 'l') { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 410 | depth = 1; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Get the starting path. The root node is an oddball, |
| 415 | * the offset is zero and has no name. |
| 416 | */ |
Kumar Gala | 51ab7f9 | 2007-10-25 16:15:07 -0500 | [diff] [blame] | 417 | if (argc == 2) |
| 418 | pathp = root; |
| 419 | else |
| 420 | pathp = argv[2]; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 421 | if (argc > 3) |
| 422 | prop = argv[3]; |
| 423 | else |
| 424 | prop = NULL; |
| 425 | |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 426 | ret = fdt_print(pathp, prop, depth); |
| 427 | if (ret != 0) |
| 428 | return ret; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 429 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 430 | /* |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 431 | * Remove a property/node |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 432 | */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 433 | } else if (strncmp(argv[1], "rm", 2) == 0) { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 434 | int nodeoffset; /* node offset from libfdt */ |
| 435 | int err; |
| 436 | |
| 437 | /* |
| 438 | * Get the path. The root node is an oddball, the offset |
| 439 | * is zero and has no name. |
| 440 | */ |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 441 | nodeoffset = fdt_path_offset (working_fdt, argv[2]); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 442 | if (nodeoffset < 0) { |
| 443 | /* |
| 444 | * Not found or something else bad happened. |
| 445 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 446 | printf ("libfdt fdt_path_offset() returned %s\n", |
Gerald Van Baren | 1178d6a | 2007-05-21 23:27:16 -0400 | [diff] [blame] | 447 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 448 | return 1; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 449 | } |
| 450 | /* |
| 451 | * Do the delete. A fourth parameter means delete a property, |
| 452 | * otherwise delete the node. |
| 453 | */ |
| 454 | if (argc > 3) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 455 | err = fdt_delprop(working_fdt, nodeoffset, argv[3]); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 456 | if (err < 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 457 | printf("libfdt fdt_delprop(): %s\n", |
| 458 | fdt_strerror(err)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 459 | return err; |
| 460 | } |
| 461 | } else { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 462 | err = fdt_del_node(working_fdt, nodeoffset); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 463 | if (err < 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 464 | printf("libfdt fdt_del_node(): %s\n", |
| 465 | fdt_strerror(err)); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 466 | return err; |
| 467 | } |
| 468 | } |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 469 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 470 | /* |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 471 | * Display header info |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 472 | */ |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 473 | } else if (argv[1][0] == 'h') { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 474 | u32 version = fdt_version(working_fdt); |
| 475 | printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt)); |
| 476 | printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt), |
| 477 | fdt_totalsize(working_fdt)); |
| 478 | printf("off_dt_struct:\t\t0x%x\n", |
| 479 | fdt_off_dt_struct(working_fdt)); |
| 480 | printf("off_dt_strings:\t\t0x%x\n", |
| 481 | fdt_off_dt_strings(working_fdt)); |
| 482 | printf("off_mem_rsvmap:\t\t0x%x\n", |
| 483 | fdt_off_mem_rsvmap(working_fdt)); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 484 | printf("version:\t\t%d\n", version); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 485 | printf("last_comp_version:\t%d\n", |
| 486 | fdt_last_comp_version(working_fdt)); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 487 | if (version >= 2) |
| 488 | printf("boot_cpuid_phys:\t0x%x\n", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 489 | fdt_boot_cpuid_phys(working_fdt)); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 490 | if (version >= 3) |
| 491 | printf("size_dt_strings:\t0x%x\n", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 492 | fdt_size_dt_strings(working_fdt)); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 493 | if (version >= 17) |
| 494 | printf("size_dt_struct:\t\t0x%x\n", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 495 | fdt_size_dt_struct(working_fdt)); |
| 496 | printf("number mem_rsv:\t\t0x%x\n", |
| 497 | fdt_num_mem_rsv(working_fdt)); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 498 | printf("\n"); |
| 499 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 500 | /* |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 501 | * Set boot cpu id |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 502 | */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 503 | } else if (strncmp(argv[1], "boo", 3) == 0) { |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 504 | unsigned long tmp = simple_strtoul(argv[2], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 505 | fdt_set_boot_cpuid_phys(working_fdt, tmp); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 506 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 507 | /* |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 508 | * memory command |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 509 | */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 510 | } else if (strncmp(argv[1], "me", 2) == 0) { |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 511 | uint64_t addr, size; |
| 512 | int err; |
Heiko Schocher | 0f602e1 | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 513 | addr = simple_strtoull(argv[2], NULL, 16); |
| 514 | size = simple_strtoull(argv[3], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 515 | err = fdt_fixup_memory(working_fdt, addr, size); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 516 | if (err < 0) |
| 517 | return err; |
| 518 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 519 | /* |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 520 | * mem reserve commands |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 521 | */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 522 | } else if (strncmp(argv[1], "rs", 2) == 0) { |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 523 | if (argv[2][0] == 'p') { |
| 524 | uint64_t addr, size; |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 525 | int total = fdt_num_mem_rsv(working_fdt); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 526 | int j, err; |
| 527 | printf("index\t\t start\t\t size\n"); |
| 528 | printf("-------------------------------" |
| 529 | "-----------------\n"); |
| 530 | for (j = 0; j < total; j++) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 531 | err = fdt_get_mem_rsv(working_fdt, j, &addr, &size); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 532 | if (err < 0) { |
| 533 | printf("libfdt fdt_get_mem_rsv(): %s\n", |
| 534 | fdt_strerror(err)); |
| 535 | return err; |
| 536 | } |
| 537 | printf(" %x\t%08x%08x\t%08x%08x\n", j, |
| 538 | (u32)(addr >> 32), |
| 539 | (u32)(addr & 0xffffffff), |
| 540 | (u32)(size >> 32), |
| 541 | (u32)(size & 0xffffffff)); |
| 542 | } |
| 543 | } else if (argv[2][0] == 'a') { |
| 544 | uint64_t addr, size; |
| 545 | int err; |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 546 | addr = simple_strtoull(argv[3], NULL, 16); |
| 547 | size = simple_strtoull(argv[4], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 548 | err = fdt_add_mem_rsv(working_fdt, addr, size); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 549 | |
| 550 | if (err < 0) { |
| 551 | printf("libfdt fdt_add_mem_rsv(): %s\n", |
| 552 | fdt_strerror(err)); |
| 553 | return err; |
| 554 | } |
| 555 | } else if (argv[2][0] == 'd') { |
| 556 | unsigned long idx = simple_strtoul(argv[3], NULL, 16); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 557 | int err = fdt_del_mem_rsv(working_fdt, idx); |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 558 | |
| 559 | if (err < 0) { |
| 560 | printf("libfdt fdt_del_mem_rsv(): %s\n", |
| 561 | fdt_strerror(err)); |
| 562 | return err; |
| 563 | } |
| 564 | } else { |
| 565 | /* Unrecognized command */ |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 566 | return CMD_RET_USAGE; |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 567 | } |
Kim Phillips | bd9d115 | 2007-07-17 13:57:04 -0500 | [diff] [blame] | 568 | } |
Gerald Van Baren | 5606a36 | 2007-06-25 23:25:28 -0400 | [diff] [blame] | 569 | #ifdef CONFIG_OF_BOARD_SETUP |
Kim Phillips | bd9d115 | 2007-07-17 13:57:04 -0500 | [diff] [blame] | 570 | /* Call the board-specific fixup routine */ |
Gerald Van Baren | 3b9d629 | 2008-06-09 21:02:17 -0400 | [diff] [blame] | 571 | else if (strncmp(argv[1], "boa", 3) == 0) |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 572 | ft_board_setup(working_fdt, gd->bd); |
Gerald Van Baren | 5606a36 | 2007-06-25 23:25:28 -0400 | [diff] [blame] | 573 | #endif |
Kim Phillips | bd9d115 | 2007-07-17 13:57:04 -0500 | [diff] [blame] | 574 | /* Create a chosen node */ |
Kumar Gala | fb5dcd5 | 2008-08-15 08:24:34 -0500 | [diff] [blame] | 575 | else if (argv[1][0] == 'c') { |
| 576 | unsigned long initrd_start = 0, initrd_end = 0; |
| 577 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 578 | if ((argc != 2) && (argc != 4)) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 579 | return CMD_RET_USAGE; |
Kumar Gala | fb5dcd5 | 2008-08-15 08:24:34 -0500 | [diff] [blame] | 580 | |
| 581 | if (argc == 4) { |
| 582 | initrd_start = simple_strtoul(argv[2], NULL, 16); |
| 583 | initrd_end = simple_strtoul(argv[3], NULL, 16); |
| 584 | } |
| 585 | |
Heiko Schocher | d29abae | 2008-09-11 08:11:23 +0200 | [diff] [blame] | 586 | fdt_chosen(working_fdt, 1); |
| 587 | fdt_initrd(working_fdt, initrd_start, initrd_end, 1); |
Kumar Gala | 58911df | 2008-08-15 08:24:44 -0500 | [diff] [blame] | 588 | } |
| 589 | /* resize the fdt */ |
| 590 | else if (strncmp(argv[1], "re", 2) == 0) { |
| 591 | fdt_resize(working_fdt); |
| 592 | } |
| 593 | else { |
Kim Phillips | bd9d115 | 2007-07-17 13:57:04 -0500 | [diff] [blame] | 594 | /* Unrecognized command */ |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 595 | return CMD_RET_USAGE; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 601 | /****************************************************************************/ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 602 | |
| 603 | static int fdt_valid(void) |
| 604 | { |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 605 | int err; |
| 606 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 607 | if (working_fdt == NULL) { |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 608 | printf ("The address of the fdt is invalid (NULL).\n"); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 609 | return 0; |
| 610 | } |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 611 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 612 | err = fdt_check_header(working_fdt); |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 613 | if (err == 0) |
| 614 | return 1; /* valid */ |
| 615 | |
| 616 | if (err < 0) { |
Gerald Van Baren | 0ea55d2 | 2007-05-12 09:47:25 -0400 | [diff] [blame] | 617 | printf("libfdt fdt_check_header(): %s", fdt_strerror(err)); |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 618 | /* |
| 619 | * Be more informative on bad version. |
| 620 | */ |
| 621 | if (err == -FDT_ERR_BADVERSION) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 622 | if (fdt_version(working_fdt) < |
| 623 | FDT_FIRST_SUPPORTED_VERSION) { |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 624 | printf (" - too old, fdt %d < %d", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 625 | fdt_version(working_fdt), |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 626 | FDT_FIRST_SUPPORTED_VERSION); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 627 | working_fdt = NULL; |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 628 | } |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 629 | if (fdt_last_comp_version(working_fdt) > |
| 630 | FDT_LAST_SUPPORTED_VERSION) { |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 631 | printf (" - too new, fdt %d > %d", |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 632 | fdt_version(working_fdt), |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 633 | FDT_LAST_SUPPORTED_VERSION); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 634 | working_fdt = NULL; |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 635 | } |
| 636 | return 0; |
| 637 | } |
| 638 | printf("\n"); |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | return 1; |
| 642 | } |
| 643 | |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 644 | /****************************************************************************/ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 645 | |
| 646 | /* |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 647 | * Parse the user's input, partially heuristic. Valid formats: |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 648 | * <0x00112233 4 05> - an array of cells. Numbers follow standard |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 649 | * C conventions. |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 650 | * [00 11 22 .. nn] - byte stream |
| 651 | * "string" - If the the value doesn't start with "<" or "[", it is |
| 652 | * treated as a string. Note that the quotes are |
| 653 | * stripped by the parser before we get the string. |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 654 | * newval: An array of strings containing the new property as specified |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 655 | * on the command line |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 656 | * count: The number of strings in the array |
| 657 | * data: A bytestream to be placed in the property |
| 658 | * len: The length of the resulting bytestream |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 659 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 660 | static int fdt_parse_prop(char * const *newval, int count, char *data, int *len) |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 661 | { |
| 662 | char *cp; /* temporary char pointer */ |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 663 | char *newp; /* temporary newval char pointer */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 664 | unsigned long tmp; /* holds converted values */ |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 665 | int stridx = 0; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 666 | |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 667 | *len = 0; |
| 668 | newp = newval[0]; |
| 669 | |
| 670 | /* An array of cells */ |
| 671 | if (*newp == '<') { |
| 672 | newp++; |
| 673 | while ((*newp != '>') && (stridx < count)) { |
| 674 | /* |
| 675 | * Keep searching until we find that last ">" |
| 676 | * That way users don't have to escape the spaces |
| 677 | */ |
| 678 | if (*newp == '\0') { |
| 679 | newp = newval[++stridx]; |
| 680 | continue; |
| 681 | } |
| 682 | |
| 683 | cp = newp; |
| 684 | tmp = simple_strtoul(cp, &newp, 0); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 685 | *(__be32 *)data = __cpu_to_be32(tmp); |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 686 | data += 4; |
| 687 | *len += 4; |
| 688 | |
| 689 | /* If the ptr didn't advance, something went wrong */ |
| 690 | if ((newp - cp) <= 0) { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 691 | printf("Sorry, I could not convert \"%s\"\n", |
| 692 | cp); |
| 693 | return 1; |
| 694 | } |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 695 | |
| 696 | while (*newp == ' ') |
| 697 | newp++; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 698 | } |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 699 | |
| 700 | if (*newp != '>') { |
| 701 | printf("Unexpected character '%c'\n", *newp); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 702 | return 1; |
| 703 | } |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 704 | } else if (*newp == '[') { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 705 | /* |
| 706 | * Byte stream. Convert the values. |
| 707 | */ |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 708 | newp++; |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 709 | while ((stridx < count) && (*newp != ']')) { |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 710 | while (*newp == ' ') |
| 711 | newp++; |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 712 | if (*newp == '\0') { |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 713 | newp = newval[++stridx]; |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 714 | continue; |
| 715 | } |
| 716 | if (!isxdigit(*newp)) |
| 717 | break; |
| 718 | tmp = simple_strtoul(newp, &newp, 16); |
| 719 | *data++ = tmp & 0xFF; |
| 720 | *len = *len + 1; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 721 | } |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 722 | if (*newp != ']') { |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 723 | printf("Unexpected character '%c'\n", *newp); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 724 | return 1; |
| 725 | } |
| 726 | } else { |
| 727 | /* |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 728 | * Assume it is one or more strings. Copy it into our |
| 729 | * data area for convenience (including the |
| 730 | * terminating '\0's). |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 731 | */ |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 732 | while (stridx < count) { |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 733 | size_t length = strlen(newp) + 1; |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 734 | strcpy(data, newp); |
Ken MacLeod | d028afa | 2009-09-11 15:16:18 -0500 | [diff] [blame] | 735 | data += length; |
| 736 | *len += length; |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 737 | newp = newval[++stridx]; |
| 738 | } |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 739 | } |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | /****************************************************************************/ |
| 744 | |
| 745 | /* |
| 746 | * Heuristic to guess if this is a string or concatenated strings. |
| 747 | */ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 748 | |
| 749 | static int is_printable_string(const void *data, int len) |
| 750 | { |
| 751 | const char *s = data; |
| 752 | |
| 753 | /* zero length is not */ |
| 754 | if (len == 0) |
| 755 | return 0; |
| 756 | |
Joe Hershberger | ea2243b | 2012-08-17 10:34:38 +0000 | [diff] [blame] | 757 | /* must terminate with zero or '\n' */ |
| 758 | if (s[len - 1] != '\0' && s[len - 1] != '\n') |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 759 | return 0; |
| 760 | |
| 761 | /* printable or a null byte (concatenated strings) */ |
Joe Hershberger | ea2243b | 2012-08-17 10:34:38 +0000 | [diff] [blame] | 762 | while (((*s == '\0') || isprint(*s) || isspace(*s)) && (len > 0)) { |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 763 | /* |
| 764 | * If we see a null, there are three possibilities: |
| 765 | * 1) If len == 1, it is the end of the string, printable |
| 766 | * 2) Next character also a null, not printable. |
| 767 | * 3) Next character not a null, continue to check. |
| 768 | */ |
| 769 | if (s[0] == '\0') { |
| 770 | if (len == 1) |
| 771 | return 1; |
| 772 | if (s[1] == '\0') |
| 773 | return 0; |
| 774 | } |
| 775 | s++; |
| 776 | len--; |
| 777 | } |
| 778 | |
| 779 | /* Not the null termination, or not done yet: not printable */ |
| 780 | if (*s != '\0' || (len != 0)) |
| 781 | return 0; |
| 782 | |
| 783 | return 1; |
| 784 | } |
| 785 | |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 786 | |
| 787 | /* |
| 788 | * Print the property in the best format, a heuristic guess. Print as |
| 789 | * a string, concatenated strings, a byte, word, double word, or (if all |
| 790 | * else fails) it is printed as a stream of bytes. |
| 791 | */ |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 792 | static void print_data(const void *data, int len) |
| 793 | { |
| 794 | int j; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 795 | |
| 796 | /* no data, don't print */ |
| 797 | if (len == 0) |
| 798 | return; |
| 799 | |
| 800 | /* |
| 801 | * It is a string, but it may have multiple strings (embedded '\0's). |
| 802 | */ |
| 803 | if (is_printable_string(data, len)) { |
| 804 | puts("\""); |
| 805 | j = 0; |
| 806 | while (j < len) { |
| 807 | if (j > 0) |
| 808 | puts("\", \""); |
| 809 | puts(data); |
| 810 | j += strlen(data) + 1; |
| 811 | data += strlen(data) + 1; |
| 812 | } |
| 813 | puts("\""); |
| 814 | return; |
| 815 | } |
| 816 | |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 817 | if ((len %4) == 0) { |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 818 | if (len > CONFIG_CMD_FDT_MAX_DUMP) |
Tom Rini | 1db8b53 | 2012-10-29 14:53:18 +0000 | [diff] [blame] | 819 | printf("* 0x%p [0x%08x]", data, len); |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 820 | else { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 821 | const __be32 *p; |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 822 | |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 823 | printf("<"); |
| 824 | for (j = 0, p = data; j < len/4; j++) |
| 825 | printf("0x%08x%s", fdt32_to_cpu(p[j]), |
| 826 | j < (len/4 - 1) ? " " : ""); |
| 827 | printf(">"); |
| 828 | } |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 829 | } else { /* anything else... hexdump */ |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 830 | if (len > CONFIG_CMD_FDT_MAX_DUMP) |
Tom Rini | 1db8b53 | 2012-10-29 14:53:18 +0000 | [diff] [blame] | 831 | printf("* 0x%p [0x%08x]", data, len); |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 832 | else { |
| 833 | const u8 *s; |
Andy Fleming | 4689147 | 2008-03-31 20:45:56 -0500 | [diff] [blame] | 834 | |
Joe Hershberger | f72c692 | 2012-08-17 10:34:36 +0000 | [diff] [blame] | 835 | printf("["); |
| 836 | for (j = 0, s = data; j < len; j++) |
| 837 | printf("%02x%s", s[j], j < len - 1 ? " " : ""); |
| 838 | printf("]"); |
| 839 | } |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 840 | } |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /****************************************************************************/ |
| 844 | |
| 845 | /* |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 846 | * Recursively print (a portion of) the working_fdt. The depth parameter |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 847 | * determines how deeply nested the fdt is printed. |
| 848 | */ |
Kumar Gala | 1e386af | 2007-11-21 14:07:46 -0600 | [diff] [blame] | 849 | static int fdt_print(const char *pathp, char *prop, int depth) |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 850 | { |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 851 | static char tabs[MAX_LEVEL+1] = |
| 852 | "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" |
| 853 | "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; |
Kumar Gala | 1e386af | 2007-11-21 14:07:46 -0600 | [diff] [blame] | 854 | const void *nodep; /* property node pointer */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 855 | int nodeoffset; /* node offset from libfdt */ |
| 856 | int nextoffset; /* next node offset from libfdt */ |
| 857 | uint32_t tag; /* tag */ |
| 858 | int len; /* length of the property */ |
| 859 | int level = 0; /* keep track of nesting level */ |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 860 | const struct fdt_property *fdt_prop; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 861 | |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 862 | nodeoffset = fdt_path_offset (working_fdt, pathp); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 863 | if (nodeoffset < 0) { |
| 864 | /* |
| 865 | * Not found or something else bad happened. |
| 866 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 867 | printf ("libfdt fdt_path_offset() returned %s\n", |
Gerald Van Baren | 1178d6a | 2007-05-21 23:27:16 -0400 | [diff] [blame] | 868 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 869 | return 1; |
| 870 | } |
| 871 | /* |
| 872 | * The user passed in a property as well as node path. |
| 873 | * Print only the given property and then return. |
| 874 | */ |
| 875 | if (prop) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 876 | nodep = fdt_getprop (working_fdt, nodeoffset, prop, &len); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 877 | if (len == 0) { |
| 878 | /* no property value */ |
| 879 | printf("%s %s\n", pathp, prop); |
| 880 | return 0; |
| 881 | } else if (len > 0) { |
Gerald Van Baren | fc1a109 | 2007-11-23 19:43:20 -0500 | [diff] [blame] | 882 | printf("%s = ", prop); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 883 | print_data (nodep, len); |
| 884 | printf("\n"); |
| 885 | return 0; |
| 886 | } else { |
| 887 | printf ("libfdt fdt_getprop(): %s\n", |
| 888 | fdt_strerror(len)); |
| 889 | return 1; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | /* |
| 894 | * The user passed in a node path and no property, |
| 895 | * print the node and all subnodes. |
| 896 | */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 897 | while(level >= 0) { |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 898 | tag = fdt_next_tag(working_fdt, nodeoffset, &nextoffset); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 899 | switch(tag) { |
| 900 | case FDT_BEGIN_NODE: |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 901 | pathp = fdt_get_name(working_fdt, nodeoffset, NULL); |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 902 | if (level <= depth) { |
| 903 | if (pathp == NULL) |
| 904 | pathp = "/* NULL pointer error */"; |
| 905 | if (*pathp == '\0') |
| 906 | pathp = "/"; /* root is nameless */ |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 907 | printf("%s%s {\n", |
| 908 | &tabs[MAX_LEVEL - level], pathp); |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 909 | } |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 910 | level++; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 911 | if (level >= MAX_LEVEL) { |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 912 | printf("Nested too deep, aborting.\n"); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 913 | return 1; |
| 914 | } |
| 915 | break; |
| 916 | case FDT_END_NODE: |
| 917 | level--; |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 918 | if (level <= depth) |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 919 | printf("%s};\n", &tabs[MAX_LEVEL - level]); |
| 920 | if (level == 0) { |
| 921 | level = -1; /* exit the loop */ |
| 922 | } |
| 923 | break; |
| 924 | case FDT_PROP: |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 925 | fdt_prop = fdt_offset_ptr(working_fdt, nodeoffset, |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 926 | sizeof(*fdt_prop)); |
Kim Phillips | f3a42e2 | 2008-06-10 11:06:17 -0500 | [diff] [blame] | 927 | pathp = fdt_string(working_fdt, |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 928 | fdt32_to_cpu(fdt_prop->nameoff)); |
| 929 | len = fdt32_to_cpu(fdt_prop->len); |
| 930 | nodep = fdt_prop->data; |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 931 | if (len < 0) { |
| 932 | printf ("libfdt fdt_getprop(): %s\n", |
| 933 | fdt_strerror(len)); |
| 934 | return 1; |
| 935 | } else if (len == 0) { |
| 936 | /* the property has no value */ |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 937 | if (level <= depth) |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 938 | printf("%s%s;\n", |
| 939 | &tabs[MAX_LEVEL - level], |
| 940 | pathp); |
| 941 | } else { |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 942 | if (level <= depth) { |
Gerald Van Baren | fc1a109 | 2007-11-23 19:43:20 -0500 | [diff] [blame] | 943 | printf("%s%s = ", |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 944 | &tabs[MAX_LEVEL - level], |
| 945 | pathp); |
| 946 | print_data (nodep, len); |
| 947 | printf(";\n"); |
| 948 | } |
| 949 | } |
| 950 | break; |
| 951 | case FDT_NOP: |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 952 | printf("%s/* NOP */\n", &tabs[MAX_LEVEL - level]); |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 953 | break; |
| 954 | case FDT_END: |
| 955 | return 1; |
| 956 | default: |
Gerald Van Baren | eb999ee | 2007-11-22 17:23:23 -0500 | [diff] [blame] | 957 | if (level <= depth) |
Gerald Van Baren | e596a16 | 2007-05-16 22:39:59 -0400 | [diff] [blame] | 958 | printf("Unknown tag 0x%08X\n", tag); |
| 959 | return 1; |
| 960 | } |
| 961 | nodeoffset = nextoffset; |
| 962 | } |
| 963 | return 0; |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 964 | } |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 965 | |
| 966 | /********************************************************************/ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 967 | #ifdef CONFIG_SYS_LONGHELP |
| 968 | static char fdt_help_text[] = |
| 969 | "addr <addr> [<length>] - Set the fdt location to <addr>\n" |
Gerald Van Baren | 5606a36 | 2007-06-25 23:25:28 -0400 | [diff] [blame] | 970 | #ifdef CONFIG_OF_BOARD_SETUP |
| 971 | "fdt boardsetup - Do board-specific set up\n" |
| 972 | #endif |
Gerald Van Baren | 7655c09 | 2008-01-05 15:33:29 -0500 | [diff] [blame] | 973 | "fdt move <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n" |
Kumar Gala | 58911df | 2008-08-15 08:24:44 -0500 | [diff] [blame] | 974 | "fdt resize - Resize fdt to size + padding to 4k addr\n" |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 975 | "fdt print <path> [<prop>] - Recursive print starting at <path>\n" |
| 976 | "fdt list <path> [<prop>] - Print one level starting at <path>\n" |
Joe Hershberger | fc5abf0 | 2012-08-17 10:34:37 +0000 | [diff] [blame] | 977 | "fdt get value <var> <path> <prop> - Get <property> and store in <var>\n" |
| 978 | "fdt get name <var> <path> <index> - Get name of node <index> and store in <var>\n" |
| 979 | "fdt get addr <var> <path> <prop> - Get start address of <property> and store in <var>\n" |
| 980 | "fdt get size <var> <path> [<prop>] - Get size of [<property>] or num nodes and store in <var>\n" |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 981 | "fdt set <path> <prop> [<val>] - Set <property> [to <val>]\n" |
| 982 | "fdt mknode <path> <node> - Create a new node after <path>\n" |
| 983 | "fdt rm <path> [<prop>] - Delete the node or <property>\n" |
Kumar Gala | b79da7b | 2008-02-15 03:34:36 -0600 | [diff] [blame] | 984 | "fdt header - Display header info\n" |
| 985 | "fdt bootcpu <id> - Set boot cpuid\n" |
| 986 | "fdt memory <addr> <size> - Add/Update memory node\n" |
| 987 | "fdt rsvmem print - Show current mem reserves\n" |
| 988 | "fdt rsvmem add <addr> <size> - Add a mem reserve\n" |
| 989 | "fdt rsvmem delete <index> - Delete a mem reserves\n" |
Kumar Gala | fb5dcd5 | 2008-08-15 08:24:34 -0500 | [diff] [blame] | 990 | "fdt chosen [<start> <end>] - Add/update the /chosen branch in the tree\n" |
| 991 | " <start>/<end> - initrd start/end addr\n" |
Gerald Van Baren | 0989fcf | 2008-08-22 14:37:05 -0400 | [diff] [blame] | 992 | "NOTE: Dereference aliases by omiting the leading '/', " |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 993 | "e.g. fdt print ethernet0."; |
| 994 | #endif |
| 995 | |
| 996 | U_BOOT_CMD( |
| 997 | fdt, 255, 0, do_fdt, |
| 998 | "flattened device tree utility commands", fdt_help_text |
Gerald Van Baren | ade8ef4 | 2007-03-31 12:22:10 -0400 | [diff] [blame] | 999 | ); |