public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512.
@ 2013-03-26  8:15 egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

The patches provide fixes for partition tables:
 - GPT
 - ISO (to ignore devices with blocksize != 512)

The ext4 fs code also got fixed. I've reviewed the fat code, it seems 
to be ok already (except for a bug that I came across).
I may be persuaded to take a shot at other fs which are supported by 
a vanilla Linux kernel.

Cheers,
	Egbert.

Egbert Eich (5):
  disk/gpt: Fix GPT Partition handling for Blocksize != 512.
  disk/iso: Add Support for Block Sizes > 512 Byte to ISO partition
    support.
  fs/fat: Don't multiply fatsize  with sector size.
  part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.
  fs/ext4: Support device block sizes != 512 bytes.

 common/cmd_ide.c          |    4 +++
 common/cmd_sata.c         |    1 +
 common/cmd_scsi.c         |    2 +
 common/usb_storage.c      |    1 +
 disk/part_efi.c           |   32 +++++++++++++-------------
 disk/part_iso.c           |    3 ++
 drivers/block/ata_piix.c  |    1 +
 drivers/block/pata_bfin.c |    1 +
 drivers/block/systemace.c |    1 +
 drivers/mmc/mmc.c         |    1 +
 fs/ext4/dev.c             |   52 +++++++++++++++++++++++++++-----------------
 fs/ext4/ext4_common.c     |   26 ++++++++++------------
 fs/ext4/ext4_common.h     |    2 +-
 fs/ext4/ext4_journal.c    |    6 +---
 fs/ext4/ext4_write.c      |   27 +++++++++++------------
 fs/ext4/ext4fs.c          |   11 +++++----
 fs/fat/fat_write.c        |    1 -
 include/common.h          |   12 +++++++--
 include/ext4fs.h          |    1 +
 include/ext_common.h      |    9 +-------
 include/part.h            |    8 +++++++
 include/part_efi.h        |    2 -
 22 files changed, 116 insertions(+), 88 deletions(-)

-- 
1.7.7

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize != 512.
  2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
@ 2013-03-26  8:15 ` egbert.eich at googlemail.com
  2013-03-26 11:30   ` Wolfgang Denk
  2013-04-09 16:03   ` [U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize " Egbert Eich
  2013-03-26  8:15 ` [U-Boot] [PATCH 2/5] disk/iso: Add Support for Block Sizes > 512 Byte to ISO partition support egbert.eich at googlemail.com
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

Disks beyond 2T in size use blocksizes of 4096 bytes. However a lot of
code in u-boot  still assumes a 512 byte blocksize.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 disk/part_efi.c    |   32 ++++++++++++++++----------------
 include/common.h   |   10 ++++++++--
 include/part.h     |    3 +++
 include/part_efi.h |    2 --
 4 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index b3fd0e9..75315ef 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -114,7 +114,7 @@ static inline int is_bootable(gpt_entry *p)
 
 void print_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 	int i = 0;
 	char uuid[37];
@@ -161,7 +161,7 @@ void print_part_efi(block_dev_desc_t * dev_desc)
 int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 				disk_partition_t * info)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 
 	/* "part" argument must be at least 1 */
@@ -189,7 +189,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 	/* The ending LBA is inclusive, to calculate size, add 1 to it */
 	info->size = ((u64)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1)
 		     - info->start;
-	info->blksz = GPT_BLOCK_SIZE;
+	info->blksz = dev_desc->blksz;
 
 	sprintf((char *)info->name, "%s",
 			print_efiname(&gpt_pte[part - 1]));
@@ -209,7 +209,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
 int test_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, legacymbr, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
 
 	/* Read legacy MBR from block 0 and validate it */
 	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)legacymbr) != 1)
@@ -310,9 +310,8 @@ static int string_uuid(char *uuid, u8 *dst)
 int write_gpt_table(block_dev_desc_t *dev_desc,
 		gpt_header *gpt_h, gpt_entry *gpt_e)
 {
-	const int pte_blk_num = (gpt_h->num_partition_entries
-		* sizeof(gpt_entry)) / dev_desc->blksz;
-
+	const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries
+					   * sizeof(gpt_entry)), dev_desc);
 	u32 calc_crc32;
 	u64 val;
 
@@ -335,8 +334,8 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 	if (dev_desc->block_write(dev_desc->dev, 1, 1, gpt_h) != 1)
 		goto err;
 
-	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_num, gpt_e)
-	    != pte_blk_num)
+	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_cnt, gpt_e)
+	    != pte_blk_cnt)
 		goto err;
 
 	/* recalculate the values for the Second GPT Header */
@@ -351,7 +350,7 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 
 	if (dev_desc->block_write(dev_desc->dev,
 				  le32_to_cpu(gpt_h->last_usable_lba + 1),
-				  pte_blk_num, gpt_e) != pte_blk_num)
+				  pte_blk_cnt, gpt_e) != pte_blk_cnt)
 		goto err;
 
 	if (dev_desc->block_write(dev_desc->dev,
@@ -461,13 +460,13 @@ int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
 {
 	int ret;
 
-	gpt_header *gpt_h = calloc(1, sizeof(gpt_header));
+	gpt_header *gpt_h = calloc(1, PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc));
 	if (gpt_h == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		return -1;
 	}
 
-	gpt_entry *gpt_e = calloc(GPT_ENTRY_NUMBERS, sizeof(gpt_entry));
+	gpt_entry *gpt_e = calloc(1, PAD_TO_BLOCKSIZE(GPT_ENTRY_NUMBERS * sizeof(gpt_entry), dev_desc));
 	if (gpt_e == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		free(gpt_h);
@@ -651,7 +650,7 @@ static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba,
 static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 					 gpt_header * pgpt_head)
 {
-	size_t count = 0;
+	size_t count = 0, blk_cnt;
 	gpt_entry *pte = NULL;
 
 	if (!dev_desc || !pgpt_head) {
@@ -668,7 +667,7 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
 	/* Allocate memory for PTE, remember to FREE */
 	if (count != 0) {
-		pte = memalign(ARCH_DMA_MINALIGN, count);
+		pte = memalign(ARCH_DMA_MINALIGN, PAD_TO_BLOCKSIZE(count,dev_desc));
 	}
 
 	if (count == 0 || pte == NULL) {
@@ -679,10 +678,11 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 	}
 
 	/* Read GPT Entries from device */
+	blk_cnt = BLOCK_CNT(count, dev_desc);
 	if (dev_desc->block_read (dev_desc->dev,
 		le64_to_cpu(pgpt_head->partition_entry_lba),
-		(lbaint_t) (count / GPT_BLOCK_SIZE), pte)
-		!= (count / GPT_BLOCK_SIZE)) {
+		(lbaint_t) (blk_cnt), pte)
+		!= blk_cnt) {
 
 		printf("*** ERROR: Can't read GPT Entries ***\n");
 		free(pte);
diff --git a/include/common.h b/include/common.h
index d41aeb4..a6172cd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -990,10 +990,16 @@ static inline void unmap_sysmem(const void *vaddr)
  * of a function scoped static buffer.  It can not be used to create a cache
  * line aligned global buffer.
  */
-#define ALLOC_ALIGN_BUFFER(type, name, size, align)			\
-	char __##name[ROUND(size * sizeof(type), align) + (align - 1)];	\
+#define PAD_COUNT(s, pad) ((s - 1) / pad + 1)
+#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
+#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
+	char __##name[ROUND(PAD_SIZE(size * sizeof(type),pad), align) + (align - 1)]; \
 									\
 	type *name = (type *) ALIGN((uintptr_t)__##name, align)
+#define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
+#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
 #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
 	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
diff --git a/include/part.h b/include/part.h
index c58a734..71607d7 100644
--- a/include/part.h
+++ b/include/part.h
@@ -55,6 +55,9 @@ typedef struct block_dev_desc {
 	void		*priv;		/* driver private struct pointer */
 }block_dev_desc_t;
 
+#define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
+#define PAD_TO_BLOCKSIZE(size, block_dev_desc) (PAD_SIZE(size, block_dev_desc->blksz))
+
 /* Interface types: */
 #define IF_TYPE_UNKNOWN		0
 #define IF_TYPE_IDE		1
diff --git a/include/part_efi.h b/include/part_efi.h
index 6de0a32..95e4c8f 100644
--- a/include/part_efi.h
+++ b/include/part_efi.h
@@ -38,7 +38,6 @@
 #define EFI_PMBR_OSTYPE_EFI 0xEF
 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
 
-#define GPT_BLOCK_SIZE 512
 #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
 #define GPT_HEADER_REVISION_V1 0x00010000
 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL
@@ -112,7 +111,6 @@ typedef struct _gpt_header {
 	__le32 num_partition_entries;
 	__le32 sizeof_partition_entry;
 	__le32 partition_entry_array_crc32;
-	u8 reserved2[GPT_BLOCK_SIZE - 92];
 } __packed gpt_header;
 
 typedef union _gpt_entry_attributes {
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 2/5] disk/iso: Add Support for Block Sizes > 512 Byte to ISO partition support.
  2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
@ 2013-03-26  8:15 ` egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 3/5] fs/fat: Don't multiply fatsize with sector size egbert.eich at googlemail.com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

For ISO we check the block size of the device if this is != the CD sector
size we assume that the device has no ISO partition.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 disk/part_iso.c  |    3 +++
 include/common.h |    2 +-
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/disk/part_iso.c b/disk/part_iso.c
index 49639af..cc323b0 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -73,6 +73,9 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
 	iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
 	iso_init_def_entry_t *pide;
 
+	if (dev_desc->blksz != CD_SECTSIZE)
+		return -1;
+
 	/* the first sector (sector 0x10) must be a primary volume desc */
 	blkaddr=PVD_OFFSET;
 	if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1)
diff --git a/include/common.h b/include/common.h
index a6172cd..1db5dcf 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1010,7 +1010,7 @@ static inline void unmap_sysmem(const void *vaddr)
  */
 #define DEFINE_ALIGN_BUFFER(type, name, size, align)			\
 	static char __##name[roundup(size * sizeof(type), align)]	\
-			__attribute__((aligned(align)));				\
+			__attribute__((aligned(align)));		\
 									\
 	static type *name = (type *)__##name
 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 3/5] fs/fat: Don't multiply fatsize with sector size.
  2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 2/5] disk/iso: Add Support for Block Sizes > 512 Byte to ISO partition support egbert.eich at googlemail.com
@ 2013-03-26  8:15 ` egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct egbert.eich at googlemail.com
  2013-03-26  8:15 ` [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes egbert.eich at googlemail.com
  4 siblings, 0 replies; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

Here at this place we need the fat size in sectors not bytes.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 fs/fat/fat_write.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index b4022aa..fd07240 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -120,7 +120,6 @@ static int flush_fat_buffer(fsdata *mydata)
 	__u8 *bufptr = mydata->fatbuf;
 	__u32 startblock = mydata->fatbufnum * FATBUFBLOCKS;
 
-	fatlength *= mydata->sect_size;
 	startblock += mydata->fat_sect;
 
 	if (getsize > fatlength)
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.
  2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
                   ` (2 preceding siblings ...)
  2013-03-26  8:15 ` [U-Boot] [PATCH 3/5] fs/fat: Don't multiply fatsize with sector size egbert.eich at googlemail.com
@ 2013-03-26  8:15 ` egbert.eich at googlemail.com
  2013-03-26 11:31   ` Wolfgang Denk
  2013-03-26  8:15 ` [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes egbert.eich at googlemail.com
  4 siblings, 1 reply; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

This value serves as the shift value used to calculate the block number
to read in file systems when implementing aviable block sizes.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 common/cmd_ide.c          |    4 ++++
 common/cmd_sata.c         |    1 +
 common/cmd_scsi.c         |    2 ++
 common/usb_storage.c      |    1 +
 drivers/block/ata_piix.c  |    1 +
 drivers/block/pata_bfin.c |    1 +
 drivers/block/systemace.c |    1 +
 drivers/mmc/mmc.c         |    1 +
 include/part.h            |    5 +++++
 9 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 0105bdb..de981f7 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -455,6 +455,7 @@ void ide_init(void)
 		ide_dev_desc[i].dev = i;
 		ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
 		ide_dev_desc[i].blksz = 0;
+		ide_dev_desc[i].log2blksz = LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz)); /* just init to an invalid value */
 		ide_dev_desc[i].lba = 0;
 		ide_dev_desc[i].block_read = ide_read;
 		ide_dev_desc[i].block_write = ide_write;
@@ -806,6 +807,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 	/* assuming HD */
 	dev_desc->type = DEV_TYPE_HARDDISK;
 	dev_desc->blksz = ATA_BLOCKSIZE;
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 	dev_desc->lun = 0;	/* just to fill something in... */
 
 #if 0				/* only used to test the powersaving mode,
@@ -1448,6 +1450,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 	dev_desc->lun = 0;
 	dev_desc->lba = 0;
 	dev_desc->blksz = 0;
+	dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz)); /* just init to an invalid value */
 	dev_desc->type = iobuf[0] & 0x1f;
 
 	if ((iobuf[1] & 0x80) == 0x80)
@@ -1492,6 +1495,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 	dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
 		((unsigned long) iobuf[5] << 16) +
 		((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 #ifdef CONFIG_LBA48
 	/* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
 	dev_desc->lba48 = 0;
diff --git a/common/cmd_sata.c b/common/cmd_sata.c
index 8d57285..5a57a37 100644
--- a/common/cmd_sata.c
+++ b/common/cmd_sata.c
@@ -44,6 +44,7 @@ int __sata_initialize(void)
 		sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
 		sata_dev_desc[i].lba = 0;
 		sata_dev_desc[i].blksz = 512;
+		sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
 		sata_dev_desc[i].block_read = sata_read;
 		sata_dev_desc[i].block_write = sata_write;
 
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index 266bfa6..cf2cbba 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -106,6 +106,7 @@ void scsi_scan(int mode)
 		scsi_dev_desc[i].lun=0xff;
 		scsi_dev_desc[i].lba=0;
 		scsi_dev_desc[i].blksz=0;
+		scsi_dev_desc[i].log2blksz = LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz)); /* just init to an invalid value */
 		scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
 		scsi_dev_desc[i].vendor[0]=0;
 		scsi_dev_desc[i].product[0]=0;
@@ -166,6 +167,7 @@ void scsi_scan(int mode)
 			}
 			scsi_dev_desc[scsi_max_devs].lba=capacity;
 			scsi_dev_desc[scsi_max_devs].blksz=blksz;
+			scsi_dev_desc[scsi_max_devs].log2blksz = LOG2(scsi_dev_desc[scsi_max_devs].blksz);
 			scsi_dev_desc[scsi_max_devs].type=perq;
 			init_part(&scsi_dev_desc[scsi_max_devs]);
 removable:
diff --git a/common/usb_storage.c b/common/usb_storage.c
index fb322b4..c5db044 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -1430,6 +1430,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
 			*capacity, *blksz);
 	dev_desc->lba = *capacity;
 	dev_desc->blksz = *blksz;
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 	dev_desc->type = perq;
 	USB_STOR_PRINTF(" address %d\n", dev_desc->target);
 	USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type);
diff --git a/drivers/block/ata_piix.c b/drivers/block/ata_piix.c
index 1e33a66..fcae448 100644
--- a/drivers/block/ata_piix.c
+++ b/drivers/block/ata_piix.c
@@ -406,6 +406,7 @@ void sata_identify(int num, int dev)
 	/* assuming HD */
 	sata_dev_desc[devno].type = DEV_TYPE_HARDDISK;
 	sata_dev_desc[devno].blksz = ATA_BLOCKSIZE;
+	sata_dev_desc[devno].log2blksz = LOG2(sata_dev_desc[devno].blksz);
 	sata_dev_desc[devno].lun = 0;	/* just to fill something in... */
 }
 
