Merge branch '2024-11-22-assorted-fixes'
[u-boot.git] / cmd / fat.c
blob5b7484dc1af72b051632fcd326d30e8d5a8fd247
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2002
4 * Richard Jones, rjones@nexus-tech.net
5 */
7 /*
8 * Boot support
9 */
10 #include <command.h>
11 #include <mapmem.h>
12 #include <fat.h>
13 #include <fs.h>
14 #include <part.h>
15 #include <asm/cache.h>
17 static int do_fat_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
19 return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
22 U_BOOT_CMD(
23 fatsize, 4, 0, do_fat_size,
24 "determine a file's size",
25 "<interface> <dev[:part]> <filename>\n"
26 " - Find file 'filename' from 'dev' on 'interface'\n"
27 " and determine its size."
30 int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
32 return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
35 U_BOOT_CMD(
36 fatload, 7, 0, do_fat_fsload,
37 "load binary file from a dos filesystem",
38 "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
39 " - Load binary file 'filename' from 'dev' on 'interface'\n"
40 " to address 'addr' from dos filesystem.\n"
41 " 'pos' gives the file position to start loading from.\n"
42 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
43 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
44 " the load stops on end of file.\n"
45 " If either 'pos' or 'bytes' are not aligned to\n"
46 " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
47 " be printed and performance will suffer for the load."
50 static int do_fat_ls(struct cmd_tbl *cmdtp, int flag, int argc,
51 char *const argv[])
53 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
56 U_BOOT_CMD(
57 fatls, 4, 1, do_fat_ls,
58 "list files in a directory (default /)",
59 "<interface> [<dev[:part]>] [directory]\n"
60 " - list files from 'dev' on 'interface' in a 'directory'"
63 static int do_fat_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
64 char *const argv[])
66 int dev, part;
67 struct blk_desc *dev_desc;
68 struct disk_partition info;
70 if (argc < 2) {
71 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
72 return 0;
75 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
76 if (part < 0)
77 return 1;
79 dev = dev_desc->devnum;
80 if (fat_set_blk_dev(dev_desc, &info) != 0) {
81 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
82 argv[1], dev, part);
83 return 1;
85 return file_fat_detectfs();
88 U_BOOT_CMD(
89 fatinfo, 3, 1, do_fat_fsinfo,
90 "print information about filesystem",
91 "<interface> [<dev[:part]>]\n"
92 " - print information about filesystem from 'dev' on 'interface'"
95 #ifdef CONFIG_FAT_WRITE
96 static int do_fat_fswrite(struct cmd_tbl *cmdtp, int flag, int argc,
97 char *const argv[])
99 return do_save(cmdtp, flag, argc, argv, FS_TYPE_FAT);
102 U_BOOT_CMD(
103 fatwrite, 7, 0, do_fat_fswrite,
104 "write file into a dos filesystem",
105 "<interface> <dev[:part]> <addr> <filename> [<bytes> [<offset>]]\n"
106 " - write file 'filename' from the address 'addr' in RAM\n"
107 " to 'dev' on 'interface'"
110 static int do_fat_rm(struct cmd_tbl *cmdtp, int flag, int argc,
111 char *const argv[])
113 return do_rm(cmdtp, flag, argc, argv, FS_TYPE_FAT);
116 U_BOOT_CMD(
117 fatrm, 4, 1, do_fat_rm,
118 "delete a file",
119 "<interface> [<dev[:part]>] <filename>\n"
120 " - delete a file from 'dev' on 'interface'"
123 static int do_fat_mkdir(struct cmd_tbl *cmdtp, int flag, int argc,
124 char *const argv[])
126 return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT);
129 U_BOOT_CMD(
130 fatmkdir, 4, 1, do_fat_mkdir,
131 "create a directory",
132 "<interface> [<dev[:part]>] <directory>\n"
133 " - create a directory in 'dev' on 'interface'"
135 #endif