Commit 6bf4ca076f8c7a3c1c5abd1cbb059516f7af15df

Authored by Heiko Schocher
Committed by Tom Rini
1 parent bf007ebb6f

tools, fit: add fit_info host command

add fit_info command to the host tools. This command prints
the name, offset and the len from a property from a node in
a fit file. This info can be used to extract a properties
data with linux tools, for example "dd".

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 217 additions and 58 deletions Side-by-side Diff

1 1 /bmp_logo
2 2 /envcrc
  3 +/fit_info
3 4 /gen_eth_addr
4 5 /img2srec
5 6 /kwboot
... ... @@ -60,6 +60,9 @@
60 60 mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o
61 61  
62 62 hostprogs-y += dumpimage$(SFX) mkimage$(SFX)
  63 +ifdef CONFIG_FIT_SIGNATURE
  64 +hostprogs-y += fit_info$(SFX)
  65 +endif
63 66  
64 67 FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o
65 68 # Flattened device tree objects
... ... @@ -71,6 +74,8 @@
71 74 $(FIT_SIG_OBJS-y) \
72 75 crc32.o \
73 76 default_image.o \
  77 + fdtdec.o \
  78 + fit_common.o \
74 79 fit_image.o \
75 80 image-fit.o \
76 81 image-host.o \
... ... @@ -91,6 +96,7 @@
91 96  
92 97 dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o
93 98 mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o
  99 +fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o
94 100  
95 101 # TODO(sjg@chromium.org): Is this correct on Mac OS?
96 102  
... ... @@ -98,6 +104,7 @@
98 104 ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
99 105 HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
100 106 HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
  107 +HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
101 108 # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
102 109 # the mxsimage support within tools/mxsimage.c .
103 110 HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
... ... @@ -106,6 +113,7 @@
106 113 ifdef CONFIG_FIT_SIGNATURE
107 114 HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
108 115 HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
  116 +HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
109 117  
110 118 # This affects include/image.h, but including the board config file
111 119 # is tricky, so manually define this options here.
  1 +/*
  2 + * (C) Copyright 2014
  3 + * DENX Software Engineering
  4 + * Heiko Schocher <hs@denx.de>
  5 + *
  6 + * (C) Copyright 2008 Semihalf
  7 + *
  8 + * (C) Copyright 2000-2004
  9 + * DENX Software Engineering
  10 + * Wolfgang Denk, wd@denx.de
  11 + *
  12 + * Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
  13 + * FIT image specific code abstracted from mkimage.c
  14 + * some functions added to address abstraction
  15 + *
  16 + * All rights reserved.
  17 + *
  18 + * SPDX-License-Identifier: GPL-2.0+
  19 + */
  20 +
  21 +#include "imagetool.h"
  22 +#include "mkimage.h"
  23 +#include "fit_common.h"
  24 +#include <image.h>
  25 +#include <u-boot/crc.h>
  26 +
  27 +int fit_verify_header(unsigned char *ptr, int image_size,
  28 + struct image_tool_params *params)
  29 +{
  30 + return fdt_check_header(ptr);
  31 +}
  32 +
  33 +int fit_check_image_types(uint8_t type)
  34 +{
  35 + if (type == IH_TYPE_FLATDT)
  36 + return EXIT_SUCCESS;
  37 + else
  38 + return EXIT_FAILURE;
  39 +}
  40 +
  41 +int mmap_fdt(char *cmdname, const char *fname, void **blobp,
  42 + struct stat *sbuf, int useunlink)
  43 +{
  44 + void *ptr;
  45 + int fd;
  46 +
  47 + /* Load FIT blob into memory (we need to write hashes/signatures) */
  48 + fd = open(fname, O_RDWR | O_BINARY);
  49 +
  50 + if (fd < 0) {
  51 + fprintf(stderr, "%s: Can't open %s: %s\n",
  52 + cmdname, fname, strerror(errno));
  53 + if (useunlink)
  54 + unlink(fname);
  55 + return -1;
  56 + }
  57 +
  58 + if (fstat(fd, sbuf) < 0) {
  59 + fprintf(stderr, "%s: Can't stat %s: %s\n",
  60 + cmdname, fname, strerror(errno));
  61 + if (useunlink)
  62 + unlink(fname);
  63 + return -1;
  64 + }
  65 +
  66 + errno = 0;
  67 + ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  68 + if ((ptr == MAP_FAILED) || (errno != 0)) {
  69 + fprintf(stderr, "%s: Can't read %s: %s\n",
  70 + cmdname, fname, strerror(errno));
  71 + if (useunlink)
  72 + unlink(fname);
  73 + return -1;
  74 + }
  75 +
  76 + /* check if ptr has a valid blob */
  77 + if (fdt_check_header(ptr)) {
  78 + fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
  79 + if (useunlink)
  80 + unlink(fname);
  81 + return -1;
  82 + }
  83 +
  84 + *blobp = ptr;
  85 + return fd;
  86 +}
  1 +/*
  2 + * (C) Copyright 2014
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#ifndef _FIT_COMMON_H_
  8 +#define _FIT_COMMON_H_
  9 +
  10 +#include "imagetool.h"
  11 +#include "mkimage.h"
  12 +#include <image.h>
  13 +
  14 +int fit_verify_header(unsigned char *ptr, int image_size,
  15 + struct image_tool_params *params);
  16 +
  17 +int fit_check_image_types(uint8_t type);
  18 +
  19 +int mmap_fdt(char *cmdname, const char *fname, void **blobp,
  20 + struct stat *sbuf, int useunlink);
  21 +
  22 +#endif /* _FIT_COMMON_H_ */