diff --git a/drivers/block/pata_bfin.c b/drivers/block/pata_bfin.c
index b847dd9..db6d6ef 100644
--- a/drivers/block/pata_bfin.c
+++ b/drivers/block/pata_bfin.c
@@ -897,6 +897,7 @@ static void bfin_ata_identify(struct ata_port *ap, int dev)
 	/* assuming HD */
 	sata_dev_desc[ap->port_no].type = DEV_TYPE_HARDDISK;
 	sata_dev_desc[ap->port_no].blksz = ATA_SECT_SIZE;
+	sata_dev_desc[ap->port_no].log2blksz = LOG2(sata_dev_desc[ap->port_no].blksz);
 	sata_dev_desc[ap->port_no].lun = 0;	/* just to fill something in... */
 
 	printf("PATA device#%d %s is found on ata port#%d.\n",
diff --git a/drivers/block/systemace.c b/drivers/block/systemace.c
index bf29cbb..b08715f 100644
--- a/drivers/block/systemace.c
+++ b/drivers/block/systemace.c
@@ -127,6 +127,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
 		systemace_dev.part_type = PART_TYPE_UNKNOWN;
 		systemace_dev.type = DEV_TYPE_HARDDISK;
 		systemace_dev.blksz = 512;
+		systemace_dev.log2blksz = LOG2(systemace_dev.blksz);
 		systemace_dev.removable = 1;
 		systemace_dev.block_read = systemace_read;
 
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 7b5fdd9..7db633c 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1174,6 +1174,7 @@ static int mmc_startup(struct mmc *mmc)
 	mmc->block_dev.lun = 0;
 	mmc->block_dev.type = 0;
 	mmc->block_dev.blksz = mmc->read_bl_len;
+	mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz);
 	mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
 	sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x",
 		mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff),
diff --git a/include/part.h b/include/part.h
index 71607d7..44792fc 100644
--- a/include/part.h
+++ b/include/part.h
@@ -38,6 +38,7 @@ typedef struct block_dev_desc {
 #endif
 	lbaint_t	lba;		/* number of blocks */
 	unsigned long	blksz;		/* block size */
+	int		log2blksz;	/* for convenience: log2(blksz) */
 	char		vendor [40+1];	/* IDE model, SCSI Vendor */
 	char		product[20+1];	/* IDE Serial no, SCSI product */
 	char		revision[8+1];	/* firmware revision */
@@ -57,6 +58,10 @@ typedef struct block_dev_desc {
 
 #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
 #define PAD_TO_BLOCKSIZE(size, block_dev_desc) (PAD_SIZE(size, block_dev_desc->blksz))
+#define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
+		 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
+		 ((x & 0xffff0000) ? 16 : 0))
+#define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
 
 /* Interface types: */
 #define IF_TYPE_UNKNOWN		0
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes.
  2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
                   ` (3 preceding siblings ...)
  2013-03-26  8:15 ` [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct egbert.eich at googlemail.com
@ 2013-03-26  8:15 ` egbert.eich at googlemail.com
  2013-03-26 11:32   ` Wolfgang Denk
  4 siblings, 1 reply; 17+ messages in thread
From: egbert.eich at googlemail.com @ 2013-03-26  8:15 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

The 512 byte block size was hard coded in the ext4 file systems. Large
harddisks today support bigger block sizes typically 4096 bytes.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 fs/ext4/dev.c          |   52 +++++++++++++++++++++++++++++------------------
 fs/ext4/ext4_common.c  |   26 +++++++++++------------
 fs/ext4/ext4_common.h  |    2 +-
 fs/ext4/ext4_journal.c |    6 +---
 fs/ext4/ext4_write.c   |   27 ++++++++++++------------
 fs/ext4/ext4fs.c       |   11 +++++----
 include/ext4fs.h       |    1 +
 include/ext_common.h   |    9 +-------
 8 files changed, 68 insertions(+), 66 deletions(-)

diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
index 464a67d..c6e9576 100644
--- a/fs/ext4/dev.c
+++ b/fs/ext4/dev.c
@@ -40,6 +40,7 @@
 #include <config.h>
 #include <ext4fs.h>
 #include <ext_common.h>
+#include "ext4_common.h"
 
 unsigned long part_offset;
 
@@ -48,37 +49,38 @@ static disk_partition_t *part_info;
 
 void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
 {
+	assert(rbdd->blksz == (1 << rbdd->log2blksz));
 	ext4fs_block_dev_desc = rbdd;
 	part_info = info;
 	part_offset = info->start;
-	get_fs()->total_sect = (info->size * info->blksz) / SECTOR_SIZE;
+	get_fs()->total_sect = (info->size * info->blksz) >> get_fs()->dev_desc->log2blksz;
 	get_fs()->dev_desc = rbdd;
 }
 
 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, SECTOR_SIZE);
 	unsigned block_len;
+	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf,
+				 (ext4fs_block_dev_desc ? ext4fs_block_dev_desc->blksz: 0));
+	if (ext4fs_block_dev_desc == NULL) {
+		printf("** Invalid Block Device Descriptor (NULL)\n");
+		return 0;
+	}
 
 	/* Check partition boundaries */
 	if ((sector < 0)
-	    || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
+	    || ((sector + ((byte_offset + byte_len - 1) >> ext4fs_block_dev_desc->log2blksz)) >=
 		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;
+	sector += byte_offset >> ext4fs_block_dev_desc->log2blksz;
+	byte_offset &= ext4fs_block_dev_desc->blksz - 1;
 
 	debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
 
-	if (ext4fs_block_dev_desc == NULL) {
-		printf("** Invalid Block Device Descriptor (NULL)\n");
-		return 0;
-	}
-
 	if (byte_offset != 0) {
 		/* read first part which isn't aligned with start of sector */
 		if (ext4fs_block_dev_desc->
@@ -89,9 +91,9 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 			return 0;
 		}
 		memcpy(buf, sec_buf + byte_offset,
-			min(SECTOR_SIZE - byte_offset, byte_len));
-		buf += min(SECTOR_SIZE - byte_offset, byte_len);
-		byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
+			min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len));
+		buf += min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len);
+		byte_len -= min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len);
 		sector++;
 	}
 
@@ -99,12 +101,12 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 		return 1;
 
 	/* read sector aligned part */
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 
 	if (block_len == 0) {
-		ALLOC_CACHE_ALIGN_BUFFER(u8, p, SECTOR_SIZE);
+		ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_block_dev_desc->blksz);
 
-		block_len = SECTOR_SIZE;
+		block_len = ext4fs_block_dev_desc->blksz;
 		ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 						  part_info->start + sector,
 						  1, (unsigned long *)p);
@@ -114,16 +116,16 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 
 	if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 					       part_info->start + sector,
-					       block_len / SECTOR_SIZE,
+					       block_len >> ext4fs_block_dev_desc->log2blksz,
 					       (unsigned long *) buf) !=
-					       block_len / SECTOR_SIZE) {
+					       block_len >> ext4fs_block_dev_desc->log2blksz) {
 		printf(" ** %s read error - block\n", __func__);
 		return 0;
 	}
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 	buf += block_len;
 	byte_len -= block_len;
-	sector += block_len / SECTOR_SIZE;
+	sector += block_len / ext4fs_block_dev_desc->blksz;
 
 	if (byte_len != 0) {
 		/* read rest of data which are not in whole sector */
@@ -138,3 +140,13 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 	}
 	return 1;
 }
+
+int ext4_read_superblock(char *buffer)
+{
+	struct ext_filesystem *fs = get_fs();
+	int sect = SUPERBLOCK_START >> fs->dev_desc->log2blksz;
+	int off = SUPERBLOCK_START % fs->dev_desc->blksz;
+
+	return ext4fs_devread(sect, off, SUPERBLOCK_SIZE,
+				buffer);
+}
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index f12b805..69d5abc 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -71,18 +71,17 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 	uint64_t startblock;
 	uint64_t remainder;
 	unsigned char *temp_ptr = NULL;
-	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, SECTOR_SIZE);
 	struct ext_filesystem *fs = get_fs();
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, fs->dev_desc->blksz);
 
-	startblock = off / (uint64_t)SECTOR_SIZE;
+	startblock = off >> fs->dev_desc->log2blksz;
 	startblock += part_offset;
-	remainder = off % (uint64_t)SECTOR_SIZE;
-	remainder &= SECTOR_SIZE - 1;
+	remainder = off & (uint64_t)(fs->dev_desc->blksz - 1);
 
 	if (fs->dev_desc == NULL)
 		return;
 
-	if ((startblock + (size / SECTOR_SIZE)) >
+	if ((startblock + (size >> fs->dev_desc->log2blksz)) >
 	    (part_offset + fs->total_sect)) {
 		printf("part_offset is %lu\n", part_offset);
 		printf("total_sector is %llu\n", fs->total_sect);
@@ -101,10 +100,10 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 						  startblock, 1, sec_buf);
 		}
 	} else {
-		if (size / SECTOR_SIZE != 0) {
+		if (size >> fs->dev_desc->log2blksz != 0) {
 			fs->dev_desc->block_write(fs->dev_desc->dev,
 						  startblock,
-						  size / SECTOR_SIZE,
+						  size >> fs->dev_desc->log2blksz,
 						  (unsigned long *)buf);
 		} else {
 			fs->dev_desc->block_read(fs->dev_desc->dev,
@@ -1469,7 +1468,7 @@ static int ext4fs_blockgroup
 	debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n",
 	      group, blkno, blkoff);
 
-	return ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data),
+	return ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - get_fs()->dev_desc->log2blksz),
 			      blkoff, sizeof(struct ext2_block_group),
 			      (char *)blkgrp);
 }
@@ -1495,7 +1494,7 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
 	    (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
 	blkoff = (ino % inodes_per_block) * fs->inodesz;
 	/* Read the inode. */
-	status = ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data), blkoff,
+	status = ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - fs->dev_desc->log2blksz), blkoff,
 				sizeof(struct ext2_inode), (char *)inode);
 	if (status == 0)
 		return 0;
@@ -1515,7 +1514,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 	unsigned long long start;
 	/* get the blocksize of the filesystem */
 	blksz = EXT2_BLOCK_SIZE(ext4fs_root);
-	log2_blksz = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
+	log2_blksz = LOG2_BLOCK_SIZE(ext4fs_root) - get_fs()->dev_desc->log2blksz;
 	if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) {
 		char *buf = zalloc(blksz);
 		if (!buf)
@@ -1839,7 +1838,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 		blknr = __le32_to_cpu(ext4fs_indir3_block
 				      [rblock % perblock_child]);
 	}
-	debug("ext4fs_read_block %ld\n", blknr);
+	debug("read_allocated_block %ld\n", blknr);
 
 	return blknr;
 }
@@ -2193,13 +2192,12 @@ int ext4fs_mount(unsigned part_length)
 	struct ext2_data *data;
 	int status;
 	struct ext_filesystem *fs = get_fs();
-	data = zalloc(sizeof(struct ext2_data));
+	data = zalloc(SUPERBLOCK_SIZE);
 	if (!data)
 		return 0;
 
 	/* Read the superblock. */
