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 * SPDX-License-Identifier: GPL-2.0+
21 #ifndef __EXT_COMMON__
22 #define __EXT_COMMON__
24 #define SECTOR_SIZE 0x200
26 /* Magic value used to identify an ext2 filesystem. */
27 #define EXT2_MAGIC 0xEF53
28 /* Amount of indirect blocks in an inode. */
29 #define INDIRECT_BLOCKS 12
30 /* Maximum lenght of a pathname. */
31 #define EXT2_PATH_MAX 4096
32 /* Maximum nesting of symlinks, used to prevent a loop. */
33 #define EXT2_MAX_SYMLINKCNT 8
35 /* Filetype used in directory entry. */
36 #define FILETYPE_UNKNOWN 0
37 #define FILETYPE_REG 1
38 #define FILETYPE_DIRECTORY 2
39 #define FILETYPE_SYMLINK 7
41 /* Filetype information as used in inodes. */
42 #define FILETYPE_INO_MASK 0170000
43 #define FILETYPE_INO_REG 0100000
44 #define FILETYPE_INO_DIRECTORY 0040000
45 #define FILETYPE_INO_SYMLINK 0120000
46 #define EXT2_ROOT_INO 2 /* Root inode */
48 /* The size of an ext2 block in bytes. */
49 #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
51 /* Log2 size of ext2 block in bytes. */
52 #define LOG2_BLOCK_SIZE(data) (le32_to_cpu \
53 (data->sblock.log2_block_size) \
54 + EXT2_MIN_BLOCK_LOG_SIZE)
55 #define INODE_SIZE_FILESYSTEM(data) (le16_to_cpu \
56 (data->sblock.inode_size))
61 /* Macro-instructions used to manage several block sizes */
62 #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
63 #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
64 #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
65 #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
67 /* The ext2 superblock. */
71 __le32 reserved_blocks;
74 __le32 first_data_block;
75 __le32 log2_block_size;
76 __le32 log2_fragment_size;
77 __le32 blocks_per_group;
78 __le32 fragments_per_group;
79 __le32 inodes_per_group;
86 __le16 error_handling;
87 __le16 minor_revision_level;
91 __le32 revision_level;
96 __le16 block_group_number;
97 __le32 feature_compatibility;
98 __le32 feature_incompat;
99 __le32 feature_ro_compat;
101 char volume_name[16];
102 char last_mounted_on[64];
103 __le32 compression_info;
106 struct ext2_block_group {
107 __le32 block_id; /* Blocks bitmap block */
108 __le32 inode_id; /* Inodes bitmap block */
109 __le32 inode_table_id; /* Inodes table block */
110 __le16 free_blocks; /* Free blocks count */
111 __le16 free_inodes; /* Free inodes count */
112 __le16 used_dir_cnt; /* Directories count */
114 __le32 bg_reserved[2];
115 __le16 bg_itable_unused; /* Unused inodes count */
116 __le16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
119 /* The ext2 inode. */
130 __le32 blockcnt; /* Blocks of 512 bytes!! */
135 __le32 dir_blocks[INDIRECT_BLOCKS];
137 __le32 double_indir_block;
138 __le32 triple_indir_block;
145 __le32 fragment_addr;
149 /* The header of an ext2 directory entry. */
158 struct ext2_data *data;
159 struct ext2_inode inode;
164 /* Information about a "mounted" ext2 filesystem. */
166 struct ext2_sblock sblock;
167 struct ext2_inode *inode;
168 struct ext2fs_node diropen;
171 extern lbaint_t part_offset;
173 int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
174 int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
175 int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
177 int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
178 int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,