Blame view

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