]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_fat.c
tools: refactor HOSTLOADLIBES_* options
[people/ms/u-boot.git] / common / 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>
735dd97b 16#include <part.h>
71f95118 17#include <fat.h>
045fa1e1 18#include <fs.h>
7205e407 19
54841ab5 20int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 21{
b770e88a 22 return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
71f95118
WD
23}
24
7205e407 25
0d498393 26U_BOOT_CMD(
1170e634 27 fatload, 7, 0, do_fat_fsload,
2fb2604d 28 "load binary file from a dos filesystem",
1170e634
BT
29 "<interface> [<dev[:part]>] <addr> <filename> [bytes [pos]]\n"
30 " - Load binary file 'filename' from 'dev' on 'interface'\n"
31 " to address 'addr' from dos filesystem.\n"
32 " 'pos' gives the file position to start loading from.\n"
33 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
34 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
3f83c87e 35 " the load stops on end of file.\n"
01fac041
TR
36 " If either 'pos' or 'bytes' are not aligned to\n"
37 " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
b770e88a 38 " be printed and performance will suffer for the load."
b0fce99b
WD
39);
40
088f1b19 41static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 42{
045fa1e1 43 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
71f95118
WD
44}
45
0d498393 46U_BOOT_CMD(
7205e407 47 fatls, 4, 1, do_fat_ls,
2fb2604d 48 "list files in a directory (default /)",
cfda5aea 49 "<interface> [<dev[:part]>] [directory]\n"
a89c33db 50 " - list files from 'dev' on 'interface' in a 'directory'"
b0fce99b
WD
51);
52
088f1b19
KP
53static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
54 char * const argv[])
71f95118 55{
cfda5aea
RH
56 int dev, part;
57 block_dev_desc_t *dev_desc;
58 disk_partition_t info;
71f95118 59
7205e407 60 if (argc < 2) {
cfda5aea 61 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
7385c28e 62 return 0;
7205e407 63 }
cfda5aea 64
10a37fd7 65 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
cfda5aea 66 if (part < 0)
7205e407 67 return 1;
cfda5aea
RH
68
69 dev = dev_desc->dev;
5e8f9831 70 if (fat_set_blk_dev(dev_desc, &info) != 0) {
7385c28e
WD
71 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
72 argv[1], dev, part);
7205e407
WD
73 return 1;
74 }
7385c28e 75 return file_fat_detectfs();
71f95118
WD
76}
77
0d498393 78U_BOOT_CMD(
7205e407 79 fatinfo, 3, 1, do_fat_fsinfo,
2fb2604d 80 "print information about filesystem",
cfda5aea 81 "<interface> [<dev[:part]>]\n"
a89c33db 82 " - print information about filesystem from 'dev' on 'interface'"
b0fce99b 83);
656f4c65
DK
84
85#ifdef CONFIG_FAT_WRITE
86static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
87 int argc, char * const argv[])
88{
89 long size;
90 unsigned long addr;
91 unsigned long count;
92 block_dev_desc_t *dev_desc = NULL;
cfda5aea 93 disk_partition_t info;
656f4c65
DK
94 int dev = 0;
95 int part = 1;
656f4c65
DK
96
97 if (argc < 5)
98 return cmd_usage(cmdtp);
99
10a37fd7 100 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
cfda5aea 101 if (part < 0)
656f4c65 102 return 1;
cfda5aea
RH
103
104 dev = dev_desc->dev;
105
5e8f9831 106 if (fat_set_blk_dev(dev_desc, &info) != 0) {
656f4c65
DK
107 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
108 argv[1], dev, part);
109 return 1;
110 }
111 addr = simple_strtoul(argv[3], NULL, 16);
112 count = simple_strtoul(argv[5], NULL, 16);
113
114 size = file_fat_write(argv[4], (void *)addr, count);
115 if (size == -1) {
116 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
117 argv[4], argv[1], dev, part);
118 return 1;
119 }
120
121 printf("%ld bytes written\n", size);
122
123 return 0;
124}
125
126U_BOOT_CMD(
127 fatwrite, 6, 0, do_fat_fswrite,
128 "write file into a dos filesystem",
129 "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
130 " - write file 'filename' from the address 'addr' in RAM\n"
131 " to 'dev' on 'interface'"
132);
133#endif