Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 - 2012 Samsung Electronics |
| 3 | * EXT4 filesystem implementation in Uboot by |
| 4 | * Uma Shankar <uma.shankar@samsung.com> |
| 5 | * Manjunatha C Achar <a.manjunatha@samsung.com> |
| 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 <reinhard.arlt@esd-electronics.com> |
| 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 <pba@sysgo.com> |
| 19 | * |
| 20 | * This program is free software; you can redistribute it and/or |
| 21 | * modify it under the terms of the GNU General Public License as |
| 22 | * published by the Free Software Foundation; either version 2 of |
| 23 | * the License, or (at your option) any later version. |
| 24 | * |
| 25 | * This program is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU General Public License |
| 31 | * along with this program; if not, write to the Free Software |
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 33 | * MA 02111-1307 USA |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Changelog: |
| 39 | * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c |
| 40 | * file in uboot. Added ext4fs ls load and write support. |
| 41 | */ |
| 42 | |
| 43 | #include <common.h> |
| 44 | #include <part.h> |
| 45 | #include <config.h> |
| 46 | #include <command.h> |
| 47 | #include <image.h> |
| 48 | #include <linux/ctype.h> |
| 49 | #include <asm/byteorder.h> |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 50 | #include <ext4fs.h> |
| 51 | #include <linux/stat.h> |
| 52 | #include <malloc.h> |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 53 | #include <fs.h> |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 54 | |
| 55 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) |
| 56 | #include <usb.h> |
| 57 | #endif |
| 58 | |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 59 | int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc, |
| 60 | char *const argv[]) |
| 61 | { |
Stephen Warren | 128d3d9 | 2012-10-31 11:05:07 +0000 | [diff] [blame] | 62 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT, 16); |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 66 | { |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 67 | return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT); |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 68 | } |
| 69 | |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 70 | #if defined(CONFIG_CMD_EXT4_WRITE) |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 71 | int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc, |
| 72 | char *const argv[]) |
| 73 | { |
| 74 | const char *filename = "/"; |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 75 | int dev, part; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 76 | unsigned long ram_address; |
| 77 | unsigned long file_size; |
| 78 | disk_partition_t info; |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 79 | block_dev_desc_t *dev_desc; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 80 | |
| 81 | if (argc < 6) |
| 82 | return cmd_usage(cmdtp); |
| 83 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 84 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 85 | if (part < 0) |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 86 | return 1; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 87 | |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 88 | dev = dev_desc->dev; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 89 | |
| 90 | /* get the filename */ |
Tom Rini | 446543f | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 91 | filename = argv[4]; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 92 | |
| 93 | /* get the address in hexadecimal format (string to int) */ |
Tom Rini | 446543f | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 94 | ram_address = simple_strtoul(argv[3], NULL, 16); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 95 | |
| 96 | /* get the filesize in base 10 format */ |
| 97 | file_size = simple_strtoul(argv[5], NULL, 10); |
| 98 | |
| 99 | /* set the device as block device */ |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 100 | ext4fs_set_blk_dev(dev_desc, &info); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 101 | |
| 102 | /* mount the filesystem */ |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 103 | if (!ext4fs_mount(info.size)) { |
Simon Glass | ee853e7 | 2012-10-23 13:49:25 +0000 | [diff] [blame] | 104 | printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 105 | goto fail; |
| 106 | } |
| 107 | |
| 108 | /* start write */ |
| 109 | if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) { |
| 110 | printf("** Error ext4fs_write() **\n"); |
| 111 | goto fail; |
| 112 | } |
| 113 | ext4fs_close(); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | |
| 117 | fail: |
| 118 | ext4fs_close(); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 119 | |
| 120 | return 1; |
| 121 | } |
| 122 | |
| 123 | U_BOOT_CMD(ext4write, 6, 1, do_ext4_write, |
| 124 | "create a file in the root directory", |
Tom Rini | 446543f | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 125 | "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n" |
Stephen Warren | efd4a31 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 126 | " - create a file in / directory"); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 127 | |
| 128 | #endif |
| 129 | |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 130 | U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls, |
| 131 | "list files in a directory (default /)", |
| 132 | "<interface> <dev[:part]> [directory]\n" |
Stephen Warren | efd4a31 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 133 | " - list files from 'dev' on 'interface' in a 'directory'"); |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 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" |
Stephen Warren | efd4a31 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 138 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Stephen Warren | 40816a0 | 2012-10-30 12:04:19 +0000 | [diff] [blame] | 139 | " to address 'addr' from ext4 filesystem.\n" |
| 140 | " All numeric parameters are assumed to be hex."); |