Skip to content

Commit 2742275

Browse files
prabhakarladtrini
authored andcommitted
cmd: fat: Use do_save() for fatwrite
do_save() function defined in fs.c also supports FAT file system re-use the same for fatwrite command. Also fix the FAT test script to match the expected output. Signed-off-by: Lad Prabhakar <[email protected]> Reviewed-by: Biju Das <[email protected]>
1 parent f52e925 commit 2742275

File tree

2 files changed

+4
-45
lines changed

2 files changed

+4
-45
lines changed

cmd/fat.c

+1-42
Original file line numberDiff line numberDiff line change
@@ -98,48 +98,7 @@ U_BOOT_CMD(
9898
static int do_fat_fswrite(struct cmd_tbl *cmdtp, int flag, int argc,
9999
char *const argv[])
100100
{
101-
loff_t size;
102-
int ret;
103-
unsigned long addr;
104-
unsigned long count;
105-
long offset;
106-
struct blk_desc *dev_desc = NULL;
107-
struct disk_partition 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 = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
116-
if (part < 0)
117-
return 1;
118-
119-
dev = dev_desc->devnum;
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 = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
128-
/* offset should be a hex, but "-1" is allowed */
129-
offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16);
130-
131-
buf = map_sysmem(addr, count);
132-
ret = file_fat_write(argv[4], buf, offset, count, &size);
133-
unmap_sysmem(buf);
134-
if (ret < 0) {
135-
printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
136-
argv[4], argv[1], dev, part);
137-
return 1;
138-
}
139-
140-
printf("%llu bytes written\n", size);
141-
142-
return 0;
101+
return do_save(cmdtp, flag, argc, argv, FS_TYPE_FAT);
143102
}
144103

145104
U_BOOT_CMD(

test/py/tests/test_fs/test_ext.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_fs_ext3(self, u_boot_console, fs_obj_ext):
7474
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
7575
'%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
7676
% (fs_type, ADDR, MIN_FILE)])
77-
assert('Unable to write "/dir1/none/' in ''.join(output))
77+
assert('Unable to write file /dir1/none/' in ''.join(output))
7878
assert_fs_integrity(fs_type, fs_img)
7979

8080
def test_fs_ext4(self, u_boot_console, fs_obj_ext):
@@ -216,7 +216,7 @@ def test_fs_ext8(self, u_boot_console, fs_obj_ext):
216216
output = u_boot_console.run_command(
217217
'%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
218218
% (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
219-
assert('Unable to write "/dir1' in output)
219+
assert('Unable to write file /dir1' in output)
220220
assert_fs_integrity(fs_type, fs_img)
221221

222222
def test_fs_ext9(self, u_boot_console, fs_obj_ext):
@@ -231,7 +231,7 @@ def test_fs_ext9(self, u_boot_console, fs_obj_ext):
231231
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
232232
'%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
233233
% (fs_type, ADDR, MIN_FILE)])
234-
assert('Unable to write "/dir1' in ''.join(output))
234+
assert('Unable to write file /dir1' in ''.join(output))
235235
assert_fs_integrity(fs_type, fs_img)
236236

237237
def test_fs_ext10(self, u_boot_console, fs_obj_ext):

0 commit comments

Comments
 (0)