-	status = ext4fs_devread(1 * 2, 0, sizeof(struct ext2_sblock),
-				(char *)&data->sblock);
+	status = ext4_read_superblock((char *)&data->sblock);
 
 	if (status == 0)
 		goto fail;
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 87cab16..5fc0ce9 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -51,7 +51,7 @@
 
 #define S_IFLNK		0120000		/* symbolic link */
 #define BLOCK_NO_ONE		1
-#define SUPERBLOCK_SECTOR	2
+#define SUPERBLOCK_START	(2 * 512)
 #define SUPERBLOCK_SIZE	1024
 #define F_FILE			1
 
diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c
index 9f01708..4a84384 100644
--- a/fs/ext4/ext4_journal.c
+++ b/fs/ext4/ext4_journal.c
@@ -534,16 +534,14 @@ end:
 		jsb->s_start = cpu_to_be32(1);
 		jsb->s_sequence = cpu_to_be32(be32_to_cpu(jsb->s_sequence) + 1);
 		/* get the superblock */
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 		fs->sb->feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER;
 
 		/* Update the super block */
 		put_ext4((uint64_t) (SUPERBLOCK_SIZE),
 			 (struct ext2_sblock *)fs->sb,
 			 (uint32_t) SUPERBLOCK_SIZE);
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 
 		blknr = read_allocated_block(&inode_journal,
 					 EXT2_JOURNAL_SUPERBLOCK);
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index c4e399c..387f1d0 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -614,14 +614,13 @@ int ext4fs_init(void)
 	/* populate fs */
 	fs->blksz = EXT2_BLOCK_SIZE(ext4fs_root);
 	fs->inodesz = INODE_SIZE_FILESYSTEM(ext4fs_root);
-	fs->sect_perblk = fs->blksz / SECTOR_SIZE;
+	fs->sect_perblk = fs->blksz >> fs->dev_desc->log2blksz;
 
 	/* get the superblock */
 	fs->sb = zalloc(SUPERBLOCK_SIZE);
 	if (!fs->sb)
 		return -ENOMEM;
-	if (!ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			(char *)fs->sb))
+	if (!ext4_read_superblock( (char *)fs->sb))
 		goto fail;
 
 	/* init journal */
@@ -722,7 +721,7 @@ void ext4fs_deinit(void)
 	ext4fs_free_journal();
 
 	/* get the superblock */
-	ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE, (char *)fs->sb);
+	ext4_read_superblock((char *)fs->sb);
 	fs->sb->feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER;
 	put_ext4((uint64_t)(SUPERBLOCK_SIZE),
 		 (struct ext2_sblock *)fs->sb, (uint32_t)SUPERBLOCK_SIZE);
@@ -766,7 +765,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 {
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
+	int log2blocksize = LOG2_BLOCK_SIZE(ext4fs_root) - fs->dev_desc->log2blksz;
 	unsigned int filesize = __le32_to_cpu(file_inode->size);
 	struct ext_filesystem *fs = get_fs();
 	int previous_block_number = -1;
@@ -795,10 +794,10 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> fs->dev_desc->log2blksz;
 				} else {	/* spill */
-					put_ext4((uint64_t) (delayed_start *
-							     SECTOR_SIZE),
+					put_ext4((uint64_t) (delayed_start <<
+							     fs->dev_desc->log2blksz),
 						 delayed_buf,
 						 (uint32_t) delayed_extent);
 					previous_block_number = blknr;
@@ -806,7 +805,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 					delayed_extent = blockend;
 					delayed_buf = buf;
 					delayed_next = blknr +
-					    (blockend >> SECTOR_BITS);
+					    (blockend >> fs->dev_desc->log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -814,13 +813,13 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 				delayed_extent = blockend;
 				delayed_buf = buf;
 				delayed_next = blknr +
-				    (blockend >> SECTOR_BITS);
+				    (blockend >> fs->dev_desc->log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
 				/* spill */
-				put_ext4((uint64_t) (delayed_start *
-						     SECTOR_SIZE), delayed_buf,
+				put_ext4((uint64_t) (delayed_start <<
+						     fs->dev_desc->log2blksz), delayed_buf,
 					 (uint32_t) delayed_extent);
 				previous_block_number = -1;
 			}
@@ -830,7 +829,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 	}
 	if (previous_block_number != -1) {
 		/* spill */
-		put_ext4((uint64_t) (delayed_start * SECTOR_SIZE),
+		put_ext4((uint64_t) (delayed_start << fs->dev_desc->log2blksz),
 			 delayed_buf, (uint32_t) delayed_extent);
 		previous_block_number = -1;
 	}
@@ -921,7 +920,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
 	/* Allocate data blocks */
 	ext4fs_allocate_blocks(file_inode, blocks_remaining,
 			       &blks_reqd_for_file);
-	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) / SECTOR_SIZE;
+	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) >> fs->dev_desc->log2blksz;
 
 	temp_ptr = zalloc(fs->blksz);
 	if (!temp_ptr)
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 4dddde2..72dad16 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -60,10 +60,11 @@ void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot)
 int ext4fs_read_file(struct ext2fs_node *node, int pos,
 		unsigned int len, char *buf)
 {
+	struct ext_filesystem *fs = get_fs();
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(node->data);
-	int blocksize = 1 << (log2blocksize + DISK_SECTOR_BITS);
+	int log2blocksize = LOG2_BLOCK_SIZE(node->data) - fs->dev_desc->log2blksz;
+	int blocksize = (1 << (log2blocksize + fs->dev_desc->log2blksz));
 	unsigned int filesize = __le32_to_cpu(node->inode.size);
 	int previous_block_number = -1;
 	int delayed_start = 0;
@@ -110,7 +111,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> fs->dev_desc->log2blksz;
 				} else {	/* spill */
 					status = ext4fs_devread(delayed_start,
 							delayed_skipfirst,
@@ -124,7 +125,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 					delayed_skipfirst = skipfirst;
 					delayed_buf = buf;
 					delayed_next = blknr +
-						(blockend >> SECTOR_BITS);
+						(blockend >> fs->dev_desc->log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -133,7 +134,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 				delayed_skipfirst = skipfirst;
 				delayed_buf = buf;
 				delayed_next = blknr +
-					(blockend >> SECTOR_BITS);
+					(blockend >> fs->dev_desc->log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
diff --git a/include/ext4fs.h b/include/ext4fs.h
index 025a2e8..379f7eb 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -141,4 +141,5 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock);
 int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
 		 disk_partition_t *fs_partition);
 int ext4_read_file(const char *filename, void *buf, int offset, int len);
+int ext4_read_superblock(char *buffer);
 #endif
diff --git a/include/ext_common.h b/include/ext_common.h
index 86373a6..1259a20 100644
--- a/include/ext_common.h
+++ b/include/ext_common.h
@@ -34,7 +34,6 @@
 #define __EXT_COMMON__
 #include <command.h>
 #define SECTOR_SIZE		0x200
-#define SECTOR_BITS		9
 
 /* Magic value used to identify an ext2 filesystem.  */
 #define	EXT2_MAGIC			0xEF53
@@ -58,18 +57,12 @@
 #define FILETYPE_INO_SYMLINK		0120000
 #define EXT2_ROOT_INO			2 /* Root inode */
 
-/* Bits used as offset in sector */
-#define DISK_SECTOR_BITS		9
 /* The size of an ext2 block in bytes.  */
 #define EXT2_BLOCK_SIZE(data)	   (1 << LOG2_BLOCK_SIZE(data))
 
-/* 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)
+				    (data->sblock.log2_block_size) + EXT2_MIN_BLOCK_LOG_SIZE)
 #define INODE_SIZE_FILESYSTEM(data)	(__le32_to_cpu \
 			(data->sblock.inode_size))
 
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize != 512.
  2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
@ 2013-03-26 11:30   ` Wolfgang Denk
  2013-03-26 12:03     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
  2013-04-09 16:03   ` [U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize " Egbert Eich
  1 sibling, 1 reply; 17+ messages in thread
From: Wolfgang Denk @ 2013-03-26 11:30 UTC (permalink / raw)
  To: u-boot

Dear egbert.eich at googlemail.com,

In message <1364285735-2364-2-git-send-email-egbert.eich@gmail.com> you wrote:
> From: Egbert Eich <eich@suse.com>
> 
> Disks beyond 2T in size use blocksizes of 4096 bytes. However a lot of
> code in u-boot  still assumes a 512 byte blocksize.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>
> ---
>  disk/part_efi.c    |   32 ++++++++++++++++----------------
>  include/common.h   |   10 ++++++++--
>  include/part.h     |    3 +++
>  include/part_efi.h |    2 --
>  4 files changed, 27 insertions(+), 20 deletions(-)

WARNING: line over 80 characters
#192: FILE: disk/part_efi.c:463:
+	gpt_header *gpt_h = calloc(1, PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc));

WARNING: line over 80 characters
#199: FILE: disk/part_efi.c:469:
+	gpt_entry *gpt_e = calloc(1, PAD_TO_BLOCKSIZE(GPT_ENTRY_NUMBERS * sizeof(gpt_entry), dev_desc));

WARNING: line over 80 characters
#217: FILE: disk/part_efi.c:670:
+		pte = memalign(ARCH_DMA_MINALIGN, PAD_TO_BLOCKSIZE(count,dev_desc));

ERROR: space required after that ',' (ctx:VxV)
#217: FILE: disk/part_efi.c:670:
+		pte = memalign(ARCH_DMA_MINALIGN, PAD_TO_BLOCKSIZE(count,dev_desc));
 		                                                        ^

WARNING: line over 80 characters
#248: FILE: include/common.h:996:
+	char __##name[ROUND(PAD_SIZE(size * sizeof(type),pad), align) + (align - 1)]; \

ERROR: space required after that ',' (ctx:VxV)
#248: FILE: include/common.h:996:
+	char __##name[ROUND(PAD_SIZE(size * sizeof(type),pad), align) + (align - 1)]; \
 	                                                ^

WARNING: line over 80 characters
#267: FILE: include/part.h:59:
+#define PAD_TO_BLOCKSIZE(size, block_dev_desc) (PAD_SIZE(size, block_dev_desc->blksz))

total: 2 errors, 5 warnings, 146 lines checked

/home/wd/Mail/U-Boot/7149 has style problems, please review.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I wish Captain Vimes were here. He wouldn't have  known  what  to  do
either, but he's got a much better vocabulary to be baffled in.
                                 - Terry Pratchett, _Guards! Guards!_

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.
  2013-03-26  8:15 ` [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct egbert.eich at googlemail.com
@ 2013-03-26 11:31   ` Wolfgang Denk
  2013-03-26 12:05     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
  0 siblings, 1 reply; 17+ messages in thread
From: Wolfgang Denk @ 2013-03-26 11:31 UTC (permalink / raw)
  To: u-boot

Dear egbert.eich at googlemail.com,

In message <1364285735-2364-5-git-send-email-egbert.eich@gmail.com> you wrote:
> From: Egbert Eich <eich@suse.com>
> 
> This value serves as the shift value used to calculate the block number
> to read in file systems when implementing aviable block sizes.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>
> ---
>  common/cmd_ide.c          |    4 ++++
>  common/cmd_sata.c         |    1 +
>  common/cmd_scsi.c         |    2 ++
>  common/usb_storage.c      |    1 +
>  drivers/block/ata_piix.c  |    1 +
>  drivers/block/pata_bfin.c |    1 +
>  drivers/block/systemace.c |    1 +
>  drivers/mmc/mmc.c         |    1 +
>  include/part.h            |    5 +++++
>  9 files changed, 17 insertions(+), 0 deletions(-)


WARNING: line over 80 characters
#127: FILE: common/cmd_ide.c:458:
+		ide_dev_desc[i].log2blksz = LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz)); /* just init to an invalid value */

WARNING: line over 80 characters
#143: FILE: common/cmd_ide.c:1453:
+	dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz)); /* just init to an invalid value */

WARNING: line over 80 characters
#175: FILE: common/cmd_scsi.c:109:
+		scsi_dev_desc[i].log2blksz = LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz)); /* just init to an invalid value */

WARNING: line over 80 characters
#183: FILE: common/cmd_scsi.c:170:
+			scsi_dev_desc[scsi_max_devs].log2blksz = LOG2(scsi_dev_desc[scsi_max_devs].blksz);

WARNING: line over 80 characters
#219: FILE: drivers/block/pata_bfin.c:900:
+	sata_dev_desc[ap->port_no].log2blksz = LOG2(sata_dev_desc[ap->port_no].blksz);

total: 0 errors, 5 warnings, 101 lines checked

/home/wd/Mail/U-Boot/7152 has style problems, please review.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"It follows that any commander in chief who undertakes to carry out a
plan which he considers defective is at fault; he must put forth  his
reasons,  insist  of  the  plan being changed, and finally tender his
resignation rather than be the instrument of his army's downfall."
- Napoleon, "Military Maxims and Thought"

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes.
  2013-03-26  8:15 ` [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes egbert.eich at googlemail.com
@ 2013-03-26 11:32   ` Wolfgang Denk
  2013-03-26 12:05     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
  0 siblings, 1 reply; 17+ messages in thread
From: Wolfgang Denk @ 2013-03-26 11:32 UTC (permalink / raw)
  To: u-boot

Dear egbert.eich at googlemail.com,