... ... @@ -15,68 +15,13 @@
15 15 */
16 16  
17 17 #include "imagetool.h"
  18 +#include "fit_common.h"
18 19 #include "mkimage.h"
19 20 #include <image.h>
20 21 #include <u-boot/crc.h>
21 22  
22 23 static image_header_t header;
23 24  
24   -static int fit_verify_header (unsigned char *ptr, int image_size,
25   - struct image_tool_params *params)
26   -{
27   - return fdt_check_header(ptr);
28   -}
29   -
30   -static int fit_check_image_types (uint8_t type)
31   -{
32   - if (type == IH_TYPE_FLATDT)
33   - return EXIT_SUCCESS;
34   - else
35   - return EXIT_FAILURE;
36   -}
37   -
38   -int mmap_fdt(struct image_tool_params *params, const char *fname, void **blobp,
39   - struct stat *sbuf)
40   -{
41   - void *ptr;
42   - int fd;
43   -
44   - /* Load FIT blob into memory (we need to write hashes/signatures) */
45   - fd = open(fname, O_RDWR | O_BINARY);
46   -
47   - if (fd < 0) {
48   - fprintf(stderr, "%s: Can't open %s: %s\n",
49   - params->cmdname, fname, strerror(errno));
50   - unlink(fname);
51   - return -1;
52   - }
53   -
54   - if (fstat(fd, sbuf) < 0) {
55   - fprintf(stderr, "%s: Can't stat %s: %s\n",
56   - params->cmdname, fname, strerror(errno));
57   - unlink(fname);
58   - return -1;
59   - }
60   -
61   - ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
62   - if (ptr == MAP_FAILED) {
63   - fprintf(stderr, "%s: Can't read %s: %s\n",
64   - params->cmdname, fname, strerror(errno));
65   - unlink(fname);
66   - return -1;
67   - }
68   -
69   - /* check if ptr has a valid blob */
70   - if (fdt_check_header(ptr)) {
71   - fprintf(stderr, "%s: Invalid FIT blob\n", params->cmdname);
72   - unlink(fname);
73   - return -1;
74   - }
75   -
76   - *blobp = ptr;
77   - return fd;
78   -}
79   -
80 25 /**
81 26 * fit_handle_file - main FIT file processing function
82 27 *
83 28  
... ... @@ -129,13 +74,14 @@
129 74 }
130 75  
131 76 if (params->keydest) {
132   - destfd = mmap_fdt(params, params->keydest, &dest_blob, &sbuf);
  77 + destfd = mmap_fdt(params->cmdname, params->keydest,
  78 + &dest_blob, &sbuf, 1);
133 79 if (destfd < 0)
134 80 goto err_keydest;
135 81 destfd_size = sbuf.st_size;
136 82 }
137 83  
138   - tfd = mmap_fdt(params, tmpfile, &ptr, &sbuf);
  84 + tfd = mmap_fdt(params->cmdname, tmpfile, &ptr, &sbuf, 1);
139 85 if (tfd < 0)
140 86 goto err_mmap;
141 87  
  1 +/*
  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 +
  30 +void 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 +
  40 +int 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 +}