blob: 45e0b310f778791e1c4d53e8b2cf136f5db5bb62 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher3cb743c2014-03-03 12:19:29 +01002/*
3 * (C) Copyright 2014
4 * DENX Software Engineering
5 * Heiko Schocher <hs@denx.de>
6 *
7 * fit_info: print the offset and the len of a property from
8 * node in a fit file.
9 *
10 * Based on:
11 * (C) Copyright 2008 Semihalf
12 *
13 * (C) Copyright 2000-2004
14 * DENX Software Engineering
15 * Wolfgang Denk, wd@denx.de
16 *
17 * Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
18 * FIT image specific code abstracted from mkimage.c
19 * some functions added to address abstraction
20 *
21 * All rights reserved.
Heiko Schocher3cb743c2014-03-03 12:19:29 +010022 */
23
24#include "mkimage.h"
25#include "fit_common.h"
26#include <image.h>
27#include <u-boot/crc.h>
28
29void usage(char *cmdname)
30{
31 fprintf(stderr, "Usage: %s -f fit file -n node -p property\n"
32 " -f ==> set fit file which is used'\n"
33 " -n ==> set node name'\n"
34 " -p ==> set property name'\n",
35 cmdname);
36 exit(EXIT_FAILURE);
37}
38
39int main(int argc, char **argv)
40{
41 int ffd = -1;
42 struct stat fsbuf;
43 void *fit_blob;
44 int len;
45 int nodeoffset; /* node offset from libfdt */
46 const void *nodep; /* property node pointer */
47 char *fdtfile = NULL;
48 char *nodename = NULL;
49 char *propertyname = NULL;
Heiko Schocher6d047532014-08-11 11:17:08 +020050 char cmdname[256];
Heiko Schocher3cb743c2014-03-03 12:19:29 +010051 int c;
52
Heiko Schocher6d047532014-08-11 11:17:08 +020053 strncpy(cmdname, *argv, sizeof(cmdname) - 1);
54 cmdname[sizeof(cmdname) - 1] = '\0';
Heiko Schocher3cb743c2014-03-03 12:19:29 +010055 while ((c = getopt(argc, argv, "f:n:p:")) != -1)
56 switch (c) {
57 case 'f':
58 fdtfile = optarg;
59 break;
60 case 'n':
61 nodename = optarg;
62 break;
63 case 'p':
64 propertyname = optarg;
65 break;
66 default:
67 usage(cmdname);
68 break;
69 }
70
Simon Glassd609a8f2014-06-12 07:24:44 -060071 if (!fdtfile) {
72 fprintf(stderr, "%s: Missing fdt file\n", *argv);
73 usage(*argv);
74 }
75 if (!nodename) {
76 fprintf(stderr, "%s: Missing node name\n", *argv);
77 usage(*argv);
78 }
79 if (!propertyname) {
80 fprintf(stderr, "%s: Missing property name\n", *argv);
81 usage(*argv);
82 }
Simon Glass802aa822014-06-02 22:04:53 -060083 ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
Heiko Schocher3cb743c2014-03-03 12:19:29 +010084
85 if (ffd < 0) {
86 printf("Could not open %s\n", fdtfile);
87 exit(EXIT_FAILURE);
88 }
89
90 nodeoffset = fdt_path_offset(fit_blob, nodename);
91 if (nodeoffset < 0) {
92 printf("%s not found.", nodename);
93 exit(EXIT_FAILURE);
94 }
95 nodep = fdt_getprop(fit_blob, nodeoffset, propertyname, &len);
96 if (len == 0) {
97 printf("len == 0 %s\n", propertyname);
98 exit(EXIT_FAILURE);
99 }
100
101 printf("NAME: %s\n", fit_get_name(fit_blob, nodeoffset, NULL));
102 printf("LEN: %d\n", len);
103 printf("OFF: %d\n", (int)(nodep - fit_blob));
104 (void) munmap((void *)fit_blob, fsbuf.st_size);
105
106 close(ffd);
107 exit(EXIT_SUCCESS);
108}