In message <1364285735-2364-6-git-send-email-egbert.eich@gmail.com> you wrote:
> From: Egbert Eich <eich@suse.com>
> 
> The 512 byte block size was hard coded in the ext4 file systems. Large
> harddisks today support bigger block sizes typically 4096 bytes.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>
> ---
>  fs/ext4/dev.c          |   52 +++++++++++++++++++++++++++++------------------
>  fs/ext4/ext4_common.c  |   26 +++++++++++------------
>  fs/ext4/ext4_common.h  |    2 +-
>  fs/ext4/ext4_journal.c |    6 +---
>  fs/ext4/ext4_write.c   |   27 ++++++++++++------------
>  fs/ext4/ext4fs.c       |   11 +++++----
>  include/ext4fs.h       |    1 +
>  include/ext_common.h   |    9 +-------
>  8 files changed, 68 insertions(+), 66 deletions(-)


WARNING: line over 80 characters
#139: FILE: fs/ext4/dev.c:56:
+	get_fs()->total_sect = (info->size * info->blksz) >> get_fs()->dev_desc->log2blksz;

WARNING: line over 80 characters
#148: FILE: fs/ext4/dev.c:64:
+				 (ext4fs_block_dev_desc ? ext4fs_block_dev_desc->blksz: 0));

ERROR: spaces required around that ':' (ctx:VxW)
#148: FILE: fs/ext4/dev.c:64:
+				 (ext4fs_block_dev_desc ? ext4fs_block_dev_desc->blksz: 0));
 				                                                      ^

WARNING: line over 80 characters
#157: FILE: fs/ext4/dev.c:72:
+	    || ((sector + ((byte_offset + byte_len - 1) >> ext4fs_block_dev_desc->log2blksz)) >=

WARNING: line over 80 characters
#186: FILE: fs/ext4/dev.c:94:
+			min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len));

WARNING: line over 80 characters
#187: FILE: fs/ext4/dev.c:95:
+		buf += min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len);

WARNING: line over 80 characters
#188: FILE: fs/ext4/dev.c:96:
+		byte_len -= min(ext4fs_block_dev_desc->blksz - byte_offset, byte_len);

WARNING: line over 80 characters
#213: FILE: fs/ext4/dev.c:119:
+					       block_len >> ext4fs_block_dev_desc->log2blksz,

WARNING: line over 80 characters
#216: FILE: fs/ext4/dev.c:121:
+					       block_len >> ext4fs_block_dev_desc->log2blksz) {

WARNING: line over 80 characters
#279: FILE: fs/ext4/ext4_common.c:106:
+						  size >> fs->dev_desc->log2blksz,

WARNING: line over 80 characters
#288: FILE: fs/ext4/ext4_common.c:1471:
+	return ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - get_fs()->dev_desc->log2blksz),

WARNING: line over 80 characters
#297: FILE: fs/ext4/ext4_common.c:1497:
+	status = ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - fs->dev_desc->log2blksz), blkoff,

WARNING: line over 80 characters
#306: FILE: fs/ext4/ext4_common.c:1517:
+	log2_blksz = LOG2_BLOCK_SIZE(ext4fs_root) - get_fs()->dev_desc->log2blksz;

ERROR: space prohibited after that open parenthesis '('
#388: FILE: fs/ext4/ext4_write.c:623:
+	if (!ext4_read_superblock( (char *)fs->sb))

WARNING: line over 80 characters
#406: FILE: fs/ext4/ext4_write.c:768:
+	int log2blocksize = LOG2_BLOCK_SIZE(ext4fs_root) - fs->dev_desc->log2blksz;

WARNING: line over 80 characters
#415: FILE: fs/ext4/ext4_write.c:797:
+					delayed_next += blockend >> fs->dev_desc->log2blksz;

WARNING: line over 80 characters
#420: FILE: fs/ext4/ext4_write.c:800:
+							     fs->dev_desc->log2blksz),

WARNING: line over 80 characters
#429: FILE: fs/ext4/ext4_write.c:808:
+					    (blockend >> fs->dev_desc->log2blksz);

WARNING: line over 80 characters
#446: FILE: fs/ext4/ext4_write.c:822:
+						     fs->dev_desc->log2blksz), delayed_buf,

WARNING: line over 80 characters
#464: FILE: fs/ext4/ext4_write.c:923:
+	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) >> fs->dev_desc->log2blksz;

WARNING: line over 80 characters
#481: FILE: fs/ext4/ext4fs.c:66:
+	int log2blocksize = LOG2_BLOCK_SIZE(node->data) - fs->dev_desc->log2blksz;

WARNING: line over 80 characters
#491: FILE: fs/ext4/ext4fs.c:114:
+					delayed_next += blockend >> fs->dev_desc->log2blksz;

WARNING: line over 80 characters
#500: FILE: fs/ext4/ext4fs.c:128:
+						(blockend >> fs->dev_desc->log2blksz);

WARNING: line over 80 characters
#551: FILE: include/ext_common.h:65:
+				    (data->sblock.log2_block_size) + EXT2_MIN_BLOCK_LOG_SIZE)

total: 2 errors, 22 warnings, 375 lines checked

/home/wd/Mail/U-Boot/7153 has style problems, please review.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Brain: an apparatus with which we think we think.    - Ambrose Bierce

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH v2] disk/gpt: Fix GPT Partition handling for Blocksize != 512.
  2013-03-26 11:30   ` Wolfgang Denk
@ 2013-03-26 12:03     ` egbert.eich at gmail.com
  0 siblings, 0 replies; 17+ messages in thread
From: egbert.eich at gmail.com @ 2013-03-26 12:03 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

Disks beyond 2T in size use blocksizes of 4096 bytes. However a lot of
code in u-boot  still assumes a 512 byte blocksize.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 disk/part_efi.c    |   38 ++++++++++++++++++++++----------------
 include/common.h   |   11 +++++++++--
 include/part.h     |    4 ++++
 include/part_efi.h |    2 --
 4 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index b3fd0e9..ba86aa5 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -114,7 +114,7 @@ static inline int is_bootable(gpt_entry *p)
 
 void print_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 	int i = 0;
 	char uuid[37];
@@ -161,7 +161,7 @@ void print_part_efi(block_dev_desc_t * dev_desc)
 int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 				disk_partition_t * info)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 
 	/* "part" argument must be at least 1 */
@@ -189,7 +189,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 	/* The ending LBA is inclusive, to calculate size, add 1 to it */
 	info->size = ((u64)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1)
 		     - info->start;
-	info->blksz = GPT_BLOCK_SIZE;
+	info->blksz = dev_desc->blksz;
 
 	sprintf((char *)info->name, "%s",
 			print_efiname(&gpt_pte[part - 1]));
@@ -209,7 +209,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
 int test_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, legacymbr, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
 
 	/* Read legacy MBR from block 0 and validate it */
 	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)legacymbr) != 1)
@@ -310,9 +310,8 @@ static int string_uuid(char *uuid, u8 *dst)
 int write_gpt_table(block_dev_desc_t *dev_desc,
 		gpt_header *gpt_h, gpt_entry *gpt_e)
 {
-	const int pte_blk_num = (gpt_h->num_partition_entries
-		* sizeof(gpt_entry)) / dev_desc->blksz;
-
+	const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries
+					   * sizeof(gpt_entry)), dev_desc);
 	u32 calc_crc32;
 	u64 val;
 
@@ -335,8 +334,8 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 	if (dev_desc->block_write(dev_desc->dev, 1, 1, gpt_h) != 1)
 		goto err;
 
-	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_num, gpt_e)
-	    != pte_blk_num)
+	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_cnt, gpt_e)
+	    != pte_blk_cnt)
 		goto err;
 
 	/* recalculate the values for the Second GPT Header */
