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>
7 * Data structures and headers for ext4 support have been taken from
8 * ext2 ls load support in Uboot
11 * esd gmbh <www.esd-electronics.com>
12 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
14 * based on code from grub2 fs/ext2.c and fs/fshelp.c by
15 * GRUB -- GRand Unified Bootloader
16 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #ifndef __EXT_COMMON__
34 #define __EXT_COMMON__
36 #define SECTOR_SIZE 0x200
38 /* Magic value used to identify an ext2 filesystem. */
39 #define EXT2_MAGIC 0xEF53
40 /* Amount of indirect blocks in an inode. */
41 #define INDIRECT_BLOCKS 12
42 /* Maximum lenght of a pathname. */
43 #define EXT2_PATH_MAX 4096
44 /* Maximum nesting of symlinks, used to prevent a loop. */
45 #define EXT2_MAX_SYMLINKCNT 8
47 /* Filetype used in directory entry. */
48 #define FILETYPE_UNKNOWN 0
49 #define FILETYPE_REG 1
50 #define FILETYPE_DIRECTORY 2
51 #define FILETYPE_SYMLINK 7
53 /* Filetype information as used in inodes. */
54 #define FILETYPE_INO_MASK 0170000
55 #define FILETYPE_INO_REG 0100000
56 #define FILETYPE_INO_DIRECTORY 0040000
57 #define FILETYPE_INO_SYMLINK 0120000
58 #define EXT2_ROOT_INO 2 /* Root inode */
60 /* The size of an ext2 block in bytes. */
61 #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
63 /* Log2 size of ext2 block in bytes. */
64 #define LOG2_BLOCK_SIZE(data) (__le32_to_cpu \
65 (data->sblock.log2_block_size) \
66 + EXT2_MIN_BLOCK_LOG_SIZE)
67 #define INODE_SIZE_FILESYSTEM(data) (__le32_to_cpu \
68 (data->sblock.inode_size))
73 /* Macro-instructions used to manage several block sizes */
74 #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
75 #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
76 #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
77 #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
79 /* The ext2 superblock. */
81 uint32_t total_inodes;
82 uint32_t total_blocks;
83 uint32_t reserved_blocks;
86 uint32_t first_data_block;
87 uint32_t log2_block_size;
88 uint32_t log2_fragment_size;
89 uint32_t blocks_per_group;
90 uint32_t fragments_per_group;
91 uint32_t inodes_per_group;
95 uint16_t max_mnt_count;
98 uint16_t error_handling;
99 uint16_t minor_revision_level;
101 uint32_t checkinterval;
103 uint32_t revision_level;
104 uint16_t uid_reserved;
105 uint16_t gid_reserved;
106 uint32_t first_inode;
108 uint16_t block_group_number;
109 uint32_t feature_compatibility;
110 uint32_t feature_incompat;
111 uint32_t feature_ro_compat;
112 uint32_t unique_id[4];
113 char volume_name[16];
114 char last_mounted_on[64];
115 uint32_t compression_info;
118 struct ext2_block_group {
119 __u32 block_id; /* Blocks bitmap block */
120 __u32 inode_id; /* Inodes bitmap block */
121 __u32 inode_table_id; /* Inodes table block */
122 __u16 free_blocks; /* Free blocks count */
123 __u16 free_inodes; /* Free inodes count */
124 __u16 used_dir_cnt; /* Directories count */
126 __u32 bg_reserved[2];
127 __u16 bg_itable_unused; /* Unused inodes count */
128 __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
131 /* The ext2 inode. */
142 uint32_t blockcnt; /* Blocks of 512 bytes!! */
147 uint32_t dir_blocks[INDIRECT_BLOCKS];
148 uint32_t indir_block;
149 uint32_t double_indir_block;
150 uint32_t triple_indir_block;
157 uint32_t fragment_addr;
161 /* The header of an ext2 directory entry. */
170 struct ext2_data *data;
171 struct ext2_inode inode;
176 /* Information about a "mounted" ext2 filesystem. */
178 struct ext2_sblock sblock;
179 struct ext2_inode *inode;
180 struct ext2fs_node diropen;
183 extern unsigned long part_offset;
185 int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
186 int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
187 int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
189 int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
190 int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,