Uma Shankar | a159643 | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 20 | * SPDX-License-Identifier: GPL-2.0+ |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 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> |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 36 | #include <ext4fs.h> |
| 37 | #include <linux/stat.h> |
| 38 | #include <malloc.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 39 | #include <fs.h> |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 40 | |
| 41 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) |
| 42 | #include <usb.h> |
| 43 | #endif |
| 44 | |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 45 | int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc, |
| 46 | char *const argv[]) |
| 47 | { |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 48 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT); |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 52 | { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 53 | return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT); |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 54 | } |
| 55 | |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 56 | #if defined(CONFIG_CMD_EXT4_WRITE) |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 57 | int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc, |
| 58 | char *const argv[]) |
| 59 | { |
| 60 | const char *filename = "/"; |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 61 | int dev, part; |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 62 | unsigned long ram_address; |
| 63 | unsigned long file_size; |
| 64 | disk_partition_t info; |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 65 | block_dev_desc_t *dev_desc; |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 66 | |
| 67 | if (argc < 6) |
| 68 | return cmd_usage(cmdtp); |
| 69 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 70 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 71 | if (part < 0) |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 72 | return 1; |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 73 | |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 74 | dev = dev_desc->dev; |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 75 | |
| 76 | /* get the filename */ |
Tom Rini | 0171d52 | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 77 | filename = argv[4]; |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 78 | |
| 79 | /* get the address in hexadecimal format (string to int) */ |
Tom Rini | 0171d52 | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 80 | ram_address = simple_strtoul(argv[3], NULL, 16); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 81 | |
| 82 | /* get the filesize in base 10 format */ |
| 83 | file_size = simple_strtoul(argv[5], NULL, 10); |
| 84 | |
| 85 | /* set the device as block device */ |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 86 | ext4fs_set_blk_dev(dev_desc, &info); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 87 | |
| 88 | /* mount the filesystem */ |
Rob Herring | 8118081 | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 89 | if (!ext4fs_mount(info.size)) { |
Simon Glass | b9dc494 | 2012-10-23 13:49:25 +0000 | [diff] [blame] | 90 | printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 91 | goto fail; |
| 92 | } |
| 93 | |
| 94 | /* start write */ |
| 95 | if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) { |
| 96 | printf("** Error ext4fs_write() **\n"); |
| 97 | goto fail; |
| 98 | } |
| 99 | ext4fs_close(); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | |
| 103 | fail: |
| 104 | ext4fs_close(); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 105 | |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | U_BOOT_CMD(ext4write, 6, 1, do_ext4_write, |
| 110 | "create a file in the root directory", |
Tom Rini | 0171d52 | 2013-03-20 04:21:38 +0000 | [diff] [blame] | 111 | "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n" |
Stephen Warren | b6a3044 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 112 | " - create a file in / directory"); |
Uma Shankar | ed34f34 | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 113 | |
| 114 | #endif |
| 115 | |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 116 | U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls, |
| 117 | "list files in a directory (default /)", |
| 118 | "<interface> <dev[:part]> [directory]\n" |
Stephen Warren | b6a3044 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 119 | " - list files from 'dev' on 'interface' in a 'directory'"); |
Uma Shankar | a159643 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 120 | |
| 121 | U_BOOT_CMD(ext4load, 6, 0, do_ext4_load, |
| 122 | "load binary file from a Ext4 filesystem", |
| 123 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
Stephen Warren | b6a3044 | 2012-10-30 12:04:18 +0000 | [diff] [blame] | 124 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 125 | " to address 'addr' from ext4 filesystem"); |