1 // SPDX-License-Identifier: GPL-2.0+
4 * Roger Knecht <rknecht@pm.de>
9 #include <display_options.h>
14 static int do_xxd(struct cmd_tbl *cmdtp, int flag, int argc,
32 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
33 return CMD_RET_FAILURE;
35 if (!fs_exists(file)) {
36 log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
37 return CMD_RET_FAILURE;
41 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
42 return CMD_RET_FAILURE;
44 if (fs_size(file, &file_size)) {
45 log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
46 return CMD_RET_FAILURE;
49 // allocate memory for file content
50 buffer = calloc(sizeof(char), file_size);
52 log_err("Out of memory\n");
53 return CMD_RET_FAILURE;
56 // map pointer to system memory
57 addr = map_to_sysmem(buffer);
59 // read file to memory
60 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
61 return CMD_RET_FAILURE;
63 if (fs_read(file, addr, 0, 0, &file_size)) {
64 log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
65 return CMD_RET_FAILURE;
69 print_buffer(0, buffer, sizeof(char), file_size, 0);
76 #ifdef CONFIG_SYS_LONGHELP
77 static char xxd_help_text[] =
78 "<interface> <dev[:part]> <file>\n"
79 " - Print file from 'dev' on 'interface' as hexdump to standard output\n";
82 U_BOOT_CMD(xxd, 4, 1, do_xxd,
83 "Print file as hexdump to standard output",