]> git.ipfire.org Git - people/ms/u-boot.git/blame - cmd/fat.c
Remove CONFIG_SYS_BOOTCOUNT_SINGLEWORD
[people/ms/u-boot.git] / cmd / fat.c
CommitLineData
71f95118
WD
1/*
2 * (C) Copyright 2002
3 * Richard Jones, rjones@nexus-tech.net
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
71f95118
WD
6 */
7
8/*
9 * Boot support
10 */
11#include <common.h>
12#include <command.h>
71f95118
WD
13#include <s_record.h>
14#include <net.h>
15#include <ata.h>
31e997f9 16#include <asm/io.h>
0eb25b61 17#include <mapmem.h>
735dd97b 18#include <part.h>
71f95118 19#include <fat.h>
045fa1e1 20#include <fs.h>
7205e407 21
cf659819
SW
22int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23{
24 return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
25}
26
27U_BOOT_CMD(
28 fatsize, 4, 0, do_fat_size,
29 "determine a file's size",
30 "<interface> <dev[:part]> <filename>\n"
31 " - Find file 'filename' from 'dev' on 'interface'\n"
32 " and determine its size."
33);
34
54841ab5 35int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 36{
b770e88a 37 return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
71f95118
WD
38}
39
7205e407 40
0d498393 41U_BOOT_CMD(
1170e634 42 fatload, 7, 0, do_fat_fsload,
2fb2604d 43 "load binary file from a dos filesystem",
6b367467 44 "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
1170e634
BT
45 " - Load binary file 'filename' from 'dev' on 'interface'\n"
46 " to address 'addr' from dos filesystem.\n"
47 " 'pos' gives the file position to start loading from.\n"
48 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
49 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
3f83c87e 50 " the load stops on end of file.\n"
01fac041
TR
51 " If either 'pos' or 'bytes' are not aligned to\n"
52 " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
b770e88a 53 " be printed and performance will suffer for the load."
b0fce99b
WD
54);
55
088f1b19 56static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 57{
045fa1e1 58 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
71f95118
WD
59}
60
0d498393 61U_BOOT_CMD(
7205e407 62 fatls, 4, 1, do_fat_ls,
2fb2604d 63 "list files in a directory (default /)",
cfda5aea 64 "<interface> [<dev[:part]>] [directory]\n"
a89c33db 65 " - list files from 'dev' on 'interface' in a 'directory'"
b0fce99b
WD
66);
67
088f1b19
KP
68static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
69 char * const argv[])
71f95118 70{
cfda5aea 71 int dev, part;
4101f687 72 struct blk_desc *dev_desc;
cfda5aea 73 disk_partition_t info;
71f95118 74
7205e407 75 if (argc < 2) {
cfda5aea 76 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
7385c28e 77 return 0;
7205e407 78 }
cfda5aea 79
e35929e4 80 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
cfda5aea 81 if (part < 0)
7205e407 82 return 1;
cfda5aea 83
bcce53d0 84 dev = dev_desc->devnum;
5e8f9831 85 if (fat_set_blk_dev(dev_desc, &info) != 0) {
7385c28e
WD
86 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
87 argv[1], dev, part);
7205e407
WD
88 return 1;
89 }
7385c28e 90 return file_fat_detectfs();
71f95118
WD
91}
92
0d498393 93U_BOOT_CMD(
7205e407 94 fatinfo, 3, 1, do_fat_fsinfo,
2fb2604d 95 "print information about filesystem",
cfda5aea 96 "<interface> [<dev[:part]>]\n"
a89c33db 97 " - print information about filesystem from 'dev' on 'interface'"
b0fce99b 98);
656f4c65
DK
99
100#ifdef CONFIG_FAT_WRITE
101static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
102 int argc, char * const argv[])
103{
1ad0b98a
SR
104 loff_t size;
105 int ret;
656f4c65
DK
106 unsigned long addr;
107 unsigned long count;
4101f687 108 struct blk_desc *dev_desc = NULL;
cfda5aea 109 disk_partition_t info;
656f4c65
DK
110 int dev = 0;
111 int part = 1;
31e997f9 112 void *buf;
656f4c65
DK
113
114 if (argc < 5)
115 return cmd_usage(cmdtp);
116
e35929e4 117 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
cfda5aea 118 if (part < 0)
656f4c65 119 return 1;
cfda5aea 120
bcce53d0 121 dev = dev_desc->devnum;
cfda5aea 122
5e8f9831 123 if (fat_set_blk_dev(dev_desc, &info) != 0) {
656f4c65
DK
124 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
125 argv[1], dev, part);
126 return 1;
127 }
128 addr = simple_strtoul(argv[3], NULL, 16);
454e3d90 129 count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
656f4c65 130
31e997f9 131 buf = map_sysmem(addr, count);
1ad0b98a 132 ret = file_fat_write(argv[4], buf, 0, count, &size);
31e997f9 133 unmap_sysmem(buf);
1ad0b98a 134 if (ret < 0) {
656f4c65
DK
135 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
136 argv[4], argv[1], dev, part);
137 return 1;
138 }
139
1ad0b98a 140 printf("%llu bytes written\n", size);
656f4c65
DK
141
142 return 0;
143}
144
145U_BOOT_CMD(
146 fatwrite, 6, 0, do_fat_fswrite,
147 "write file into a dos filesystem",
454e3d90 148 "<interface> <dev[:part]> <addr> <filename> [<bytes>]\n"
656f4c65
DK
149 " - write file 'filename' from the address 'addr' in RAM\n"
150 " to 'dev' on 'interface'"
151);
152#endif