9
0
Fork 0

factor out iminfo command

The rests of U-Boots iminfo command are sitting in commands/bootm.c and
are in a nonusable state. Factor it out to its own file and make it work
again.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2011-11-25 19:09:07 +01:00
parent 88611e7448
commit ac4854be5e
6 changed files with 79 additions and 83 deletions

View File

@ -309,6 +309,12 @@ config CMD_BOOTM_SHOW_TYPE
depends on CMD_BOOTM
prompt "show image information"
config CMD_IMINFO
bool
prompt "iminfo"
help
Show information about uImages
config CMD_BOOTZ
tristate
default y

View File

@ -1,4 +1,5 @@
obj-$(CONFIG_CMD_BOOTM) += bootm.o
obj-$(CONFIG_CMD_IMINFO) += iminfo.o
obj-$(CONFIG_CMD_LINUX16) += linux16.o
obj-$(CONFIG_CMD_LOADB) += loadb.o xyzModem.o
obj-$(CONFIG_CMD_LOADY) += loadb.o xyzModem.o

View File

@ -321,85 +321,6 @@ BAREBOX_CMD_END
BAREBOX_MAGICVAR(bootargs, "Linux Kernel parameters");
/**
* @page bootm_command
\todo What does bootm do, what kind of image does it boot?
*/
#ifdef CONFIG_CMD_IMI
static int do_iminfo(struct command *cmdtp, int argc, char *argv[])
{
int arg;
ulong addr;
int rcode=0;
if (argc < 2) {
return image_info (load_addr);
}
for (arg=1; arg <argc; ++arg) {
addr = simple_strtoul(argv[arg], NULL, 16);
if (image_info (addr) != 0) rcode = 1;
}
return rcode;
}
static int image_info (ulong addr)
{
ulong data, len, checksum;
image_header_t *hdr = &header;
printf ("\n## Checking Image at %08lx ...\n", addr);
/* Copy header so we can blank CRC field for re-calculation */
memmove (&header, (char *)addr, image_get_header_size());
if (image_get_magic(hdr) != IH_MAGIC) {
puts (" Bad Magic Number\n");
return 1;
}
data = (ulong)&header;
len = image_get_header_size();
checksum = image_get_hcrc(hdr);
hdr->ih_hcrc = 0;
if (crc32 (0, (uchar *)data, len) != checksum) {
puts (" Bad Header Checksum\n");
return 1;
}
/* for multi-file images we need the data part, too */
print_image_hdr ((image_header_t *)addr);
data = addr + image_get_header_size();
len = image_get_size(hdr);
puts (" Verifying Checksum ... ");
if (crc32 (0, (uchar *)data, len) != image_get_dcrc(hdr)) {
puts (" Bad Data CRC\n");
return 1;
}
puts ("OK\n");
return 0;
}
BAREBOX_CMD_HELP_START(iminfo)
BAREBOX_CMD_HELP_USAGE("iminfo\n")
BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(iminfo)
.cmd = do_iminfo,
.usage = "print header information for an application image",
BAREBOX_CMD_HELP(cmd_iminfo_help)
BAREBOX_CMD_END
#endif /* CONFIG_CMD_IMI */
#ifdef CONFIG_BZLIB
void bz_internal_error(int errcode)
{

71
commands/iminfo.c Normal file
View File

@ -0,0 +1,71 @@
#include <common.h>
#include <command.h>
#include <image.h>
#include <fs.h>
#include <malloc.h>
#include <fcntl.h>
#include <errno.h>
static int image_info(image_header_t *hdr)
{
u32 len, checksum;
if (image_get_magic(hdr) != IH_MAGIC) {
puts (" Bad Magic Number\n");
return 1;
}
len = image_get_header_size();
checksum = image_get_hcrc(hdr);
hdr->ih_hcrc = 0;
if (crc32 (0, hdr, len) != checksum) {
puts (" Bad Header Checksum\n");
return 1;
}
image_print_contents(hdr, NULL);
return 0;
}
static int do_iminfo(struct command *cmdtp, int argc, char *argv[])
{
int rcode = 1;
int fd;
int ret;
image_header_t hdr;
if (argc != 2)
return COMMAND_ERROR_USAGE;
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open");
return 1;
}
ret = read(fd, &hdr, sizeof(image_header_t));
if (ret != sizeof(image_header_t))
goto err_out;
printf("Image at %s:\n", argv[1]);
image_info(&hdr);
err_out:
close(fd);
return rcode;
}
BAREBOX_CMD_HELP_START(iminfo)
BAREBOX_CMD_HELP_USAGE("iminfo\n")
BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(iminfo)
.cmd = do_iminfo,
.usage = "print header information for an application image",
BAREBOX_CMD_HELP(cmd_iminfo_help)
BAREBOX_CMD_END

View File

@ -290,7 +290,7 @@ void image_print_contents(const image_header_t *hdr, void *data)
printf ("%sEntry Point: %08x\n", p, image_get_ep(hdr));
type = image_get_type(hdr);
if (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT) {
if (data && (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT)) {
int i;
ulong img_data, len;
ulong count = image_multi_count(data);

View File

@ -335,9 +335,6 @@ void image_print_size(uint32_t size);
void image_print_contents(const image_header_t *hdr, void *data);
/* commamds/bootm.c */
void print_image_hdr (image_header_t *hdr);
/*
* Load an image into memory. Returns a pointer to the loaded
* image.