@@ -351,7 +350,7 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 
 	if (dev_desc->block_write(dev_desc->dev,
 				  le32_to_cpu(gpt_h->last_usable_lba + 1),
-				  pte_blk_num, gpt_e) != pte_blk_num)
+				  pte_blk_cnt, gpt_e) != pte_blk_cnt)
 		goto err;
 
 	if (dev_desc->block_write(dev_desc->dev,
@@ -461,13 +460,18 @@ int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
 {
 	int ret;
 
-	gpt_header *gpt_h = calloc(1, sizeof(gpt_header));
+	gpt_header *gpt_h = calloc(1, PAD_TO_BLOCKSIZE(sizeof(gpt_header),
+						       dev_desc));
+	gpt_entry *gpt_e;
+
 	if (gpt_h == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		return -1;
 	}
 
-	gpt_entry *gpt_e = calloc(GPT_ENTRY_NUMBERS, sizeof(gpt_entry));
+	gpt_e = calloc(1, PAD_TO_BLOCKSIZE(GPT_ENTRY_NUMBERS
+					       * sizeof(gpt_entry),
+					       dev_desc));
 	if (gpt_e == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		free(gpt_h);
@@ -651,7 +655,7 @@ static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba,
 static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 					 gpt_header * pgpt_head)
 {
-	size_t count = 0;
+	size_t count = 0, blk_cnt;
 	gpt_entry *pte = NULL;
 
 	if (!dev_desc || !pgpt_head) {
@@ -668,7 +672,8 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
 	/* Allocate memory for PTE, remember to FREE */
 	if (count != 0) {
-		pte = memalign(ARCH_DMA_MINALIGN, count);
+		pte = memalign(ARCH_DMA_MINALIGN,
+			       PAD_TO_BLOCKSIZE(count, dev_desc));
 	}
 
 	if (count == 0 || pte == NULL) {
@@ -679,10 +684,11 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 	}
 
 	/* Read GPT Entries from device */
+	blk_cnt = BLOCK_CNT(count, dev_desc);
 	if (dev_desc->block_read (dev_desc->dev,
 		le64_to_cpu(pgpt_head->partition_entry_lba),
-		(lbaint_t) (count / GPT_BLOCK_SIZE), pte)
-		!= (count / GPT_BLOCK_SIZE)) {
+		(lbaint_t) (blk_cnt), pte)
+		!= blk_cnt) {
 
 		printf("*** ERROR: Can't read GPT Entries ***\n");
 		free(pte);
diff --git a/include/common.h b/include/common.h
index d41aeb4..53cc859 100644
--- a/include/common.h
+++ b/include/common.h
@@ -990,10 +990,17 @@ static inline void unmap_sysmem(const void *vaddr)
  * of a function scoped static buffer.  It can not be used to create a cache
  * line aligned global buffer.
  */
-#define ALLOC_ALIGN_BUFFER(type, name, size, align)			\
-	char __##name[ROUND(size * sizeof(type), align) + (align - 1)];	\
+#define PAD_COUNT(s, pad) ((s - 1) / pad + 1)
+#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
+#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
+	char __##name[ROUND(PAD_SIZE(size * sizeof(type), pad), align)  \
+		      + (align - 1)];					\
 									\
 	type *name = (type *) ALIGN((uintptr_t)__##name, align)
+#define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
+#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
 #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
 	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
diff --git a/include/part.h b/include/part.h
index c58a734..12e9b05 100644
--- a/include/part.h
+++ b/include/part.h
@@ -55,6 +55,10 @@ typedef struct block_dev_desc {
 	void		*priv;		/* driver private struct pointer */
 }block_dev_desc_t;
 
+#define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
+#define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
+	(PAD_SIZE(size, block_dev_desc->blksz))
+
 /* Interface types: */
 #define IF_TYPE_UNKNOWN		0
 #define IF_TYPE_IDE		1
diff --git a/include/part_efi.h b/include/part_efi.h
index 6de0a32..95e4c8f 100644
--- a/include/part_efi.h
+++ b/include/part_efi.h
@@ -38,7 +38,6 @@
 #define EFI_PMBR_OSTYPE_EFI 0xEF
 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
 
-#define GPT_BLOCK_SIZE 512
 #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
 #define GPT_HEADER_REVISION_V1 0x00010000
 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL
@@ -112,7 +111,6 @@ typedef struct _gpt_header {
 	__le32 num_partition_entries;
 	__le32 sizeof_partition_entry;
 	__le32 partition_entry_array_crc32;
-	u8 reserved2[GPT_BLOCK_SIZE - 92];
 } __packed gpt_header;
 
 typedef union _gpt_entry_attributes {
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH v2] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.
  2013-03-26 11:31   ` Wolfgang Denk
@ 2013-03-26 12:05     ` egbert.eich at gmail.com
  0 siblings, 0 replies; 17+ messages in thread
From: egbert.eich at gmail.com @ 2013-03-26 12:05 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

This value serves as the shift value used to calculate the block number
to read in file systems when implementing aviable block sizes.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 common/cmd_ide.c          |    5 +++++
 common/cmd_sata.c         |    1 +
 common/cmd_scsi.c         |    4 ++++
 common/usb_storage.c      |    1 +
 drivers/block/ata_piix.c  |    1 +
 drivers/block/pata_bfin.c |    2 ++
 drivers/block/systemace.c |    1 +
 drivers/mmc/mmc.c         |    1 +
 include/part.h            |    5 +++++
 9 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 0105bdb..78b4aa7 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -455,6 +455,8 @@ void ide_init(void)
 		ide_dev_desc[i].dev = i;
 		ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
 		ide_dev_desc[i].blksz = 0;
+		ide_dev_desc[i].log2blksz =
+			LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
 		ide_dev_desc[i].lba = 0;
 		ide_dev_desc[i].block_read = ide_read;
 		ide_dev_desc[i].block_write = ide_write;
@@ -806,6 +808,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 	/* assuming HD */
 	dev_desc->type = DEV_TYPE_HARDDISK;
 	dev_desc->blksz = ATA_BLOCKSIZE;
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 	dev_desc->lun = 0;	/* just to fill something in... */
 
 #if 0				/* only used to test the powersaving mode,
@@ -1448,6 +1451,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 	dev_desc->lun = 0;
 	dev_desc->lba = 0;
 	dev_desc->blksz = 0;
+	dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
 	dev_desc->type = iobuf[0] & 0x1f;
 
 	if ((iobuf[1] & 0x80) == 0x80)
@@ -1492,6 +1496,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 	dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
 		((unsigned long) iobuf[5] << 16) +
 		((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 #ifdef CONFIG_LBA48
 	/* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
 	dev_desc->lba48 = 0;
diff --git a/common/cmd_sata.c b/common/cmd_sata.c
index 8d57285..5a57a37 100644
--- a/common/cmd_sata.c
+++ b/common/cmd_sata.c
@@ -44,6 +44,7 @@ int __sata_initialize(void)
 		sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
 		sata_dev_desc[i].lba = 0;
 		sata_dev_desc[i].blksz = 512;
+		sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
 		sata_dev_desc[i].block_read = sata_read;
 		sata_dev_desc[i].block_write = sata_write;
 
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index 266bfa6..192a439 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -106,6 +106,8 @@ void scsi_scan(int mode)
 		scsi_dev_desc[i].lun=0xff;
 		scsi_dev_desc[i].lba=0;
 		scsi_dev_desc[i].blksz=0;
+		scsi_dev_desc[i].log2blksz =
+			LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz));
 		scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
 		scsi_dev_desc[i].vendor[0]=0;
 		scsi_dev_desc[i].product[0]=0;
@@ -166,6 +168,8 @@ void scsi_scan(int mode)
 			}
 			scsi_dev_desc[scsi_max_devs].lba=capacity;
 			scsi_dev_desc[scsi_max_devs].blksz=blksz;
+			scsi_dev_desc[scsi_max_devs].log2blksz =
+				LOG2(scsi_dev_desc[scsi_max_devs].blksz);
 			scsi_dev_desc[scsi_max_devs].type=perq;
 			init_part(&scsi_dev_desc[scsi_max_devs]);
 removable:
diff --git a/common/usb_storage.c b/common/usb_storage.c
index fb322b4..c5db044 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -1430,6 +1430,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
 			*capacity, *blksz);
 	dev_desc->lba = *capacity;
 	dev_desc->blksz = *blksz;
+	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 	dev_desc->type = perq;
 	USB_STOR_PRINTF(" address %d\n", dev_desc->target);
 	USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type);
diff --git a/drivers/block/ata_piix.c b/drivers/block/ata_piix.c
index 1e33a66..fcae448 100644
--- a/drivers/block/ata_piix.c
+++ b/drivers/block/ata_piix.c
@@ -406,6 +406,7 @@ void sata_identify(int num, int dev)
 	/* assuming HD */
 	sata_dev_desc[devno].type = DEV_TYPE_HARDDISK;
 	sata_dev_desc[devno].blksz = ATA_BLOCKSIZE;
+	sata_dev_desc[devno].log2blksz = LOG2(sata_dev_desc[devno].blksz);
 	sata_dev_desc[devno].lun = 0;	/* just to fill something in... */
 }
 
diff --git a/drivers/block/pata_bfin.c b/drivers/block/pata_bfin.c
index b847dd9..27ecaf4 100644
--- a/drivers/block/pata_bfin.c
+++ b/drivers/block/pata_bfin.c
@@ -897,6 +897,8 @@ static void bfin_ata_identify(struct ata_port *ap, int dev)
 	/* assuming HD */
 	sata_dev_desc[ap->port_no].type = DEV_TYPE_HARDDISK;
 	sata_dev_desc[ap->port_no].blksz = ATA_SECT_SIZE;
+	sata_dev_desc[ap->port_no].log2blksz =
+		LOG2(sata_dev_desc[ap->port_no].blksz);
 	sata_dev_desc[ap->port_no].lun = 0;	/* just to fill something in... */
 
 	printf("PATA device#%d %s is found on ata port#%d.\n",
diff --git a/drivers/block/systemace.c b/drivers/block/systemace.c
index bf29cbb..b08715f 100644
--- a/drivers/block/systemace.c
+++ b/drivers/block/systemace.c
@@ -127,6 +127,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
 		systemace_dev.part_type = PART_TYPE_UNKNOWN;
 		systemace_dev.type = DEV_TYPE_HARDDISK;
 		systemace_dev.blksz = 512;
+		systemace_dev.log2blksz = LOG2(systemace_dev.blksz);
 		systemace_dev.removable = 1;
 		systemace_dev.block_read = systemace_read;
 
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 7b5fdd9..7db633c 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1174,6 +1174,7 @@ static int mmc_startup(struct mmc *mmc)
 	mmc->block_dev.lun = 0;
 	mmc->block_dev.type = 0;
 	mmc->block_dev.blksz = mmc->read_bl_len;
+	mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz);
 	mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
 	sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x",
 		mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff),
diff --git a/include/part.h b/include/part.h
index 12e9b05..f7c7cc5 100644
--- a/include/part.h
+++ b/include/part.h
@@ -38,6 +38,7 @@ typedef struct block_dev_desc {
 #endif
 	lbaint_t	lba;		/* number of blocks */
 	unsigned long	blksz;		/* block size */
+	int		log2blksz;	/* for convenience: log2(blksz) */
 	char		vendor [40+1];	/* IDE model, SCSI Vendor */
 	char		product[20+1];	/* IDE Serial no, SCSI product */
 	char		revision[8+1];	/* firmware revision */
@@ -58,6 +59,10 @@ typedef struct block_dev_desc {
 #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
 #define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
 	(PAD_SIZE(size, block_dev_desc->blksz))
+#define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
+		 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
+		 ((x & 0xffff0000) ? 16 : 0))
+#define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
 
 /* Interface types: */
 #define IF_TYPE_UNKNOWN		0
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH v2] fs/ext4: Support device block sizes != 512 bytes.
  2013-03-26 11:32   ` Wolfgang Denk
@ 2013-03-26 12:05     ` egbert.eich at gmail.com
  2013-04-30 19:11       ` Tom Rini
  0 siblings, 1 reply; 17+ messages in thread
From: egbert.eich at gmail.com @ 2013-03-26 12:05 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

The 512 byte block size was hard coded in the ext4 file systems. Large
harddisks today support bigger block sizes typically 4096 bytes.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 fs/ext4/dev.c          |   60 +++++++++++++++++++++++++++++++----------------
 fs/ext4/ext4_common.c  |   42 ++++++++++++++++++---------------
 fs/ext4/ext4_common.h  |    2 +-
 fs/ext4/ext4_journal.c |    6 +---
 fs/ext4/ext4_write.c   |   32 +++++++++++++------------
 fs/ext4/ext4fs.c       |   14 ++++++----
 include/ext4fs.h       |    1 +
 include/ext_common.h   |   12 ++-------
 8 files changed, 94 insertions(+), 75 deletions(-)

diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
index 464a67d..7b6fd16 100644
--- a/fs/ext4/dev.c
+++ b/fs/ext4/dev.c
@@ -40,6 +40,7 @@
 #include <config.h>
 #include <ext4fs.h>
 #include <ext_common.h>
+#include "ext4_common.h"
 
 unsigned long part_offset;
 
@@ -48,37 +49,41 @@ static disk_partition_t *part_info;
 
 void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
 {
+	assert(rbdd->blksz == (1 << rbdd->log2blksz));
 	ext4fs_block_dev_desc = rbdd;
 	part_info = info;
 	part_offset = info->start;
-	get_fs()->total_sect = (info->size * info->blksz) / SECTOR_SIZE;
+	get_fs()->total_sect = (info->size * info->blksz) >>
+		get_fs()->dev_desc->log2blksz;
 	get_fs()->dev_desc = rbdd;
 }
 
 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, SECTOR_SIZE);
 	unsigned block_len;
+	int log2blksz = ext4fs_block_dev_desc->log2blksz;
+	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (ext4fs_block_dev_desc ?
+						 ext4fs_block_dev_desc->blksz :
+						 0));
+	if (ext4fs_block_dev_desc == NULL) {
+		printf("** Invalid Block Device Descriptor (NULL)\n");
+		return 0;
+	}
 
 	/* Check partition boundaries */
 	if ((sector < 0)
-	    || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
-		part_info->size)) {
+	    || ((sector + ((byte_offset + byte_len - 1) >> log2blksz))
+		>= 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;
+	sector += byte_offset >> log2blksz;
+	byte_offset &= ext4fs_block_dev_desc->blksz - 1;
 
 	debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
 
-	if (ext4fs_block_dev_desc == NULL) {
-		printf("** Invalid Block Device Descriptor (NULL)\n");
-		return 0;
-	}
-
 	if (byte_offset != 0) {
 		/* read first part which isn't aligned with start of sector */
 		if (ext4fs_block_dev_desc->
@@ -89,9 +94,12 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 			return 0;
 		}
 		memcpy(buf, sec_buf + byte_offset,
-			min(SECTOR_SIZE - byte_offset, byte_len));
-		buf += min(SECTOR_SIZE - byte_offset, byte_len);
-		byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
+			min(ext4fs_block_dev_desc->blksz
+			    - byte_offset, byte_len));
+		buf += min(ext4fs_block_dev_desc->blksz
+			   - byte_offset, byte_len);
+		byte_len -= min(ext4fs_block_dev_desc->blksz
+				- byte_offset, byte_len);
 		sector++;
 	}
 
@@ -99,12 +107,12 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 		return 1;
 
 	/* read sector aligned part */
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 
 	if (block_len == 0) {
-		ALLOC_CACHE_ALIGN_BUFFER(u8, p, SECTOR_SIZE);
+		ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_block_dev_desc->blksz);
 
-		block_len = SECTOR_SIZE;
+		block_len = ext4fs_block_dev_desc->blksz;
 		ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 						  part_info->start + sector,
 						  1, (unsigned long *)p);
@@ -114,16 +122,16 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 
 	if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 					       part_info->start + sector,
-					       block_len / SECTOR_SIZE,
+					       block_len >> log2blksz,
 					       (unsigned long *) buf) !=
-					       block_len / SECTOR_SIZE) {
+					       block_len >> log2blksz) {
 		printf(" ** %s read error - block\n", __func__);
 		return 0;
 	}
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 	buf += block_len;
 	byte_len -= block_len;
-	sector += block_len / SECTOR_SIZE;
+	sector += block_len / ext4fs_block_dev_desc->blksz;
 
 	if (byte_len != 0) {
 		/* read rest of data which are not in whole sector */
@@ -138,3 +146,13 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 	}
 	return 1;
 }
+
+int ext4_read_superblock(char *buffer)
+{
+	struct ext_filesystem *fs = get_fs();
+	int sect = SUPERBLOCK_START >> fs->dev_desc->log2blksz;
+	int off = SUPERBLOCK_START % fs->dev_desc->blksz;
+
+	return ext4fs_devread(sect, off, SUPERBLOCK_SIZE,
+				buffer);
+}
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index f12b805..38c9603 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -71,18 +71,18 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 	uint64_t startblock;
 	uint64_t remainder;
 	unsigned char *temp_ptr = NULL;
-	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, SECTOR_SIZE);
 	struct ext_filesystem *fs = get_fs();
+	int log2blksz = fs->dev_desc->log2blks;
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, fs->dev_desc->blksz);
 
-	startblock = off / (uint64_t)SECTOR_SIZE;
+	startblock = off >> log2blksz;
 	startblock += part_offset;
-	remainder = off % (uint64_t)SECTOR_SIZE;
-	remainder &= SECTOR_SIZE - 1;
+	remainder = off & (uint64_t)(fs->dev_desc->blksz - 1);
 
 	if (fs->dev_desc == NULL)
 		return;
 
-	if ((startblock + (size / SECTOR_SIZE)) >
+	if ((startblock + (size >> log2blksz)) >
 	    (part_offset + fs->total_sect)) {
 		printf("part_offset is %lu\n", part_offset);
 		printf("total_sector is %llu\n", fs->total_sect);
@@ -101,10 +101,10 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 						  startblock, 1, sec_buf);
 		}
 	} else {
-		if (size / SECTOR_SIZE != 0) {
+		if (size >> log2blksz != 0) {
 			fs->dev_desc->block_write(fs->dev_desc->dev,
 						  startblock,
-						  size / SECTOR_SIZE,
+						  size >> log2blksz,
 						  (unsigned long *)buf);
 		} else {
 			fs->dev_desc->block_read(fs->dev_desc->dev,
@@ -1459,6 +1459,7 @@ static int ext4fs_blockgroup
 {
 	long int blkno;
 	unsigned int blkoff, desc_per_blk;
+	int log2blksz = get_fs()->dev_desc->log2blksz;
 
 	desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
 
@@ -1469,7 +1470,7 @@ static int ext4fs_blockgroup
 	debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n",
 	      group, blkno, blkoff);
 
-	return ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data),
+	return ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz),
 			      blkoff, sizeof(struct ext2_block_group),
 			      (char *)blkgrp);
 }
@@ -1479,6 +1480,7 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
 	struct ext2_block_group blkgrp;
 	struct ext2_sblock *sblock = &data->sblock;
 	struct ext_filesystem *fs = get_fs();
+	int log2blksz = get_fs()->dev_desc->log2blksz;
 	int inodes_per_block, status;
 	long int blkno;
 	unsigned int blkoff;
@@ -1495,7 +1497,8 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
 	    (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
 	blkoff = (ino % inodes_per_block) * fs->inodesz;
 	/* Read the inode. */
-	status = ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data), blkoff,
+	status = ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz),
+				blkoff,
 				sizeof(struct ext2_inode), (char *)inode);
 	if (status == 0)
 		return 0;
@@ -1515,7 +1518,9 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 	unsigned long long start;
 	/* get the blocksize of the filesystem */
 	blksz = EXT2_BLOCK_SIZE(ext4fs_root);
-	log2_blksz = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
+	log2_blksz = LOG2_BLOCK_SIZE(ext4fs_root)
+		- get_fs()->dev_desc->log2blksz;
+
 	if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) {
 		char *buf = zalloc(blksz);
 		if (!buf)
@@ -1523,11 +1528,11 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 		struct ext4_extent_header *ext_block;
 		struct ext4_extent *extent;
 		int i = -1;
-		ext_block = ext4fs_get_extent_block(ext4fs_root, buf,
-						    (struct ext4_extent_header
-						     *)inode->b.
-						    blocks.dir_blocks,
-						    fileblock, log2_blksz);
+		ext_block =
+			ext4fs_get_extent_block(ext4fs_root, buf,
+						(struct ext4_extent_header *)
+						inode->b.blocks.dir_blocks,
+						fileblock, log2_blksz);
 		if (!ext_block) {
 			printf("invalid extent block\n");
 			free(buf);
@@ -1839,7 +1844,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 		blknr = __le32_to_cpu(ext4fs_indir3_block
 				      [rblock % perblock_child]);
 	}
-	debug("ext4fs_read_block %ld\n", blknr);
+	debug("read_allocated_block %ld\n", blknr);
 
 	return blknr;
 }
@@ -2193,13 +2198,12 @@ int ext4fs_mount(unsigned part_length)
 	struct ext2_data *data;
 	int status;
 	struct ext_filesystem *fs = get_fs();
-	data = zalloc(sizeof(struct ext2_data));
+	data = zalloc(SUPERBLOCK_SIZE);
 	if (!data)
 		return 0;
 
 	/* Read the superblock. */
-	status = ext4fs_devread(1 * 2, 0, sizeof(struct ext2_sblock),
-				(char *)&data->sblock);
+	status = ext4_read_superblock((char *)&data->sblock);
 
 	if (status == 0)
 		goto fail;
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 87cab16..5fc0ce9 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -51,7 +51,7 @@
 
 #define S_IFLNK		0120000		/* symbolic link */
 #define BLOCK_NO_ONE		1
-#define SUPERBLOCK_SECTOR	2
+#define SUPERBLOCK_START	(2 * 512)
 #define SUPERBLOCK_SIZE	1024
 #define F_FILE			1
 
diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c
index 9f01708..4a84384 100644
--- a/fs/ext4/ext4_journal.c
+++ b/fs/ext4/ext4_journal.c
@@ -534,16 +534,14 @@ end:
 		jsb->s_start = cpu_to_be32(1);
 		jsb->s_sequence = cpu_to_be32(be32_to_cpu(jsb->s_sequence) + 1);
 		/* get the superblock */
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 		fs->sb->feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER;
 
 		/* Update the super block */
 		put_ext4((uint64_t) (SUPERBLOCK_SIZE),
 			 (struct ext2_sblock *)fs->sb,
 			 (uint32_t) SUPERBLOCK_SIZE);
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 
 		blknr = read_allocated_block(&inode_journal,
 					 EXT2_JOURNAL_SUPERBLOCK);
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index c4e399c..f76a464 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -614,14 +614,13 @@ int ext4fs_init(void)
 	/* populate fs */
 	fs->blksz = EXT2_BLOCK_SIZE(ext4fs_root);
 	fs->inodesz = INODE_SIZE_FILESYSTEM(ext4fs_root);
-	fs->sect_perblk = fs->blksz / SECTOR_SIZE;
+	fs->sect_perblk = fs->blksz >> fs->dev_desc->log2blksz;
 
 	/* get the superblock */
 	fs->sb = zalloc(SUPERBLOCK_SIZE);
 	if (!fs->sb)
 		return -ENOMEM;
-	if (!ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			(char *)fs->sb))
+	if (!ext4_read_superblock((char *)fs->sb))
 		goto fail;
 
 	/* init journal */
@@ -722,7 +721,7 @@ void ext4fs_deinit(void)
 	ext4fs_free_journal();
 
 	/* get the superblock */
-	ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE, (char *)fs->sb);
+	ext4_read_superblock((char *)fs->sb);
 	fs->sb->feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER;
 	put_ext4((uint64_t)(SUPERBLOCK_SIZE),
 		 (struct ext2_sblock *)fs->sb, (uint32_t)SUPERBLOCK_SIZE);
@@ -766,7 +765,8 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 {
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
+	int log2blksz = fs->dev_desc->log2blksz;
+	int log2_fs_blocksize = LOG2_BLOCK_SIZE(ext4fs_root) - log2blksz;
 	unsigned int filesize = __le32_to_cpu(file_inode->size);
 	struct ext_filesystem *fs = get_fs();
 	int previous_block_number = -1;
@@ -789,16 +789,16 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 		if (blknr < 0)
 			return -1;
 
-		blknr = blknr << log2blocksize;
+		blknr = blknr << log2_fs_blocksize;
 
 		if (blknr) {
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> log2blksz;
 				} else {	/* spill */
-					put_ext4((uint64_t) (delayed_start *
-							     SECTOR_SIZE),
+					put_ext4((uint64_t)
+						 (delayed_start << log2blksz),
 						 delayed_buf,
 						 (uint32_t) delayed_extent);
 					previous_block_number = blknr;
@@ -806,7 +806,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 					delayed_extent = blockend;
 					delayed_buf = buf;
 					delayed_next = blknr +
-					    (blockend >> SECTOR_BITS);
+					    (blockend >> log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -814,13 +814,14 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 				delayed_extent = blockend;
 				delayed_buf = buf;
 				delayed_next = blknr +
-				    (blockend >> SECTOR_BITS);
+				    (blockend >> log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
 				/* spill */
-				put_ext4((uint64_t) (delayed_start *
-						     SECTOR_SIZE), delayed_buf,
+				put_ext4((uint64_t) (delayed_start <<
+						     log2blksz),
+					 delayed_buf,
 					 (uint32_t) delayed_extent);
 				previous_block_number = -1;
 			}
@@ -830,7 +831,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 	}
 	if (previous_block_number != -1) {
 		/* spill */
-		put_ext4((uint64_t) (delayed_start * SECTOR_SIZE),
+		put_ext4((uint64_t) (delayed_start << log2blksz),
 			 delayed_buf, (uint32_t) delayed_extent);
 		previous_block_number = -1;
 	}
@@ -921,7 +922,8 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
 	/* Allocate data blocks */
 	ext4fs_allocate_blocks(file_inode, blocks_remaining,
 			       &blks_reqd_for_file);
-	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) / SECTOR_SIZE;
+	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) >>
+		fs->dev_desc->log2blksz;
 
 	temp_ptr = zalloc(fs->blksz);
 	if (!temp_ptr)
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 4dddde2..1954afb 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -60,10 +60,12 @@ void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot)
 int ext4fs_read_file(struct ext2fs_node *node, int pos,
 		unsigned int len, char *buf)
 {
+	struct ext_filesystem *fs = get_fs();
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(node->data);
-	int blocksize = 1 << (log2blocksize + DISK_SECTOR_BITS);
+	int log2blksz = fs->dev_desc->log2blksz;
+	int log2_fs_blocksize = LOG2_BLOCK_SIZE(node->data) - log2blksz;
+	int blocksize = (1 << (log2_fs_blocksize + log2blksz));
 	unsigned int filesize = __le32_to_cpu(node->inode.size);
 	int previous_block_number = -1;
 	int delayed_start = 0;
@@ -88,7 +90,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 		if (blknr < 0)
 			return -1;
 
-		blknr = blknr << log2blocksize;
+		blknr = blknr << log2_fs_blocksize;
 
 		/* Last block.  */
 		if (i == blockcnt - 1) {
@@ -110,7 +112,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> log2blksz;
 				} else {	/* spill */
 					status = ext4fs_devread(delayed_start,
 							delayed_skipfirst,
@@ -124,7 +126,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 					delayed_skipfirst = skipfirst;
 					delayed_buf = buf;
 					delayed_next = blknr +
-						(blockend >> SECTOR_BITS);
+						(blockend >> log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -133,7 +135,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 				delayed_skipfirst = skipfirst;
 				delayed_buf = buf;
 				delayed_next = blknr +
-					(blockend >> SECTOR_BITS);
+					(blockend >> log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
diff --git a/include/ext4fs.h b/include/ext4fs.h
index 025a2e8..379f7eb 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -141,4 +141,5 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock);
 int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
 		 disk_partition_t *fs_partition);
 int ext4_read_file(const char *filename, void *buf, int offset, int len);
+int ext4_read_superblock(char *buffer);
 #endif
diff --git a/include/ext_common.h b/include/ext_common.h
index 86373a6..78a7808 100644
--- a/include/ext_common.h
+++ b/include/ext_common.h
@@ -34,7 +34,6 @@
 #define __EXT_COMMON__
 #include <command.h>
 #define SECTOR_SIZE		0x200
-#define SECTOR_BITS		9
 
 /* Magic value used to identify an ext2 filesystem.  */
 #define	EXT2_MAGIC			0xEF53
@@ -58,18 +57,13 @@
 #define FILETYPE_INO_SYMLINK		0120000
 #define EXT2_ROOT_INO			2 /* Root inode */
 
-/* Bits used as offset in sector */
-#define DISK_SECTOR_BITS		9
 /* The size of an ext2 block in bytes.  */
 #define EXT2_BLOCK_SIZE(data)	   (1 << LOG2_BLOCK_SIZE(data))
 
-/* 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)
+#define LOG2_BLOCK_SIZE(data)	   (__le32_to_cpu		   \
+				    (data->sblock.log2_block_size) \
+				    + EXT2_MIN_BLOCK_LOG_SIZE)
 #define INODE_SIZE_FILESYSTEM(data)	(__le32_to_cpu \
 			(data->sblock.inode_size))
 
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize != 512
  2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
  2013-03-26 11:30   ` Wolfgang Denk
@ 2013-04-09 16:03   ` Egbert Eich
  2013-05-02 16:07     ` [U-Boot] [U-Boot, " Tom Rini
  1 sibling, 1 reply; 17+ messages in thread
From: Egbert Eich @ 2013-04-09 16:03 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

Disks beyond 2T in size use blocksizes of 4096 bytes. However a lot of
code in u-boot  still assumes a 512 byte blocksize.
This patch fixes the handling of GPTs.

Signed-off-by: Egbert Eich <eich@suse.com>
---
Changes for v2:
  - Coding style fixes.

 disk/part_efi.c    | 38 ++++++++++++++++++++++----------------
 include/common.h   | 11 +++++++++--
 include/part.h     |  4 ++++
 include/part_efi.h |  2 --
 4 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index e9987f0..5986589 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -115,7 +115,7 @@ static inline int is_bootable(gpt_entry *p)
 
 void print_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 	int i = 0;
 	char uuid[37];
@@ -162,7 +162,7 @@ void print_part_efi(block_dev_desc_t * dev_desc)
 int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 				disk_partition_t * info)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
 	gpt_entry *gpt_pte = NULL;
 
 	/* "part" argument must be at least 1 */
@@ -190,7 +190,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 	/* The ending LBA is inclusive, to calculate size, add 1 to it */
 	info->size = ((u64)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1)
 		     - info->start;
-	info->blksz = GPT_BLOCK_SIZE;
+	info->blksz = dev_desc->blksz;
 
 	sprintf((char *)info->name, "%s",
 			print_efiname(&gpt_pte[part - 1]));
@@ -210,7 +210,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
 int test_part_efi(block_dev_desc_t * dev_desc)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, legacymbr, 1);
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
 
 	/* Read legacy MBR from block 0 and validate it */
 	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)legacymbr) != 1)
@@ -311,9 +311,8 @@ static int string_uuid(char *uuid, u8 *dst)
 int write_gpt_table(block_dev_desc_t *dev_desc,
 		gpt_header *gpt_h, gpt_entry *gpt_e)
 {
-	const int pte_blk_num = (gpt_h->num_partition_entries
-		* sizeof(gpt_entry)) / dev_desc->blksz;
-
+	const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries
+					   * sizeof(gpt_entry)), dev_desc);
 	u32 calc_crc32;
 	u64 val;
 
