b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 <part.h> |
| 17 | #include <fat.h> |
| 18 | #include <fs.h> |
| 19 | |
| 20 | int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 21 | { |
| 22 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | U_BOOT_CMD( |
| 27 | fatload, 7, 0, do_fat_fsload, |
| 28 | "load binary file from a dos filesystem", |
| 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" |
| 35 | " the load stops on end of file.\n" |
| 36 | " If either 'pos' or 'bytes' are not aligned to\n" |
| 37 | " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n" |
| 38 | " be printed and performance will suffer for the load." |
| 39 | ); |
| 40 | |
| 41 | static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 42 | { |
| 43 | return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT); |
| 44 | } |
| 45 | |
| 46 | U_BOOT_CMD( |
| 47 | fatls, 4, 1, do_fat_ls, |
| 48 | "list files in a directory (default /)", |
| 49 | "<interface> [<dev[:part]>] [directory]\n" |
| 50 | " - list files from 'dev' on 'interface' in a 'directory'" |
| 51 | ); |
| 52 | |
| 53 | static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, |
| 54 | char * const argv[]) |
| 55 | { |
| 56 | int dev, part; |
| 57 | block_dev_desc_t *dev_desc; |
| 58 | disk_partition_t info; |
| 59 | |
| 60 | if (argc < 2) { |
| 61 | printf("usage: fatinfo <interface> [<dev[:part]>]\n"); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
| 66 | if (part < 0) |
| 67 | return 1; |
| 68 | |
| 69 | dev = dev_desc->dev; |
| 70 | if (fat_set_blk_dev(dev_desc, &info) != 0) { |
| 71 | printf("\n** Unable to use %s %d:%d for fatinfo **\n", |
| 72 | argv[1], dev, part); |
| 73 | return 1; |
| 74 | } |
| 75 | return file_fat_detectfs(); |
| 76 | } |
| 77 | |
| 78 | U_BOOT_CMD( |
| 79 | fatinfo, 3, 1, do_fat_fsinfo, |
| 80 | "print information about filesystem", |
| 81 | "<interface> [<dev[:part]>]\n" |
| 82 | " - print information about filesystem from 'dev' on 'interface'" |
| 83 | ); |
| 84 | |
| 85 | #ifdef CONFIG_FAT_WRITE |
| 86 | static 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; |
| 93 | disk_partition_t info; |
| 94 | int dev = 0; |
| 95 | int part = 1; |
| 96 | |
| 97 | if (argc < 5) |
| 98 | return cmd_usage(cmdtp); |
| 99 | |
| 100 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
| 101 | if (part < 0) |
| 102 | return 1; |
| 103 | |
| 104 | dev = dev_desc->dev; |
| 105 | |
| 106 | if (fat_set_blk_dev(dev_desc, &info) != 0) { |
| 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 | |
| 126 | U_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 |