2012-05-25 23:51:44 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2011 - 2012 Samsung Electronics
|
|
|
|
* EXT4 filesystem implementation in Uboot by
|
|
|
|
* Uma Shankar <uma.shankar@samsung.com>
|
|
|
|
* Manjunatha C Achar <a.manjunatha@samsung.com>
|
|
|
|
*
|
|
|
|
* Ext4fs support
|
|
|
|
* made from existing cmd_ext2.c file of Uboot
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* esd gmbh <www.esd-electronics.com>
|
|
|
|
* Reinhard Arlt <reinhard.arlt@esd-electronics.com>
|
|
|
|
*
|
|
|
|
* made from cmd_reiserfs by
|
|
|
|
*
|
|
|
|
* (C) Copyright 2003 - 2004
|
|
|
|
* Sysgo Real-Time Solutions, AG <www.elinos.com>
|
|
|
|
* Pavel Bartusek <pba@sysgo.com>
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-05-25 23:51:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changelog:
|
|
|
|
* 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
|
|
|
|
* file in uboot. Added ext4fs ls load and write support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <part.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <image.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <ext4fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <malloc.h>
|
2012-10-22 14:43:51 +08:00
|
|
|
#include <fs.h>
|
2012-05-25 23:51:44 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
|
|
|
|
#include <usb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
2012-10-31 19:05:07 +08:00
|
|
|
return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT, 16);
|
2012-05-25 23:51:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
|
|
|
{
|
2012-10-22 14:43:51 +08:00
|
|
|
return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
|
2012-05-25 23:51:44 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 23:52:49 +08:00
|
|
|
#if defined(CONFIG_CMD_EXT4_WRITE)
|
|
|
|
int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
const char *filename = "/";
|
2012-08-23 19:31:46 +08:00
|
|
|
int dev, part;
|
2012-05-25 23:52:49 +08:00
|
|
|
unsigned long ram_address;
|
|
|
|
unsigned long file_size;
|
|
|
|
disk_partition_t info;
|
2012-08-23 19:31:46 +08:00
|
|
|
block_dev_desc_t *dev_desc;
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
if (argc < 6)
|
|
|
|
return cmd_usage(cmdtp);
|
|
|
|
|
disk: get_device_and_partition() "auto" partition and cleanup
Rework get_device_and_partition() to:
a) Implement a new partition ID of "auto", which requests that U-Boot
search for the first "bootable" partition, and fall back to the first
valid partition if none is found. This way, users don't need to
specify an explicit partition in their commands.
b) Make use of get_device().
c) Add parameter to indicate whether returning a whole device is
acceptable, or whether a partition is mandatory.
d) Make error-checking of the user's device-/partition-specification
more complete. In particular, if strtoul() doesn't convert all
characters, it's an error rather than just ignored.
The resultant device/partition returned by the function will be as
follows, based on whether the disk has a partition table (ptable) or not,
and whether the calling command allows the whole device to be returned
or not.
(D and P are integers, P >= 1)
D
D:
No ptable:
!allow_whole_dev: error
allow_whole_dev: device D
ptable:
device D partition 1
D:0
!allow_whole_dev: error
allow_whole_dev: device D
D:P
No ptable: error
ptable: device D partition P
D:auto
No ptable:
!allow_whole_dev: error
allow_whole_dev: device D
ptable:
first partition in device D with bootable flag set.
If none, first valid paratition in device D.
Note: In order to review this patch, it's probably easiest to simply
look at the file contents post-application, rather than reading the
patch itself.
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
[swarren: Rob implemented scanning for bootable partitions. I fixed a
couple of issues there, switched the syntax to ":auto", added the
error-checking rework, and ":0" syntax for the whole device]
Signed-off-by: Stephen Warren <swarren@nvidia.com>
2012-09-21 17:50:57 +08:00
|
|
|
part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
|
2012-08-23 19:31:46 +08:00
|
|
|
if (part < 0)
|
2012-05-25 23:52:49 +08:00
|
|
|
return 1;
|
|
|
|
|
2012-08-23 19:31:46 +08:00
|
|
|
dev = dev_desc->dev;
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
/* get the filename */
|
2013-03-20 12:21:38 +08:00
|
|
|
filename = argv[4];
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
/* get the address in hexadecimal format (string to int) */
|
2013-03-20 12:21:38 +08:00
|
|
|
ram_address = simple_strtoul(argv[3], NULL, 16);
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
/* get the filesize in base 10 format */
|
|
|
|
file_size = simple_strtoul(argv[5], NULL, 10);
|
|
|
|
|
|
|
|
/* set the device as block device */
|
2012-08-23 19:31:46 +08:00
|
|
|
ext4fs_set_blk_dev(dev_desc, &info);
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
/* mount the filesystem */
|
2012-08-23 19:31:46 +08:00
|
|
|
if (!ext4fs_mount(info.size)) {
|
2012-10-23 21:49:25 +08:00
|
|
|
printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part);
|
2012-05-25 23:52:49 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start write */
|
|
|
|
if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
|
|
|
|
printf("** Error ext4fs_write() **\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ext4fs_close();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ext4fs_close();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(ext4write, 6, 1, do_ext4_write,
|
|
|
|
"create a file in the root directory",
|
2013-03-20 12:21:38 +08:00
|
|
|
"<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n"
|
2012-10-30 20:04:18 +08:00
|
|
|
" - create a file in / directory");
|
2012-05-25 23:52:49 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-05-25 23:51:44 +08:00
|
|
|
U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
|
|
|
|
"list files in a directory (default /)",
|
|
|
|
"<interface> <dev[:part]> [directory]\n"
|
2012-10-30 20:04:18 +08:00
|
|
|
" - list files from 'dev' on 'interface' in a 'directory'");
|
2012-05-25 23:51:44 +08:00
|
|
|
|
|
|
|
U_BOOT_CMD(ext4load, 6, 0, do_ext4_load,
|
|
|
|
"load binary file from a Ext4 filesystem",
|
|
|
|
"<interface> <dev[:part]> [addr] [filename] [bytes]\n"
|
2012-10-30 20:04:18 +08:00
|
|
|
" - load binary file 'filename' from 'dev' on 'interface'\n"
|
2012-10-30 20:04:19 +08:00
|
|
|
" to address 'addr' from ext4 filesystem.\n"
|
|
|
|
" All numeric parameters are assumed to be hex.");
|