Uma Shankar | 71014b6 | 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 | * Data structures and headers for ext4 support have been taken from |
| 8 | * ext2 ls load support in Uboot |
| 9 | * |
| 10 | * (C) Copyright 2004 |
| 11 | * esd gmbh <www.esd-electronics.com> |
| 12 | * Reinhard Arlt <reinhard.arlt@esd-electronics.com> |
| 13 | * |
| 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. |
| 17 | * |
| 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. |
| 22 | * |
| 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. |
| 27 | * |
| 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. |
| 31 | */ |
| 32 | |
| 33 | #ifndef __EXT_COMMON__ |
| 34 | #define __EXT_COMMON__ |
| 35 | #include <command.h> |
| 36 | #define SECTOR_SIZE 0x200 |
| 37 | #define SECTOR_BITS 9 |
| 38 | |
| 39 | /* Magic value used to identify an ext2 filesystem. */ |
| 40 | #define EXT2_MAGIC 0xEF53 |
| 41 | /* Amount of indirect blocks in an inode. */ |
| 42 | #define INDIRECT_BLOCKS 12 |
| 43 | /* Maximum lenght of a pathname. */ |
| 44 | #define EXT2_PATH_MAX 4096 |
| 45 | /* Maximum nesting of symlinks, used to prevent a loop. */ |
| 46 | #define EXT2_MAX_SYMLINKCNT 8 |
| 47 | |
| 48 | /* Filetype used in directory entry. */ |
| 49 | #define FILETYPE_UNKNOWN 0 |
| 50 | #define FILETYPE_REG 1 |
| 51 | #define FILETYPE_DIRECTORY 2 |
| 52 | #define FILETYPE_SYMLINK 7 |
| 53 | |
| 54 | /* Filetype information as used in inodes. */ |
| 55 | #define FILETYPE_INO_MASK 0170000 |
| 56 | #define FILETYPE_INO_REG 0100000 |
| 57 | #define FILETYPE_INO_DIRECTORY 0040000 |
| 58 | #define FILETYPE_INO_SYMLINK 0120000 |
| 59 | #define EXT2_ROOT_INO 2 /* Root inode */ |
| 60 | |
| 61 | /* Bits used as offset in sector */ |
| 62 | #define DISK_SECTOR_BITS 9 |
| 63 | /* The size of an ext2 block in bytes. */ |
| 64 | #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data)) |
| 65 | |
| 66 | /* Log2 size of ext2 block in 512 blocks. */ |
| 67 | #define LOG2_EXT2_BLOCK_SIZE(data) (__le32_to_cpu \ |
| 68 | (data->sblock.log2_block_size) + 1) |
| 69 | |
| 70 | /* Log2 size of ext2 block in bytes. */ |
| 71 | #define LOG2_BLOCK_SIZE(data) (__le32_to_cpu \ |
| 72 | (data->sblock.log2_block_size) + 10) |
| 73 | #define INODE_SIZE_FILESYSTEM(data) (__le32_to_cpu \ |
| 74 | (data->sblock.inode_size)) |
| 75 | |
| 76 | #define EXT2_FT_DIR 2 |
| 77 | #define SUCCESS 1 |
| 78 | |
| 79 | /* Macro-instructions used to manage several block sizes */ |
| 80 | #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */ |
| 81 | #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */ |
| 82 | #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE) |
| 83 | #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE) |
| 84 | |
| 85 | /* The ext2 superblock. */ |
| 86 | struct ext2_sblock { |
| 87 | uint32_t total_inodes; |
| 88 | uint32_t total_blocks; |
| 89 | uint32_t reserved_blocks; |
| 90 | uint32_t free_blocks; |
| 91 | uint32_t free_inodes; |
| 92 | uint32_t first_data_block; |
| 93 | uint32_t log2_block_size; |
| 94 | uint32_t log2_fragment_size; |
| 95 | uint32_t blocks_per_group; |
| 96 | uint32_t fragments_per_group; |
| 97 | uint32_t inodes_per_group; |
| 98 | uint32_t mtime; |
| 99 | uint32_t utime; |
| 100 | uint16_t mnt_count; |
| 101 | uint16_t max_mnt_count; |
| 102 | uint16_t magic; |
| 103 | uint16_t fs_state; |
| 104 | uint16_t error_handling; |
| 105 | uint16_t minor_revision_level; |
| 106 | uint32_t lastcheck; |
| 107 | uint32_t checkinterval; |
| 108 | uint32_t creator_os; |
| 109 | uint32_t revision_level; |
| 110 | uint16_t uid_reserved; |
| 111 | uint16_t gid_reserved; |
| 112 | uint32_t first_inode; |
| 113 | uint16_t inode_size; |
| 114 | uint16_t block_group_number; |
| 115 | uint32_t feature_compatibility; |
| 116 | uint32_t feature_incompat; |
| 117 | uint32_t feature_ro_compat; |
| 118 | uint32_t unique_id[4]; |
| 119 | char volume_name[16]; |
| 120 | char last_mounted_on[64]; |
| 121 | uint32_t compression_info; |
| 122 | }; |
| 123 | |
| 124 | struct ext2_block_group { |
| 125 | __u32 block_id; /* Blocks bitmap block */ |
| 126 | __u32 inode_id; /* Inodes bitmap block */ |
| 127 | __u32 inode_table_id; /* Inodes table block */ |
| 128 | __u16 free_blocks; /* Free blocks count */ |
| 129 | __u16 free_inodes; /* Free inodes count */ |
| 130 | __u16 used_dir_cnt; /* Directories count */ |
| 131 | __u16 bg_flags; |
| 132 | __u32 bg_reserved[2]; |
| 133 | __u16 bg_itable_unused; /* Unused inodes count */ |
| 134 | __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/ |
| 135 | }; |
| 136 | |
| 137 | /* The ext2 inode. */ |
| 138 | struct ext2_inode { |
| 139 | uint16_t mode; |
| 140 | uint16_t uid; |
| 141 | uint32_t size; |
| 142 | uint32_t atime; |
| 143 | uint32_t ctime; |
| 144 | uint32_t mtime; |
| 145 | uint32_t dtime; |
| 146 | uint16_t gid; |
| 147 | uint16_t nlinks; |
| 148 | uint32_t blockcnt; /* Blocks of 512 bytes!! */ |
| 149 | uint32_t flags; |
| 150 | uint32_t osd1; |
| 151 | union { |
| 152 | struct datablocks { |
| 153 | uint32_t dir_blocks[INDIRECT_BLOCKS]; |
| 154 | uint32_t indir_block; |
| 155 | uint32_t double_indir_block; |
| 156 | uint32_t triple_indir_block; |
| 157 | } blocks; |
| 158 | char symlink[60]; |
| 159 | } b; |
| 160 | uint32_t version; |
| 161 | uint32_t acl; |
| 162 | uint32_t dir_acl; |
| 163 | uint32_t fragment_addr; |
| 164 | uint32_t osd2[3]; |
| 165 | }; |
| 166 | |
| 167 | /* The header of an ext2 directory entry. */ |
| 168 | struct ext2_dirent { |
| 169 | uint32_t inode; |
| 170 | uint16_t direntlen; |
| 171 | uint8_t namelen; |
| 172 | uint8_t filetype; |
| 173 | }; |
| 174 | |
| 175 | struct ext2fs_node { |
| 176 | struct ext2_data *data; |
| 177 | struct ext2_inode inode; |
| 178 | int ino; |
| 179 | int inode_read; |
| 180 | }; |
| 181 | |
| 182 | /* Information about a "mounted" ext2 filesystem. */ |
| 183 | struct ext2_data { |
| 184 | struct ext2_sblock sblock; |
| 185 | struct ext2_inode *inode; |
| 186 | struct ext2fs_node diropen; |
| 187 | }; |
| 188 | |
Rob Herring | 752e1bd | 2012-08-23 11:31:46 +0000 | [diff] [blame] | 189 | extern unsigned long part_offset; |
| 190 | |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 191 | int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 192 | int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 193 | int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc, |
| 194 | char *const argv[]); |
| 195 | int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 196 | int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc, |
| 197 | char *const argv[]); |
Uma Shankar | 71014b6 | 2012-05-25 21:21:44 +0530 | [diff] [blame] | 198 | #endif |