[U-Boot] [PATCH V4 1/2] ext4fs ls load support

Rob Herring robherring2 at gmail.com
Mon Mar 26 15:10:48 CEST 2012


On 03/26/2012 02:24 AM, UMA SHANKAR wrote:
> Dear Rob Herring, Thanks for evaluating and testing our code. 
> Currently, Our ext4 implementation is capable of listing and reading
> (ls and load) ext2 partitions as well. But, we wanted the ext4 code
> to be separate from ext2 implementation.

Why?

> Your comment: --- Using ext2 commands on an ext4 partition will hang
> now.
> 
> ext2load command will only read ext2 partitions, and will definitely
> not work on ext4 (even without our implementation).

I'm not saying it should work, but it shouldn't hang. IIRC without your
patch, it would return with an error. So you have changed something in
the core ext2 code that makes it hang. But it's not something I think
you need to worry about as the ext4 version of code should just replace
the ext2 version and the issue will go away.

Rob

>   So, I propose, we can let both these implementations be there in
> uboot under different CONFIG Options (as is the case currently).   
> Thanks & Regards, Uma Shankar
> 
> ------- Original Message ------- Sender : Rob
> Herring<robherring2 at gmail.com> Date : Mar 22, 2012 21:19 (GMT+05:30) 
> Title : Re: [U-Boot] [PATCH V4 1/2] ext4fs ls load support
> 
> On 01/09/2012 11:54 AM, uma.shankar at samsung.com wrote:
>> From: uma.shankar
>> 
>> Signed-off-by: Uma Shankar Signed-off-by: Manjunatha C Achar 
>> Signed-off-by: Iqbal Shareef Signed-off-by: Hakgoo Lee --- Changes
>> for v3: - Copyright has been updated in respective files - ext4fs
>> has been made independant of ext2fs.c - Fixed API namespace -
>> Removed endianness conversion API, used uboot defined API for the
>> same - Fixed coding style issues - Moved README.ext4 file into doc
>> folder
>> 
>> Changes for v2: - Code cleanup, changed comment style - camel case
>> removed, resolved code alignment issues - memory allocation logic
>> changed, removed busybox logic - Modified ext4 load to remove grub
>> dependency (GPLv3) - Introduced new Config for ext4 write
>> 
>> Changes for v1: - Removed checkpatch warnings and errors - Moved
>> common API's of ext2 and ext4 to one generic header file
>> 
>> Makefile              |    2 +- common/Makefile       |    1 + 
>> common/cmd_ext4.c     |  266 +++++++++++++++
> 
> I don't think we need yet another version of filesystem commands
> that just duplicates the same code.
> 
> I tested this patch and can read ext2 partitions with the
> ext4ls/load commands. Using ext2 commands on an ext4 partition will
> hang now. You should merge your ext4 command changes into the
> existing ext2 commands so that commands work on either ext2/3 or ext4
> partitions.
> 
> Really, I would like to see all the block based device and file
> commands collapsed down into just fsls and fsload commands and then
> detect (or specify if necessary) the fs type. But that's a bigger
> problem.
> 
> Rob
> 
>> fs/Makefile           |    1 + fs/ext2/dev.c         |    1 + 
>> fs/ext2/ext2fs.c      |  181 ++--------- fs/ext4/Makefile      |
>> 51 +++ fs/ext4/dev.c         |  145 ++++++++ fs/ext4/ext4_common.c
>> |  875 +++++++++++++++++++++++++++++++++++++++++++++++++ 
>> fs/ext4/ext4_common.h |   63 ++++ fs/ext4/ext4fs.c      |  228
>> +++++++++++++ include/ext4fs.h      |  132 ++++++++ 
>> include/ext_common.h  |  188 +++++++++++ 13 files changed, 1977
>> insertions(+), 157 deletions(-) create mode 100644
>> common/cmd_ext4.c create mode 100644 fs/ext4/Makefile create mode
>> 100644 fs/ext4/dev.c create mode 100644 fs/ext4/ext4_common.c 
>> create mode 100644 fs/ext4/ext4_common.h create mode 100644
>> fs/ext4/ext4fs.c create mode 100644 include/ext4fs.h create mode
>> 100644 include/ext_common.h
>> 
>> diff --git a/Makefile b/Makefile index 7e9491d..e77f6be 100644 ---
>> a/Makefile +++ b/Makefile @@ -235,7 +235,7 @@ LIBS += dts/libdts.o 
>> endif LIBS += arch/$(ARCH)/lib/lib$(ARCH).o LIBS +=
>> fs/cramfs/libcramfs.o fs/fat/libfat.o fs/fdos/libfdos.o
>> fs/jffs2/libjffs2.o \ - fs/reiserfs/libreiserfs.o
>> fs/ext2/libext2fs.o fs/yaffs2/libyaffs2.o \ +
>> fs/reiserfs/libreiserfs.o fs/ext2/libext2fs.o fs/ext4/libext4fs.o
>> fs/yaffs2/libyaffs2.o \ fs/ubifs/libubifs.o LIBS += net/libnet.o 
>> LIBS += disk/libdisk.o diff --git a/common/Makefile
>> b/common/Makefile index 2d9ae8c..f5243f6 100644 ---
>> a/common/Makefile +++ b/common/Makefile @@ -86,6 +86,7 @@
>> COBJS-$(CONFIG_ENV_IS_IN_EEPROM) += cmd_eeprom.o 
>> COBJS-$(CONFIG_CMD_EEPROM) += cmd_eeprom.o COBJS-$(CONFIG_CMD_ELF)
>> += cmd_elf.o COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_exit.o 
>> +COBJS-$(CONFIG_CMD_EXT4) += cmd_ext4.o COBJS-$(CONFIG_CMD_EXT2) +=
>> cmd_ext2.o COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o 
>> COBJS-$(CONFIG_CMD_FDC)$(CONFIG_CMD_FDOS) += cmd_fdc.o diff --git
>> a/common/cmd_ext4.c b/common/cmd_ext4.c new file mode 100644 index
>> 0000000..2c53d2c --- /dev/null +++ b/common/cmd_ext4.c @@ -0,0
>> +1,266 @@ +/* + * (C) Copyright 2011 - 2012 Samsung Electronics + *
>> EXT4 filesystem implementation in Uboot by + * Uma Shankar + *
>> Manjunatha C Achar + * + * Ext4fs support + * made from existing
>> cmd_ext2.c file of Uboot + * + * (C) Copyright 2004 + * esd gmbh +
>> * Reinhard Arlt + * + * made from cmd_reiserfs by + * + * (C)
>> Copyright 2003 - 2004 + * Sysgo Real-Time Solutions, AG + * Pavel
>> Bartusek + * + * This program is free software; you can
>> redistribute it and/or + * modify it under the terms of the GNU
>> General Public License as + * published by the Free Software
>> Foundation; either version 2 of + * the License, or (at your
>> option) any later version. + * + * This program is distributed in
>> the hope that it will be useful, + * but WITHOUT ANY WARRANTY;
>> without even the implied warranty of + * MERCHANTABILITY or FITNESS
>> FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License
>> for more details. + * + * You should have received a copy of the
>> GNU General Public License + * along with this program; if not,
>> write to the Free Software + * Foundation, Inc., 59 Temple Place,
>> Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +/* + *
>> Changelog: + * 0.1 - Newly created file for ext4fs support. Taken
>> from cmd_ext2.c + *         file in uboot. Added ext4fs ls and load
>> support. + */ + +#include +#include +#include +#include +#include 
>> +#include +#include +#include +#include +#include +#include + +#if
>> defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) +#include 
>> +#endif + +#if !defined(CONFIG_DOS_PARTITION) &&
>> !defined(CONFIG_EFI_PARTITION) +#error DOS or EFI partition support
>> must be selected +#endif + +uint64_t total_sector; +uint64_t
>> part_offset; + +#define DOS_PART_MAGIC_OFFSET 0x1fe +#define
>> DOS_FS_TYPE_OFFSET 0x36 +#define DOS_FS32_TYPE_OFFSET 0x52 + 
>> +static int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc, +
>> char *const argv[]) +{ + char *filename = NULL; + char *ep; + int
>> dev; + unsigned long part = 1; + ulong addr = 0; + ulong
>> part_length; + int filelen; + disk_partition_t info; + struct
>> ext_filesystem *fs; + char buf[12]; + unsigned long count; + const
>> char *addr_str; + + count = 0; + addr = simple_strtoul(argv[3],
>> NULL, 16); + filename = getenv("bootfile"); + switch (argc) { +
>> case 3: + addr_str = getenv("loadaddr"); + if (addr_str != NULL) +
>> addr = simple_strtoul(addr_str, NULL, 16); + else + addr =
>> CONFIG_SYS_LOAD_ADDR; + + break; + case 4: + break; + case 5: +
>> filename = argv[4]; + break; + case 6: + filename = argv[4]; +
>> count = simple_strtoul(argv[5], NULL, 16); + break; + + default: +
>> return cmd_usage(cmdtp); + } + + if (!filename) { + puts("** No
>> boot file defined **\n"); + return 1; + } + + dev =
>> (int)simple_strtoul(argv[2], &ep, 16); + ext4_dev_desc =
>> get_dev(argv[1], dev); + if (ext4_dev_desc == NULL) { + printf("**
>> Block device %s %d not supported\n", argv[1], dev); + return 1; +
>> } + if (init_fs(ext4_dev_desc)) + return 1; + + fs = get_fs(); + if
>> (*ep) { + if (*ep != ':') { + puts("** Invalid boot device, use
>> `dev[:part]' **\n"); + return 1; + } + part = simple_strtoul(++ep,
>> NULL, 16); + } + + if (part != 0) { + if
>> (get_partition_info(fs->dev_desc, part, &info)) { + printf("** Bad
>> partition %lu **\n", part); + return 1; + } + + if (strncmp((char
>> *)info.type, BOOT_PART_TYPE, +     strlen(BOOT_PART_TYPE)) != 0) { 
>> + printf("** Invalid partition type \"%s\"" +        " (expect \""
>> BOOT_PART_TYPE "\")\n", info.type); + return 1; + } +
>> printf("Loading file \"%s\" " +        "from %s device %d:%lu
>> %s\n", +        filename, argv[1], dev, part, info.name); + } else
>> { + printf("Loading file \"%s\" from %s device %d\n", +
>> filename, argv[1], dev); + } + + part_length =
>> ext4fs_set_blk_dev(fs->dev_desc, part); + if (part_length == 0) { +
>> printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part); +
>> ext4fs_close(); + return 1; + } + + if (!ext4fs_mount(part_length))
>> { + printf("** Bad ext2 partition or disk - %s %d:%lu **\n", +
>> argv[1], dev, part); + ext4fs_close(); + return 1; + } + + filelen
>> = ext4fs_open(filename); + if (filelen < 0) { + printf("** File not
>> found %s\n", filename); + ext4fs_close(); + return 1; + } + if
>> ((count < filelen) && (count != 0)) + filelen = count; + + if
>> (ext4fs_read((char *)addr, filelen) != filelen) { + printf("**
>> Unable to read \"%s\" from %s %d:%lu **\n", +        filename,
>> argv[1], dev, part); + ext4fs_close(); + return 1; + } + +
>> ext4fs_close(); + deinit_fs(fs->dev_desc); + /* Loading ok, update
>> default load address */ + load_addr = addr; + + printf("%d bytes
>> read\n", filelen); + sprintf(buf, "%X", filelen); +
>> setenv("filesize", buf); + + return 0; +} + +static int
>> do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const
>> argv[]) +{ + const char *filename = "/"; + int dev; + unsigned long
>> part = 1; + char *ep; + struct ext_filesystem *fs; + int
>> part_length; + + if (argc < 3) + return cmd_usage(cmdtp); + + dev =
>> (int)simple_strtoul(argv[2], &ep, 16); + ext4_dev_desc =
>> get_dev(argv[1], dev); + + if (ext4_dev_desc == NULL) { +
>> printf("\n** Block device %s %d not supported\n", argv[1], dev); +
>> return 1; + } + + if (init_fs(ext4_dev_desc)) + return 1; + + fs =
>> get_fs(); + if (*ep) { + if (*ep != ':') { + puts("\n** Invalid
>> boot device, use `dev[:part]' **\n"); + return 1; + } + part =
>> simple_strtoul(++ep, NULL, 16); + } + + if (argc == 4) + filename =
>> argv[3]; + + part_length = ext4fs_set_blk_dev(fs->dev_desc, part); 
>> + if (part_length == 0) { + printf("** Bad partition - %s %d:%lu
>> **\n", argv[1], dev, part); + ext4fs_close(); + return 1; + } + +
>> if (!ext4fs_mount(part_length)) { + printf("** Bad ext2 partition
>> or disk - %s %d:%lu **\n", +        argv[1], dev, part); +
>> ext4fs_close(); + return 1; + } + if (ext4fs_ls(filename)) { +
>> printf("** Error ext2fs_ls() **\n"); + ext4fs_close(); + return 1; 
>> + }; + + ext4fs_close(); + deinit_fs(fs->dev_desc); + + return 0; 
>> +} + +U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls, +    "list files in a
>> directory (default /)", +    " [directory]\n" +    "   - list files
>> from 'dev' on 'interface' in a 'directory'"); + 
>> +U_BOOT_CMD(ext4load, 6, 0, do_ext4_load, +    "load binary file
>> from a Ext2 filesystem", +    " [addr] [filename] [bytes]\n" +    "
>> - load binary file 'filename' from 'dev' on 'interface'\n" +    "
>> to address 'addr' from ext2 filesystem"); diff --git a/fs/Makefile
>> b/fs/Makefile index 22aad12..00a8f37 100644 --- a/fs/Makefile +++
>> b/fs/Makefile @@ -23,6 +23,7 @@ #
>> 
>> subdirs-$(CONFIG_CMD_CRAMFS) := cramfs +subdirs-$(CONFIG_CMD_EXT4)
>> += ext4 subdirs-$(CONFIG_CMD_EXT2) += ext2 
>> subdirs-$(CONFIG_CMD_FAT) += fat subdirs-$(CONFIG_CMD_FDOS) +=
>> fdos diff --git a/fs/ext2/dev.c b/fs/ext2/dev.c index
>> 874e211..315ff53 100644 --- a/fs/ext2/dev.c +++ b/fs/ext2/dev.c @@
>> -27,6 +27,7 @@ #include #include #include +#include
>> 
>> static block_dev_desc_t *ext2fs_block_dev_desc; static
>> disk_partition_t part_info; diff --git a/fs/ext2/ext2fs.c
>> b/fs/ext2/ext2fs.c index f621741..a4f3094 100644 ---
>> a/fs/ext2/ext2fs.c +++ b/fs/ext2/ext2fs.c @@ -25,152 +25,16 @@
>> 
>> #include #include +#include #include #include
>> 
>> extern int ext2fs_devread (int sector, int byte_offset, int
>> byte_len, char *buf);
>> 
>> -/* Magic value used to identify an ext2 filesystem.  */ -#define
>> EXT2_MAGIC 0xEF53 -/* Amount of indirect blocks in an inode.  */ 
>> -#define INDIRECT_BLOCKS 12 -/* Maximum lenght of a pathname.  */ 
>> -#define EXT2_PATH_MAX 4096 -/* Maximum nesting of symlinks, used
>> to prevent a loop.  */ -#define EXT2_MAX_SYMLINKCNT 8 - -/*
>> Filetype used in directory entry.  */ -#define FILETYPE_UNKNOWN 0 
>> -#define FILETYPE_REG 1 -#define FILETYPE_DIRECTORY 2 -#define
>> FILETYPE_SYMLINK 7 - -/* Filetype information as used in inodes.
>> */ -#define FILETYPE_INO_MASK 0170000 -#define FILETYPE_INO_REG
>> 0100000 -#define FILETYPE_INO_DIRECTORY 0040000 -#define
>> FILETYPE_INO_SYMLINK 0120000 - -/* Bits used as offset in sector
>> */ -#define DISK_SECTOR_BITS        9 - -/* Log2 size of ext2 block
>> in 512 blocks.  */ -#define LOG2_EXT2_BLOCK_SIZE(data)
>> (__le32_to_cpu (data->sblock.log2_block_size) + 1) - -/* Log2 size
>> of ext2 block in bytes.  */ -#define LOG2_BLOCK_SIZE(data)
>> (__le32_to_cpu (data->sblock.log2_block_size) + 10) - -/* The size
>> of an ext2 block in bytes.  */ -#define EXT2_BLOCK_SIZE(data)    (1
>> << LOG2_BLOCK_SIZE(data)) - -/* The ext2 superblock.  */ -struct
>> ext2_sblock { - uint32_t total_inodes; - uint32_t total_blocks; -
>> uint32_t reserved_blocks; - uint32_t free_blocks; - uint32_t
>> free_inodes; - uint32_t first_data_block; - uint32_t
>> log2_block_size; - uint32_t log2_fragment_size; - uint32_t
>> blocks_per_group; - uint32_t fragments_per_group; - uint32_t
>> inodes_per_group; - uint32_t mtime; - uint32_t utime; - uint16_t
>> mnt_count; - uint16_t max_mnt_count; - uint16_t magic; - uint16_t
>> fs_state; - uint16_t error_handling; - uint16_t
>> minor_revision_level; - uint32_t lastcheck; - uint32_t
>> checkinterval; - uint32_t creator_os; - uint32_t revision_level; -
>> uint16_t uid_reserved; - uint16_t gid_reserved; - uint32_t
>> first_inode; - uint16_t inode_size; - uint16_t block_group_number; 
>> - uint32_t feature_compatibility; - uint32_t feature_incompat; -
>> uint32_t feature_ro_compat; - uint32_t unique_id[4]; - char
>> volume_name[16]; - char last_mounted_on[64]; - uint32_t
>> compression_info; -}; - -/* The ext2 blockgroup.  */ -struct
>> ext2_block_group { - uint32_t block_id; - uint32_t inode_id; -
>> uint32_t inode_table_id; - uint16_t free_blocks; - uint16_t
>> free_inodes; - uint16_t used_dir_cnt; - uint32_t reserved[3]; -}; 
>> - -/* The ext2 inode.  */ -struct ext2_inode { - uint16_t mode; -
>> uint16_t uid; - uint32_t size; - uint32_t atime; - uint32_t ctime; 
>> - uint32_t mtime; - uint32_t dtime; - uint16_t gid; - uint16_t
>> nlinks; - uint32_t blockcnt; /* Blocks of 512 bytes!! */ - uint32_t
>> flags; - uint32_t osd1; - union { - struct datablocks { - uint32_t
>> dir_blocks[INDIRECT_BLOCKS]; - uint32_t indir_block; - uint32_t
>> double_indir_block; - uint32_t tripple_indir_block; - } blocks; -
>> char symlink[60]; - } b; - uint32_t version; - uint32_t acl; -
>> uint32_t dir_acl; - uint32_t fragment_addr; - uint32_t osd2[3]; 
>> -}; - -/* The header of an ext2 directory entry.  */ -struct
>> ext2_dirent { - uint32_t inode; - uint16_t direntlen; - uint8_t
>> namelen; - uint8_t filetype; -}; - -struct ext2fs_node { - struct
>> ext2_data *data; - struct ext2_inode inode; - int ino; - int
>> inode_read; -}; - -/* Information about a "mounted" ext2
>> filesystem.  */ -struct ext2_data { - struct ext2_sblock sblock; -
>> struct ext2_inode *inode; - struct ext2fs_node diropen; -}; - - 
>> -typedef struct ext2fs_node *ext2fs_node_t;
>> 
>> struct ext2_data *ext2fs_root = NULL; -ext2fs_node_t ext2fs_file =
>> NULL; +struct ext2fs_node *ext2fs_file; int symlinknest = 0; 
>> uint32_t *indir1_block = NULL; int indir1_size = 0; @@ -243,14
>> +107,16 @@ static int ext2fs_read_inode }
>> 
>> 
>> -void ext2fs_free_node (ext2fs_node_t node, ext2fs_node_t currroot)
>> { +void ext2fs_free_node(struct ext2fs_node *node, struct
>> ext2fs_node *currroot) +{ if ((node != &ext2fs_root->diropen) &&
>> (node != currroot)) { free (node); } }
>> 
>> 
>> -static int ext2fs_read_block (ext2fs_node_t node, int fileblock)
>> { +static int ext2fs_read_block(struct ext2fs_node *node, int
>> fileblock) +{ struct ext2_data *data = node->data; struct
>> ext2_inode *inode = &node->inode; int blknr; @@ -396,7 +262,8 @@
>> static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
>> 
>> 
>> int ext2fs_read_file - (ext2fs_node_t node, int pos, unsigned int
>> len, char *buf) { + (struct ext2fs_node *node, int pos, unsigned
>> int len, char *buf) +{ int i; int blockcnt; int log2blocksize =
>> LOG2_EXT2_BLOCK_SIZE (node->data); @@ -455,8 +322,8 @@ int
>> ext2fs_read_file return (len); }
>> 
>> - -static int ext2fs_iterate_dir (ext2fs_node_t dir, char *name,
>> ext2fs_node_t * fnode, int *ftype) +int ext2fs_iterate_dir(struct
>> ext2fs_node *dir, char *name, + struct ext2fs_node **fnode, int
>> *ftype) { unsigned int fpos = 0; int status; @@ -485,7 +352,7 @@
>> static int ext2fs_iterate_dir (ext2fs_node_t dir, char *name,
>> ext2fs_node_t * fn } if (dirent.namelen != 0) { char
>> filename[dirent.namelen + 1]; - ext2fs_node_t fdiro; + struct
>> ext2fs_node *fdiro; int type = FILETYPE_UNKNOWN;
>> 
>> status = ext2fs_read_file (diro, @@ -587,8 +454,8 @@ static int
>> ext2fs_iterate_dir (ext2fs_node_t dir, char *name, ext2fs_node_t *
>> fn return (0); }
>> 
>> - -static char *ext2fs_read_symlink (ext2fs_node_t node) { +static
>> char *ext2fs_read_symlink(struct ext2fs_node *node) +{ char
>> *symlink; struct ext2fs_node *diro = node; int status; @@ -625,15
>> +492,16 @@ static char *ext2fs_read_symlink (ext2fs_node_t node) {
>> 
>> 
>> int ext2fs_find_file1 - (const char *currpath, - ext2fs_node_t
>> currroot, ext2fs_node_t * currfound, int *foundtype) { + (const
>> char *currpath, struct ext2fs_node *currroot, + struct ext2fs_node
>> **currfound, int *foundtype) +{ char fpath[strlen (currpath) + 1]; 
>> char *name = fpath; char *next; int status; int type =
>> FILETYPE_DIRECTORY; - ext2fs_node_t currnode = currroot; -
>> ext2fs_node_t oldnode = currroot; + struct ext2fs_node *currnode =
>> currroot; + struct ext2fs_node *oldnode = currroot;
>> 
>> strncpy (fpath, currpath, strlen (currpath) + 1);
>> 
>> @@ -729,8 +597,9 @@ int ext2fs_find_file1
>> 
>> 
>> int ext2fs_find_file - (const char *path, - ext2fs_node_t rootnode,
>> ext2fs_node_t * foundnode, int expecttype) { + (const char *path,
>> struct ext2fs_node *rootnode, + struct ext2fs_node **foundnode, int
>> expecttype) +{ int status; int foundtype = FILETYPE_DIRECTORY;
>> 
>> @@ -756,7 +625,7 @@ int ext2fs_find_file
>> 
>> 
>> int ext2fs_ls (const char *dirname) { - ext2fs_node_t dirnode; +
>> struct ext2fs_node *dirnode; int status;
>> 
>> if (ext2fs_root == NULL) { @@ -776,7 +645,7 @@ int ext2fs_ls (const
>> char *dirname) {
>> 
>> 
>> int ext2fs_open (const char *filename) { - ext2fs_node_t fdiro =
>> NULL; + struct ext2fs_node *fdiro = NULL; int status; int len;
>> 
>> @@ -806,8 +675,8 @@ fail: }
>> 
>> 
>> -int ext2fs_close (void - ) { +int ext2fs_close(void) +{ if
>> ((ext2fs_file != NULL) && (ext2fs_root != NULL)) { ext2fs_free_node
>> (ext2fs_file, &ext2fs_root->diropen); ext2fs_file = NULL; diff
>> --git a/fs/ext4/Makefile b/fs/ext4/Makefile new file mode 100644 
>> index 0000000..7add4ab --- /dev/null +++ b/fs/ext4/Makefile @@ -0,0
>> +1,51 @@ +# +# (C) Copyright 2006 +# Wolfgang Denk, DENX Software
>> Engineering, wd at denx.de. +# +# (C) Copyright 2003 +# Pavel
>> Bartusek, Sysgo Real-Time Solutions AG, pba at sysgo.de +# +# +# See
>> file CREDITS for list of people who contributed to this +#
>> project. +# +# This program is free software; you can redistribute
>> it and/or +# modify it under the terms of the GNU General Public
>> License as +# published by the Free Software Foundation; either
>> version 2 of +# the License, or (at your option) any later
>> version. +# +# This program is distributed in the hope that it will
>> be useful, +# but WITHOUT ANY WARRANTY; without even the implied
>> warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>> See the +# GNU General Public License for more details. +# +# You
>> should have received a copy of the GNU General Public License +#
>> along with this program; if not, write to the Free Software +#
>> Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA
>> 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB =
>> $(obj)libext4fs.o + +AOBJS = +COBJS-$(CONFIG_CMD_EXT4) := ext4fs.o
>> ext4_common.o dev.o + +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) 
>> +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y)) + + +all: $(LIB)
>> $(AOBJS) + +$(LIB): $(obj).depend $(OBJS) + $(call
>> cmd_link_o_target, $(OBJS)) + 
>> +#########################################################################
>>
>> 
+
>> +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + 
>> +sinclude $(obj).depend + 
>> +#########################################################################
>>
>> 
diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
>> new file mode 100644 index 0000000..2054be3 --- /dev/null +++
>> b/fs/ext4/dev.c @@ -0,0 +1,145 @@ +/* + * (C) Copyright 2011 - 2012
>> Samsung Electronics + * EXT4 filesystem implementation in Uboot by 
>> + * Uma Shankar + * Manjunatha C Achar + * + * made from existing
>> ext2/dev.c file of Uboot + * (C) Copyright 2004 + * esd gmbh + *
>> Reinhard Arlt + * + * based on code of fs/reiserfs/dev.c by + * + *
>> (C) Copyright 2003 - 2004 + * Sysgo AG, , Pavel Bartusek + * + *
>> This program is free software; you can redistribute it and/or
>> modify + * it under the terms of the GNU General Public License as
>> published by + * the Free Software Foundation; either version 2 of
>> the License, or + * (at your option) any later version. + * + *
>> This program is distributed in the hope that it will be useful, + *
>> but WITHOUT ANY WARRANTY; without even the implied warranty of + *
>> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *
>> GNU General Public License for more details. + * + * You should
>> have received a copy of the GNU General Public License + * along
>> with this program; if not, write to the Free Software + *
>> Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ 
>> + +/* + * Changelog: + * 0.1 - Newly created file for ext4fs
>> support. Taken from + *         fs/ext2/dev.c file in uboot. + */ 
>> + +#include +#include +#include + +static block_dev_desc_t
>> *ext4fs_block_dev_desc; +static disk_partition_t part_info; + +int
>> ext4fs_set_blk_dev(block_dev_desc_t *rbdd, int part) +{ +
>> ext4fs_block_dev_desc = rbdd; + + if (part == 0) { + /* disk
>> doesn't use partition table */ + part_info.start = 0; +
>> part_info.size = rbdd->lba; + part_info.blksz = rbdd->blksz; + }
>> else { + if (get_partition_info(ext4fs_block_dev_desc, + part,
>> &part_info)) + return 0; + } + return part_info.size; +} + +int
>> ext4fs_devread(int sector, int byte_offset, int byte_len, char
>> *buf) +{ + char sec_buf[SECTOR_SIZE]; + unsigned block_len; + + /*
>> Check partition boundaries */ + if ((sector < 0) +     || ((sector
>> + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >= +
>> part_info.size)) { + printf("%s read outside partition %d\n",
>> __func__, sector); + return 0; + } + + /* Get the read to the
>> beginning of a partition */ + sector += byte_offset >>
>> SECTOR_BITS; + byte_offset &= SECTOR_SIZE - 1; + + debug("



More information about the U-Boot mailing list