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