1 // SPDX-License-Identifier: GPL-2.0+
4 * Roger Knecht <rknecht@pm.de>
13 static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
31 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
32 return CMD_RET_FAILURE;
34 if (!fs_exists(file)) {
35 log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
36 return CMD_RET_FAILURE;
40 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
41 return CMD_RET_FAILURE;
43 if (fs_size(file, &file_size)) {
44 log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
45 return CMD_RET_FAILURE;
48 // allocate memory for file content
49 buffer = calloc(sizeof(char), file_size + 1);
51 log_err("Out of memory\n");
52 return CMD_RET_FAILURE;
55 // map pointer to system memory
56 addr = map_to_sysmem(buffer);
58 // read file to memory
59 if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
60 return CMD_RET_FAILURE;
62 if (fs_read(file, addr, 0, 0, &file_size)) {
63 log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
64 return CMD_RET_FAILURE;
68 buffer[file_size] = '\0';
76 #ifdef CONFIG_SYS_LONGHELP
77 static char cat_help_text[] =
78 "<interface> <dev[:part]> <file>\n"
79 " - Print file from 'dev' on 'interface' to standard output\n";
82 U_BOOT_CMD(cat, 4, 1, do_cat,
83 "Print file to standard output",