]>
Commit | Line | Data |
---|---|---|
a1596438 US |
1 | /* |
2 | * (C) Copyright 2011 - 2012 Samsung Electronics | |
3 | * EXT4 filesystem implementation in Uboot by | |
4 | * Uma Shankar <[email protected]> | |
5 | * Manjunatha C Achar <[email protected]> | |
6 | * | |
7 | * Ext4fs support | |
8 | * made from existing cmd_ext2.c file of Uboot | |
9 | * | |
10 | * (C) Copyright 2004 | |
11 | * esd gmbh <www.esd-electronics.com> | |
12 | * Reinhard Arlt <[email protected]> | |
13 | * | |
14 | * made from cmd_reiserfs by | |
15 | * | |
16 | * (C) Copyright 2003 - 2004 | |
17 | * Sysgo Real-Time Solutions, AG <www.elinos.com> | |
18 | * Pavel Bartusek <[email protected]> | |
19 | * | |
1a459660 | 20 | * SPDX-License-Identifier: GPL-2.0+ |
a1596438 US |
21 | */ |
22 | ||
23 | /* | |
24 | * Changelog: | |
25 | * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c | |
26 | * file in uboot. Added ext4fs ls load and write support. | |
27 | */ | |
28 | ||
29 | #include <common.h> | |
30 | #include <part.h> | |
31 | #include <config.h> | |
32 | #include <command.h> | |
33 | #include <image.h> | |
34 | #include <linux/ctype.h> | |
35 | #include <asm/byteorder.h> | |
a1596438 US |
36 | #include <ext4fs.h> |
37 | #include <linux/stat.h> | |
38 | #include <malloc.h> | |
045fa1e1 | 39 | #include <fs.h> |
a1596438 US |
40 | |
41 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) | |
42 | #include <usb.h> | |
43 | #endif | |
44 | ||
cf659819 SW |
45 | int do_ext4_size(cmd_tbl_t *cmdtp, int flag, int argc, |
46 | char *const argv[]) | |
47 | { | |
48 | return do_size(cmdtp, flag, argc, argv, FS_TYPE_EXT); | |
49 | } | |
50 | ||
a1596438 US |
51 | int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc, |
52 | char *const argv[]) | |
53 | { | |
b770e88a | 54 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT); |
a1596438 US |
55 | } |
56 | ||
57 | int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
58 | { | |
045fa1e1 | 59 | return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT); |
a1596438 US |
60 | } |
61 | ||
ed34f34d | 62 | #if defined(CONFIG_CMD_EXT4_WRITE) |
ed34f34d US |
63 | int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc, |
64 | char *const argv[]) | |
65 | { | |
66 | const char *filename = "/"; | |
81180819 | 67 | int dev, part; |
ed34f34d US |
68 | unsigned long ram_address; |
69 | unsigned long file_size; | |
70 | disk_partition_t info; | |
81180819 | 71 | block_dev_desc_t *dev_desc; |
ed34f34d US |
72 | |
73 | if (argc < 6) | |
74 | return cmd_usage(cmdtp); | |
75 | ||
10a37fd7 | 76 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
81180819 | 77 | if (part < 0) |
ed34f34d | 78 | return 1; |
ed34f34d | 79 | |
81180819 | 80 | dev = dev_desc->dev; |
ed34f34d US |
81 | |
82 | /* get the filename */ | |
0171d52c | 83 | filename = argv[4]; |
ed34f34d US |
84 | |
85 | /* get the address in hexadecimal format (string to int) */ | |
0171d52c | 86 | ram_address = simple_strtoul(argv[3], NULL, 16); |
ed34f34d | 87 | |
f7740f77 WD |
88 | /* get the filesize in hexadecimal format */ |
89 | file_size = simple_strtoul(argv[5], NULL, 16); | |
ed34f34d US |
90 | |
91 | /* set the device as block device */ | |
81180819 | 92 | ext4fs_set_blk_dev(dev_desc, &info); |
ed34f34d US |
93 | |
94 | /* mount the filesystem */ | |
81180819 | 95 | if (!ext4fs_mount(info.size)) { |
b9dc4941 | 96 | printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part); |
ed34f34d US |
97 | goto fail; |
98 | } | |
99 | ||
100 | /* start write */ | |
101 | if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) { | |
102 | printf("** Error ext4fs_write() **\n"); | |
103 | goto fail; | |
104 | } | |
105 | ext4fs_close(); | |
ed34f34d US |
106 | |
107 | return 0; | |
108 | ||
109 | fail: | |
110 | ext4fs_close(); | |
ed34f34d US |
111 | |
112 | return 1; | |
113 | } | |
114 | ||
115 | U_BOOT_CMD(ext4write, 6, 1, do_ext4_write, | |
116 | "create a file in the root directory", | |
0171d52c | 117 | "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n" |
b6a30444 | 118 | " - create a file in / directory"); |
ed34f34d US |
119 | |
120 | #endif | |
121 | ||
cf659819 SW |
122 | U_BOOT_CMD( |
123 | ext4size, 4, 0, do_ext4_size, | |
124 | "determine a file's size", | |
125 | "<interface> <dev[:part]> <filename>\n" | |
126 | " - Find file 'filename' from 'dev' on 'interface'\n" | |
127 | " and determine its size." | |
128 | ); | |
129 | ||
a1596438 US |
130 | U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls, |
131 | "list files in a directory (default /)", | |
132 | "<interface> <dev[:part]> [directory]\n" | |
b6a30444 | 133 | " - list files from 'dev' on 'interface' in a 'directory'"); |
a1596438 US |
134 | |
135 | U_BOOT_CMD(ext4load, 6, 0, do_ext4_load, | |
136 | "load binary file from a Ext4 filesystem", | |
137 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" | |
b6a30444 | 138 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
b770e88a | 139 | " to address 'addr' from ext4 filesystem"); |