Commit 857f62fe authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fdt & fit

parent de50fa99
/*
* (C) Copyright 2008 Semihalf
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __FDT_HOST_H__
#define __FDT_HOST_H__
/* Make sure to include u-boot version of libfdt include files */
#include "../include/libfdt.h"
#include "../include/fdt_support.h"
/**
* fdt_remove_unused_strings() - Remove any unused strings from an FDT
*
* This creates a new device tree in @new with unused strings removed. The
* called can then use fdt_pack() to minimise the space consumed.
*
* @old: Old device tree blog
* @new: Place to put new device tree blob, which must be as large as
* @old
* @return
* 0, on success
* -FDT_ERR_BADOFFSET, corrupt device tree
* -FDT_ERR_NOSPACE, out of space, which should not happen unless there
* is something very wrong with the device tree input
*/
int fdt_remove_unused_strings(const void *old, void *new);
int fit_check_sign(const void *working_fdt, const void *key);
#endif /* __FDT_HOST_H__ */
This diff is collapsed.
/*
* (C) Copyright 2014
* DENX Software Engineering
* Heiko Schocher <hs@denx.de>
*
* 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.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#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 -k key file\n"
" -f ==> set fit file which should be checked'\n"
" -k ==> set key file which contains the key'\n",
cmdname);
exit(EXIT_FAILURE);
}
int main(int argc, char **argv)
{
int ffd = -1;
int kfd = -1;
struct stat fsbuf;
struct stat ksbuf;
void *fit_blob;
char *fdtfile = NULL;
char *keyfile = NULL;
char cmdname[256];
int ret;
void *key_blob;
int c;
strncpy(cmdname, *argv, sizeof(cmdname) - 1);
cmdname[sizeof(cmdname) - 1] = '\0';
while ((c = getopt(argc, argv, "f:k:")) != -1)
switch (c) {
case 'f':
fdtfile = optarg;
break;
case 'k':
keyfile = optarg;
break;
default:
usage(cmdname);
break;
}
if (!fdtfile) {
fprintf(stderr, "%s: Missing fdt file\n", *argv);
usage(*argv);
}
if (!keyfile) {
fprintf(stderr, "%s: Missing key file\n", *argv);
usage(*argv);
}
ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0)
return EXIT_FAILURE;
kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false);
if (kfd < 0)
return EXIT_FAILURE;
image_set_host_blob(key_blob);
ret = fit_check_sign(fit_blob, key_blob);
if (!ret) {
ret = EXIT_SUCCESS;
fprintf(stderr, "Signature check OK\n");
} else {
ret = EXIT_FAILURE;
fprintf(stderr, "Signature check Bad (error %d)\n", ret);
}
(void) munmap((void *)fit_blob, fsbuf.st_size);
(void) munmap((void *)key_blob, ksbuf.st_size);
close(ffd);
close(kfd);
exit(ret);
}
/*
* (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.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#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\n"
" -f ==> set fit file which is used'\n"
" -n ==> set node name'\n"
" -p ==> set property name'\n",
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;
char cmdname[256];
int c;
strncpy(cmdname, *argv, sizeof(cmdname) - 1);
cmdname[sizeof(cmdname) - 1] = '\0';
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;
}
if (!fdtfile) {
fprintf(stderr, "%s: Missing fdt file\n", *argv);
usage(*argv);
}
if (!nodename) {
fprintf(stderr, "%s: Missing node name\n", *argv);
usage(*argv);
}
if (!propertyname) {
fprintf(stderr, "%s: Missing property name\n", *argv);
usage(*argv);
}
ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0) {
printf("Could not open %s\n", 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\n", propertyname);
exit(EXIT_FAILURE);
}
printf("NAME: %s\n", fit_get_name(fit_blob, nodeoffset, NULL));
printf("LEN: %d\n", len);
printf("OFF: %d\n", (int)(nodep - fit_blob));
(void) munmap((void *)fit_blob, fsbuf.st_size);
close(ffd);
exit(EXIT_SUCCESS);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment