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