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