blob: 50f3c8edf12ef2cde4c89572eece2bcdbfa54454 [file] [log] [blame]
Heiko Schocher3cb743c2014-03-03 12:19:29 +01001/*
2 * (C) Copyright 2014
3 * DENX Software Engineering
4 * Heiko Schocher <hs@denx.de>
5 *
6 * fit_info: print the offset and the len of a property from
7 * node in a fit file.
8 *
9 * Based on:
10 * (C) Copyright 2008 Semihalf
11 *
12 * (C) Copyright 2000-2004
13 * DENX Software Engineering
14 * Wolfgang Denk, wd@denx.de
15 *
16 * Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
17 * FIT image specific code abstracted from mkimage.c
18 * some functions added to address abstraction
19 *
20 * All rights reserved.
21 *
22 * SPDX-License-Identifier: GPL-2.0+
23 */
24
25#include "mkimage.h"
26#include "fit_common.h"
27#include <image.h>
28#include <u-boot/crc.h>
29
30void usage(char *cmdname)
31{
32 fprintf(stderr, "Usage: %s -f fit file -n node -p property\n"
33 " -f ==> set fit file which is used'\n"
34 " -n ==> set node name'\n"
35 " -p ==> set property name'\n",
36 cmdname);
37 exit(EXIT_FAILURE);
38}
39
40int main(int argc, char **argv)
41{
42 int ffd = -1;
43 struct stat fsbuf;
44 void *fit_blob;
45 int len;
46 int nodeoffset; /* node offset from libfdt */
47 const void *nodep; /* property node pointer */
48 char *fdtfile = NULL;
49 char *nodename = NULL;
50 char *propertyname = NULL;
51 char cmdname[50];
52 int c;
53
54 strcpy(cmdname, *argv);
55 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
71 ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
72
73 if (ffd < 0) {
74 printf("Could not open %s\n", fdtfile);
75 exit(EXIT_FAILURE);
76 }
77
78 nodeoffset = fdt_path_offset(fit_blob, nodename);
79 if (nodeoffset < 0) {
80 printf("%s not found.", nodename);
81 exit(EXIT_FAILURE);
82 }
83 nodep = fdt_getprop(fit_blob, nodeoffset, propertyname, &len);
84 if (len == 0) {
85 printf("len == 0 %s\n", propertyname);
86 exit(EXIT_FAILURE);
87 }
88
89 printf("NAME: %s\n", fit_get_name(fit_blob, nodeoffset, NULL));
90 printf("LEN: %d\n", len);
91 printf("OFF: %d\n", (int)(nodep - fit_blob));
92 (void) munmap((void *)fit_blob, fsbuf.st_size);
93
94 close(ffd);
95 exit(EXIT_SUCCESS);
96}