@@ -336,8 +335,8 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 	if (dev_desc->block_write(dev_desc->dev, 1, 1, gpt_h) != 1)
 		goto err;
 
-	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_num, gpt_e)
-	    != pte_blk_num)
+	if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_cnt, gpt_e)
+	    != pte_blk_cnt)
 		goto err;
 
 	/* recalculate the values for the Second GPT Header */
@@ -352,7 +351,7 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
 
 	if (dev_desc->block_write(dev_desc->dev,
 				  le32_to_cpu(gpt_h->last_usable_lba + 1),
-				  pte_blk_num, gpt_e) != pte_blk_num)
+				  pte_blk_cnt, gpt_e) != pte_blk_cnt)
 		goto err;
 
 	if (dev_desc->block_write(dev_desc->dev,
@@ -462,13 +461,18 @@ int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
 {
 	int ret;
 
-	gpt_header *gpt_h = calloc(1, sizeof(gpt_header));
+	gpt_header *gpt_h = calloc(1, PAD_TO_BLOCKSIZE(sizeof(gpt_header),
+						       dev_desc));
+	gpt_entry *gpt_e;
+
 	if (gpt_h == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		return -1;
 	}
 
-	gpt_entry *gpt_e = calloc(GPT_ENTRY_NUMBERS, sizeof(gpt_entry));
+	gpt_e = calloc(1, PAD_TO_BLOCKSIZE(GPT_ENTRY_NUMBERS
+					       * sizeof(gpt_entry),
+					       dev_desc));
 	if (gpt_e == NULL) {
 		printf("%s: calloc failed!\n", __func__);
 		free(gpt_h);
@@ -652,7 +656,7 @@ static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba,
 static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 					 gpt_header * pgpt_head)
 {
-	size_t count = 0;
+	size_t count = 0, blk_cnt;
 	gpt_entry *pte = NULL;
 
 	if (!dev_desc || !pgpt_head) {
@@ -669,7 +673,8 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
 	/* Allocate memory for PTE, remember to FREE */
 	if (count != 0) {
-		pte = memalign(ARCH_DMA_MINALIGN, count);
+		pte = memalign(ARCH_DMA_MINALIGN,
+			       PAD_TO_BLOCKSIZE(count, dev_desc));
 	}
 
 	if (count == 0 || pte == NULL) {
@@ -680,10 +685,11 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 	}
 
 	/* Read GPT Entries from device */
+	blk_cnt = BLOCK_CNT(count, dev_desc);
 	if (dev_desc->block_read (dev_desc->dev,
 		le64_to_cpu(pgpt_head->partition_entry_lba),
-		(lbaint_t) (count / GPT_BLOCK_SIZE), pte)
-		!= (count / GPT_BLOCK_SIZE)) {
+		(lbaint_t) (blk_cnt), pte)
+		!= blk_cnt) {
 
 		printf("*** ERROR: Can't read GPT Entries ***\n");
 		free(pte);
diff --git a/include/common.h b/include/common.h
index d41aeb4..53cc859 100644
--- a/include/common.h
+++ b/include/common.h
@@ -990,10 +990,17 @@ static inline void unmap_sysmem(const void *vaddr)
  * of a function scoped static buffer.  It can not be used to create a cache
  * line aligned global buffer.
  */
-#define ALLOC_ALIGN_BUFFER(type, name, size, align)			\
-	char __##name[ROUND(size * sizeof(type), align) + (align - 1)];	\
+#define PAD_COUNT(s, pad) ((s - 1) / pad + 1)
+#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
+#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
+	char __##name[ROUND(PAD_SIZE(size * sizeof(type), pad), align)  \
+		      + (align - 1)];					\
 									\
 	type *name = (type *) ALIGN((uintptr_t)__##name, align)
+#define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
+#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
 #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
 	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
diff --git a/include/part.h b/include/part.h
index c58a734..12e9b05 100644
--- a/include/part.h
+++ b/include/part.h
@@ -55,6 +55,10 @@ typedef struct block_dev_desc {
 	void		*priv;		/* driver private struct pointer */
 }block_dev_desc_t;
 
+#define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
+#define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
+	(PAD_SIZE(size, block_dev_desc->blksz))
+
 /* Interface types: */
 #define IF_TYPE_UNKNOWN		0
 #define IF_TYPE_IDE		1
diff --git a/include/part_efi.h b/include/part_efi.h
index 6de0a32..95e4c8f 100644
--- a/include/part_efi.h
+++ b/include/part_efi.h
@@ -38,7 +38,6 @@
 #define EFI_PMBR_OSTYPE_EFI 0xEF
 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
 
-#define GPT_BLOCK_SIZE 512
 #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
 #define GPT_HEADER_REVISION_V1 0x00010000
 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL
@@ -112,7 +111,6 @@ typedef struct _gpt_header {
 	__le32 num_partition_entries;
 	__le32 sizeof_partition_entry;
 	__le32 partition_entry_array_crc32;
-	u8 reserved2[GPT_BLOCK_SIZE - 92];
 } __packed gpt_header;
 
 typedef union _gpt_entry_attributes {
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH v2] fs/ext4: Support device block sizes != 512 bytes.
  2013-03-26 12:05     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
@ 2013-04-30 19:11       ` Tom Rini
  2013-05-01 11:13         ` [U-Boot] [PATCH v3] " Egbert Eich
  0 siblings, 1 reply; 17+ messages in thread
From: Tom Rini @ 2013-04-30 19:11 UTC (permalink / raw)
  To: u-boot

On Tue, Mar 26, 2013 at 08:05:59AM -0400, egbert.eich at gmail.com wrote:

> From: Egbert Eich <eich@suse.com>
> 
> The 512 byte block size was hard coded in the ext4 file systems. Large
> harddisks today support bigger block sizes typically 4096 bytes.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>
> ---
>  fs/ext4/dev.c          |   60 +++++++++++++++++++++++++++++++----------------
>  fs/ext4/ext4_common.c  |   42 ++++++++++++++++++---------------
>  fs/ext4/ext4_common.h  |    2 +-
>  fs/ext4/ext4_journal.c |    6 +---
>  fs/ext4/ext4_write.c   |   32 +++++++++++++------------
>  fs/ext4/ext4fs.c       |   14 ++++++----
>  include/ext4fs.h       |    1 +
>  include/ext_common.h   |   12 ++-------
>  8 files changed, 94 insertions(+), 75 deletions(-)

This breaks the sandbox and trats boards (same problem on both), please
fix, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130430/07a05a6e/attachment.pgp>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [PATCH v3] fs/ext4: Support device block sizes != 512 bytes
  2013-04-30 19:11       ` Tom Rini
@ 2013-05-01 11:13         ` Egbert Eich
  2013-05-10 19:58           ` [U-Boot] [U-Boot, " Tom Rini
  0 siblings, 1 reply; 17+ messages in thread
From: Egbert Eich @ 2013-05-01 11:13 UTC (permalink / raw)
  To: u-boot

From: Egbert Eich <eich@suse.com>

The 512 byte block size was hard coded in the ext4 file systems.
Large harddisks today support bigger block sizes typically 4096
bytes.
This patch removes this limitation.

Signed-off-by: Egbert Eich <eich@suse.com>
---
Changes for v2:                                                                                      - Coding style fixes.                                                                            
Changes for v3:
  - Build fixes. Builds on sandbox now.
                                      
 fs/ext4/dev.c          | 62 ++++++++++++++++++++++++++++++++------------------
 fs/ext4/ext4_common.c  | 42 ++++++++++++++++++----------------
 fs/ext4/ext4_common.h  |  2 +-
 fs/ext4/ext4_journal.c |  6 ++---
 fs/ext4/ext4_write.c   | 32 ++++++++++++++------------
 fs/ext4/ext4fs.c       | 14 +++++++-----
 include/ext4fs.h       |  1 +
 include/ext_common.h   | 12 +++-------
 8 files changed, 95 insertions(+), 76 deletions(-)

diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
index 464a67d..3e993cc 100644
--- a/fs/ext4/dev.c
+++ b/fs/ext4/dev.c
@@ -40,6 +40,7 @@
 #include <config.h>
 #include <ext4fs.h>
 #include <ext_common.h>
+#include "ext4_common.h"
 
 unsigned long part_offset;
 
@@ -48,37 +49,41 @@ static disk_partition_t *part_info;
 
 void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
 {
+	assert(rbdd->blksz == (1 << rbdd->log2blksz));
 	ext4fs_block_dev_desc = rbdd;
 	part_info = info;
 	part_offset = info->start;
-	get_fs()->total_sect = (info->size * info->blksz) / SECTOR_SIZE;
+	get_fs()->total_sect = (info->size * info->blksz) >>
+		get_fs()->dev_desc->log2blksz;
 	get_fs()->dev_desc = rbdd;
 }
 
 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, SECTOR_SIZE);
 	unsigned block_len;
+	int log2blksz = ext4fs_block_dev_desc->log2blksz;
+	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (ext4fs_block_dev_desc ?
+						 ext4fs_block_dev_desc->blksz :
+						 0));
+	if (ext4fs_block_dev_desc == NULL) {
+		printf("** Invalid Block Device Descriptor (NULL)\n");
+		return 0;
+	}
 
 	/* Check partition boundaries */
-	if ((sector < 0)
-	    || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
-		part_info->size)) {
+	if ((sector < 0) ||
+	    ((sector + ((byte_offset + byte_len - 1) >> log2blksz))
+	     >= 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;
+	sector += byte_offset >> log2blksz;
+	byte_offset &= ext4fs_block_dev_desc->blksz - 1;
 
 	debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
 
-	if (ext4fs_block_dev_desc == NULL) {
-		printf("** Invalid Block Device Descriptor (NULL)\n");
-		return 0;
-	}
-
 	if (byte_offset != 0) {
 		/* read first part which isn't aligned with start of sector */
 		if (ext4fs_block_dev_desc->
@@ -89,9 +94,12 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 			return 0;
 		}
 		memcpy(buf, sec_buf + byte_offset,
-			min(SECTOR_SIZE - byte_offset, byte_len));
-		buf += min(SECTOR_SIZE - byte_offset, byte_len);
-		byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
+			min(ext4fs_block_dev_desc->blksz
+			    - byte_offset, byte_len));
+		buf += min(ext4fs_block_dev_desc->blksz
+			   - byte_offset, byte_len);
+		byte_len -= min(ext4fs_block_dev_desc->blksz
+				- byte_offset, byte_len);
 		sector++;
 	}
 
@@ -99,12 +107,12 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 		return 1;
 
 	/* read sector aligned part */
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 
 	if (block_len == 0) {
-		ALLOC_CACHE_ALIGN_BUFFER(u8, p, SECTOR_SIZE);
+		ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_block_dev_desc->blksz);
 
-		block_len = SECTOR_SIZE;
+		block_len = ext4fs_block_dev_desc->blksz;
 		ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 						  part_info->start + sector,
 						  1, (unsigned long *)p);
@@ -114,16 +122,16 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 
 	if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
 					       part_info->start + sector,
-					       block_len / SECTOR_SIZE,
+					       block_len >> log2blksz,
 					       (unsigned long *) buf) !=
-					       block_len / SECTOR_SIZE) {
+					       block_len >> log2blksz) {
 		printf(" ** %s read error - block\n", __func__);
 		return 0;
 	}
-	block_len = byte_len & ~(SECTOR_SIZE - 1);
+	block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
 	buf += block_len;
 	byte_len -= block_len;
-	sector += block_len / SECTOR_SIZE;
+	sector += block_len / ext4fs_block_dev_desc->blksz;
 
 	if (byte_len != 0) {
 		/* read rest of data which are not in whole sector */
@@ -138,3 +146,13 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 	}
 	return 1;
 }
+
+int ext4_read_superblock(char *buffer)
+{
+	struct ext_filesystem *fs = get_fs();
+	int sect = SUPERBLOCK_START >> fs->dev_desc->log2blksz;
+	int off = SUPERBLOCK_START % fs->dev_desc->blksz;
+
+	return ext4fs_devread(sect, off, SUPERBLOCK_SIZE,
+				buffer);
+}
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index f12b805..58880b4 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -71,18 +71,18 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 	uint64_t startblock;
 	uint64_t remainder;
 	unsigned char *temp_ptr = NULL;
-	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, SECTOR_SIZE);
 	struct ext_filesystem *fs = get_fs();
+	int log2blksz = fs->dev_desc->log2blksz;
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, fs->dev_desc->blksz);
 
-	startblock = off / (uint64_t)SECTOR_SIZE;
+	startblock = off >> log2blksz;
 	startblock += part_offset;
-	remainder = off % (uint64_t)SECTOR_SIZE;
-	remainder &= SECTOR_SIZE - 1;
+	remainder = off & (uint64_t)(fs->dev_desc->blksz - 1);
 
 	if (fs->dev_desc == NULL)
 		return;
 
-	if ((startblock + (size / SECTOR_SIZE)) >
+	if ((startblock + (size >> log2blksz)) >
 	    (part_offset + fs->total_sect)) {
 		printf("part_offset is %lu\n", part_offset);
 		printf("total_sector is %llu\n", fs->total_sect);
@@ -101,10 +101,10 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 						  startblock, 1, sec_buf);
 		}
 	} else {
-		if (size / SECTOR_SIZE != 0) {
+		if (size >> log2blksz != 0) {
 			fs->dev_desc->block_write(fs->dev_desc->dev,
 						  startblock,
-						  size / SECTOR_SIZE,
+						  size >> log2blksz,
 						  (unsigned long *)buf);
 		} else {
 			fs->dev_desc->block_read(fs->dev_desc->dev,
@@ -1459,6 +1459,7 @@ static int ext4fs_blockgroup
 {
 	long int blkno;
 	unsigned int blkoff, desc_per_blk;
+	int log2blksz = get_fs()->dev_desc->log2blksz;
 
 	desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
 
@@ -1469,7 +1470,7 @@ static int ext4fs_blockgroup
 	debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n",
 	      group, blkno, blkoff);
 
-	return ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data),
+	return ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz),
 			      blkoff, sizeof(struct ext2_block_group),
 			      (char *)blkgrp);
 }
@@ -1479,6 +1480,7 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
 	struct ext2_block_group blkgrp;
 	struct ext2_sblock *sblock = &data->sblock;
 	struct ext_filesystem *fs = get_fs();
+	int log2blksz = get_fs()->dev_desc->log2blksz;
 	int inodes_per_block, status;
 	long int blkno;
 	unsigned int blkoff;
@@ -1495,7 +1497,8 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
 	    (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
 	blkoff = (ino % inodes_per_block) * fs->inodesz;
 	/* Read the inode. */
-	status = ext4fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data), blkoff,
+	status = ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz),
+				blkoff,
 				sizeof(struct ext2_inode), (char *)inode);
 	if (status == 0)
 		return 0;
@@ -1515,7 +1518,9 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 	unsigned long long start;
 	/* get the blocksize of the filesystem */
 	blksz = EXT2_BLOCK_SIZE(ext4fs_root);
-	log2_blksz = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
+	log2_blksz = LOG2_BLOCK_SIZE(ext4fs_root)
+		- get_fs()->dev_desc->log2blksz;
+
 	if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) {
 		char *buf = zalloc(blksz);
 		if (!buf)
@@ -1523,11 +1528,11 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 		struct ext4_extent_header *ext_block;
 		struct ext4_extent *extent;
 		int i = -1;
-		ext_block = ext4fs_get_extent_block(ext4fs_root, buf,
-						    (struct ext4_extent_header
-						     *)inode->b.
-						    blocks.dir_blocks,
-						    fileblock, log2_blksz);
+		ext_block =
+			ext4fs_get_extent_block(ext4fs_root, buf,
+						(struct ext4_extent_header *)
+						inode->b.blocks.dir_blocks,
+						fileblock, log2_blksz);
 		if (!ext_block) {
 			printf("invalid extent block\n");
 			free(buf);
@@ -1839,7 +1844,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 		blknr = __le32_to_cpu(ext4fs_indir3_block
 				      [rblock % perblock_child]);
 	}
-	debug("ext4fs_read_block %ld\n", blknr);
+	debug("read_allocated_block %ld\n", blknr);
 
 	return blknr;
 }
@@ -2193,13 +2198,12 @@ int ext4fs_mount(unsigned part_length)
 	struct ext2_data *data;
 	int status;
 	struct ext_filesystem *fs = get_fs();
-	data = zalloc(sizeof(struct ext2_data));
+	data = zalloc(SUPERBLOCK_SIZE);
 	if (!data)
 		return 0;
 
 	/* Read the superblock. */
-	status = ext4fs_devread(1 * 2, 0, sizeof(struct ext2_sblock),
-				(char *)&data->sblock);
+	status = ext4_read_superblock((char *)&data->sblock);
 
 	if (status == 0)
 		goto fail;
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 72cd020..6571df6 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -49,7 +49,7 @@
 
 #define S_IFLNK		0120000		/* symbolic link */
 #define BLOCK_NO_ONE		1
-#define SUPERBLOCK_SECTOR	2
+#define SUPERBLOCK_START	(2 * 512)
 #define SUPERBLOCK_SIZE	1024
 #define F_FILE			1
 
diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c
index ba4a7bb..81aa5fc 100644
--- a/fs/ext4/ext4_journal.c
+++ b/fs/ext4/ext4_journal.c
@@ -534,16 +534,14 @@ end:
 		jsb->s_start = cpu_to_be32(1);
 		jsb->s_sequence = cpu_to_be32(be32_to_cpu(jsb->s_sequence) + 1);
 		/* get the superblock */
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 		fs->sb->feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER;
 
 		/* Update the super block */
 		put_ext4((uint64_t) (SUPERBLOCK_SIZE),
 			 (struct ext2_sblock *)fs->sb,
 			 (uint32_t) SUPERBLOCK_SIZE);
-		ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			       (char *)fs->sb);
+		ext4_read_superblock((char *)fs->sb);
 
 		blknr = read_allocated_block(&inode_journal,
 					 EXT2_JOURNAL_SUPERBLOCK);
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index c4e399c..0c1f62b 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -614,14 +614,13 @@ int ext4fs_init(void)
 	/* populate fs */
 	fs->blksz = EXT2_BLOCK_SIZE(ext4fs_root);
 	fs->inodesz = INODE_SIZE_FILESYSTEM(ext4fs_root);
-	fs->sect_perblk = fs->blksz / SECTOR_SIZE;
+	fs->sect_perblk = fs->blksz >> fs->dev_desc->log2blksz;
 
 	/* get the superblock */
 	fs->sb = zalloc(SUPERBLOCK_SIZE);
 	if (!fs->sb)
 		return -ENOMEM;
-	if (!ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE,
-			(char *)fs->sb))
+	if (!ext4_read_superblock((char *)fs->sb))
 		goto fail;
 
 	/* init journal */
@@ -722,7 +721,7 @@ void ext4fs_deinit(void)
 	ext4fs_free_journal();
 
 	/* get the superblock */
-	ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE, (char *)fs->sb);
+	ext4_read_superblock((char *)fs->sb);
 	fs->sb->feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER;
 	put_ext4((uint64_t)(SUPERBLOCK_SIZE),
 		 (struct ext2_sblock *)fs->sb, (uint32_t)SUPERBLOCK_SIZE);
@@ -766,9 +765,10 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 {
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(ext4fs_root);
 	unsigned int filesize = __le32_to_cpu(file_inode->size);
 	struct ext_filesystem *fs = get_fs();
+	int log2blksz = fs->dev_desc->log2blksz;
+	int log2_fs_blocksize = LOG2_BLOCK_SIZE(ext4fs_root) - log2blksz;
 	int previous_block_number = -1;
 	int delayed_start = 0;
 	int delayed_extent = 0;
@@ -789,16 +789,16 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 		if (blknr < 0)
 			return -1;
 
-		blknr = blknr << log2blocksize;
+		blknr = blknr << log2_fs_blocksize;
 
 		if (blknr) {
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> log2blksz;
 				} else {	/* spill */
-					put_ext4((uint64_t) (delayed_start *
-							     SECTOR_SIZE),
+					put_ext4((uint64_t)
+						 (delayed_start << log2blksz),
 						 delayed_buf,
 						 (uint32_t) delayed_extent);
 					previous_block_number = blknr;
@@ -806,7 +806,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 					delayed_extent = blockend;
 					delayed_buf = buf;
 					delayed_next = blknr +
-					    (blockend >> SECTOR_BITS);
+					    (blockend >> log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -814,13 +814,14 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 				delayed_extent = blockend;
 				delayed_buf = buf;
 				delayed_next = blknr +
-				    (blockend >> SECTOR_BITS);
+				    (blockend >> log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
 				/* spill */
-				put_ext4((uint64_t) (delayed_start *
-						     SECTOR_SIZE), delayed_buf,
+				put_ext4((uint64_t) (delayed_start <<
+						     log2blksz),
+					 delayed_buf,
 					 (uint32_t) delayed_extent);
 				previous_block_number = -1;
 			}
@@ -830,7 +831,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
 	}
 	if (previous_block_number != -1) {
 		/* spill */
-		put_ext4((uint64_t) (delayed_start * SECTOR_SIZE),
+		put_ext4((uint64_t) (delayed_start << log2blksz),
 			 delayed_buf, (uint32_t) delayed_extent);
 		previous_block_number = -1;
 	}
@@ -921,7 +922,8 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
 	/* Allocate data blocks */
 	ext4fs_allocate_blocks(file_inode, blocks_remaining,
 			       &blks_reqd_for_file);
-	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) / SECTOR_SIZE;
+	file_inode->blockcnt = (blks_reqd_for_file * fs->blksz) >>
+		fs->dev_desc->log2blksz;
 
 	temp_ptr = zalloc(fs->blksz);
 	if (!temp_ptr)
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 4dddde2..1954afb 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -60,10 +60,12 @@ void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot)
 int ext4fs_read_file(struct ext2fs_node *node, int pos,
 		unsigned int len, char *buf)
 {
+	struct ext_filesystem *fs = get_fs();
 	int i;
 	int blockcnt;
-	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(node->data);
-	int blocksize = 1 << (log2blocksize + DISK_SECTOR_BITS);
+	int log2blksz = fs->dev_desc->log2blksz;
+	int log2_fs_blocksize = LOG2_BLOCK_SIZE(node->data) - log2blksz;
+	int blocksize = (1 << (log2_fs_blocksize + log2blksz));
 	unsigned int filesize = __le32_to_cpu(node->inode.size);
 	int previous_block_number = -1;
 	int delayed_start = 0;
@@ -88,7 +90,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 		if (blknr < 0)
 			return -1;
 
-		blknr = blknr << log2blocksize;
+		blknr = blknr << log2_fs_blocksize;
 
 		/* Last block.  */
 		if (i == blockcnt - 1) {
@@ -110,7 +112,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 			if (previous_block_number != -1) {
 				if (delayed_next == blknr) {
 					delayed_extent += blockend;
-					delayed_next += blockend >> SECTOR_BITS;
+					delayed_next += blockend >> log2blksz;
 				} else {	/* spill */
 					status = ext4fs_devread(delayed_start,
 							delayed_skipfirst,
@@ -124,7 +126,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 					delayed_skipfirst = skipfirst;
 					delayed_buf = buf;
 					delayed_next = blknr +
-						(blockend >> SECTOR_BITS);
+						(blockend >> log2blksz);
 				}
 			} else {
 				previous_block_number = blknr;
@@ -133,7 +135,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
 				delayed_skipfirst = skipfirst;
 				delayed_buf = buf;
 				delayed_next = blknr +
-					(blockend >> SECTOR_BITS);
+					(blockend >> log2blksz);
 			}
 		} else {
 			if (previous_block_number != -1) {
diff --git a/include/ext4fs.h b/include/ext4fs.h
index 025a2e8..379f7eb 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -141,4 +141,5 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock);
 int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
 		 disk_partition_t *fs_partition);
 int ext4_read_file(const char *filename, void *buf, int offset, int len);
+int ext4_read_superblock(char *buffer);
 #endif
diff --git a/include/ext_common.h b/include/ext_common.h
index 86373a6..78a7808 100644
--- a/include/ext_common.h
+++ b/include/ext_common.h
@@ -34,7 +34,6 @@
 #define __EXT_COMMON__
 #include <command.h>
 #define SECTOR_SIZE		0x200
-#define SECTOR_BITS		9
 
 /* Magic value used to identify an ext2 filesystem.  */
 #define	EXT2_MAGIC			0xEF53
@@ -58,18 +57,13 @@
 #define FILETYPE_INO_SYMLINK		0120000
 #define EXT2_ROOT_INO			2 /* Root inode */
 
-/* Bits used as offset in sector */
-#define DISK_SECTOR_BITS		9
 /* The size of an ext2 block in bytes.  */
 #define EXT2_BLOCK_SIZE(data)	   (1 << LOG2_BLOCK_SIZE(data))
 
-/* 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)
+#define LOG2_BLOCK_SIZE(data)	   (__le32_to_cpu		   \
+				    (data->sblock.log2_block_size) \
+				    + EXT2_MIN_BLOCK_LOG_SIZE)
 #define INODE_SIZE_FILESYSTEM(data)	(__le32_to_cpu \
 			(data->sblock.inode_size))
 
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [U-Boot] [U-Boot, v2] disk/gpt: Fix GPT partition handling for blocksize != 512
  2013-04-09 16:03   ` [U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize " Egbert Eich
@ 2013-05-02 16:07     ` Tom Rini
  0 siblings, 0 replies; 17+ messages in thread
From: Tom Rini @ 2013-05-02 16:07 UTC (permalink / raw)
  To: u-boot

On Tue, Apr 09, 2013 at 06:03:36AM -0000, egbert.eich at gmail.com wrote:

> From: Egbert Eich <eich@suse.com>
> 
> Disks beyond 2T in size use blocksizes of 4096 bytes. However a lot of
> code in u-boot  still assumes a 512 byte blocksize.
> This patch fixes the handling of GPTs.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130502/bf740016/attachment.pgp>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [U-Boot] [U-Boot, v3] fs/ext4: Support device block sizes != 512 bytes
  2013-05-01 11:13         ` [U-Boot] [PATCH v3] " Egbert Eich
@ 2013-05-10 19:58           ` Tom Rini
  0 siblings, 0 replies; 17+ messages in thread
From: Tom Rini @ 2013-05-10 19:58 UTC (permalink / raw)
  To: u-boot

On Wed, May 01, 2013 at 01:13:19AM -0000, egbert.eich at gmail.com wrote:

> From: Egbert Eich <eich@suse.com>
> 
> The 512 byte block size was hard coded in the ext4 file systems.
> Large harddisks today support bigger block sizes typically 4096
> bytes.
> This patch removes this limitation.
> 
> Signed-off-by: Egbert Eich <eich@suse.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130510/42a9c0b9/attachment.pgp>

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-05-10 19:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-26  8:15 [U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512 egbert.eich at googlemail.com
2013-03-26  8:15 ` [U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize " egbert.eich at googlemail.com
2013-03-26 11:30   ` Wolfgang Denk
2013-03-26 12:03     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
2013-04-09 16:03   ` [U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize " Egbert Eich
2013-05-02 16:07     ` [U-Boot] [U-Boot, " Tom Rini
2013-03-26  8:15 ` [U-Boot] [PATCH 2/5] disk/iso: Add Support for Block Sizes > 512 Byte to ISO partition support egbert.eich at googlemail.com
2013-03-26  8:15 ` [U-Boot] [PATCH 3/5] fs/fat: Don't multiply fatsize with sector size egbert.eich at googlemail.com
2013-03-26  8:15 ` [U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct egbert.eich at googlemail.com
2013-03-26 11:31   ` Wolfgang Denk
2013-03-26 12:05     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
2013-03-26  8:15 ` [U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes egbert.eich at googlemail.com
2013-03-26 11:32   ` Wolfgang Denk
2013-03-26 12:05     ` [U-Boot] [PATCH v2] " egbert.eich at gmail.com
2013-04-30 19:11       ` Tom Rini
2013-05-01 11:13         ` [U-Boot] [PATCH v3] " Egbert Eich
2013-05-10 19:58           ` [U-Boot] [U-Boot, " Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox