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 * made from existing ext2/dev.c file of Uboot
9 * esd gmbh <www.esd-electronics.com>
10 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
12 * based on code of fs/reiserfs/dev.c by
14 * (C) Copyright 2003 - 2004
15 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 * 0.1 - Newly created file for ext4fs support. Taken from
36 * fs/ext2/dev.c file in uboot.
42 #include <ext_common.h>
43 #include "ext4_common.h"
45 unsigned long part_offset;
47 static block_dev_desc_t *ext4fs_block_dev_desc;
48 static disk_partition_t *part_info;
50 void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
52 ext4fs_block_dev_desc = rbdd;
54 part_offset = info->start;
55 get_fs()->total_sect = (info->size * info->blksz) / SECTOR_SIZE;
56 get_fs()->dev_desc = rbdd;
59 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
61 ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, SECTOR_SIZE);
64 /* Check partition boundaries */
66 || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
68 printf("%s read outside partition %d\n", __func__, sector);
72 /* Get the read to the beginning of a partition */
73 sector += byte_offset >> SECTOR_BITS;
74 byte_offset &= SECTOR_SIZE - 1;
76 debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
78 if (ext4fs_block_dev_desc == NULL) {
79 printf("** Invalid Block Device Descriptor (NULL)\n");
83 if (byte_offset != 0) {
84 /* read first part which isn't aligned with start of sector */
85 if (ext4fs_block_dev_desc->
86 block_read(ext4fs_block_dev_desc->dev,
87 part_info->start + sector, 1,
88 (unsigned long *) sec_buf) != 1) {
89 printf(" ** ext2fs_devread() read error **\n");
92 memcpy(buf, sec_buf + byte_offset,
93 min(SECTOR_SIZE - byte_offset, byte_len));
94 buf += min(SECTOR_SIZE - byte_offset, byte_len);
95 byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
102 /* read sector aligned part */
103 block_len = byte_len & ~(SECTOR_SIZE - 1);
105 if (block_len == 0) {
106 ALLOC_CACHE_ALIGN_BUFFER(u8, p, SECTOR_SIZE);
108 block_len = SECTOR_SIZE;
109 ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
110 part_info->start + sector,
111 1, (unsigned long *)p);
112 memcpy(buf, p, byte_len);
116 if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
117 part_info->start + sector,
118 block_len / SECTOR_SIZE,
119 (unsigned long *) buf) !=
120 block_len / SECTOR_SIZE) {
121 printf(" ** %s read error - block\n", __func__);
124 block_len = byte_len & ~(SECTOR_SIZE - 1);
126 byte_len -= block_len;
127 sector += block_len / SECTOR_SIZE;
130 /* read rest of data which are not in whole sector */
131 if (ext4fs_block_dev_desc->
132 block_read(ext4fs_block_dev_desc->dev,
133 part_info->start + sector, 1,
134 (unsigned long *) sec_buf) != 1) {
135 printf("* %s read error - last part\n", __func__);
138 memcpy(buf, sec_buf, byte_len);