Re: [U-Boot] [Patch v3] cmd/gpt: Support gpt command for all devices

2013-10-12 Thread Egbert Eich
On Fri, Oct 11, 2013 at 09:13:22AM +0200, Piotr Wilczek wrote:
 Dear Egbert Eich,
 
  -Original Message-
  From: Egbert Eich [mailto:egbert.e...@gmail.com]
  Sent: Friday, October 04, 2013 6:53 PM
  To: u-boot@lists.denx.de
  Cc: Piotr Wilczek; Tom Rini; Egbert Eich; Egbert Eich
  Subject: [Patch v3] cmd/gpt: Support gpt command for all devices
  
  From: Egbert Eich e...@suse.com
  
  The gpt command was only implemented for mmc devices. There is no
  reason why this command should not be generalized and be applied all
  other storage device classes.
  This change both simplifies the implementation and eliminates a build
  failure for systems that don't support mmcs.
  
  Signed-off-by: Egbert Eich e...@suse.com
  ---
  Changes for v2:
 - Coding style cleanup.
  Changes for v3:
 - Removed wrong ''
 - Removed unused variable
 - Fixed argument checking
 Spotted by Piotr Wilczek p.wilc...@samsung.com
  
   common/cmd_gpt.c | 45 +++--
   1 file changed, 19 insertions(+), 26 deletions(-)
  
  diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c index a46f5cc..17b1180
  100644
  --- a/common/cmd_gpt.c
  +++ b/common/cmd_gpt.c

[..]

  
  @@ -287,27 +279,28 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int

[..]

  -   /* device: 'mmc' */
  -   if (strcmp(argv[2], mmc) == 0) {
  -   /* check if 'dev' is a number */
  -   for (pstr = argv[3]; *pstr != '\0'; pstr++)
  -   if (!isdigit(*pstr)) {
  -   printf('%s' is not a number\n,
  -   argv[3]);
  -   return CMD_RET_USAGE;
  -   }
  -   dev = (int)simple_strtoul(argv[3], NULL, 10);
  -   /* write to mmc */
  -   if (gpt_mmc_default(dev, argv[4]))
  -   return CMD_RET_FAILURE;
  +   char *ep;
  +   block_dev_desc_t *blk_dev_desc;
 This probably should be at the beginning of the function

I personally prefer to keep symbols as local as possible (ie. declare them
in the block they are used in if they are just used within a single block) 
for the following rasons:
1. It makes the code more readable ie. the definition is closeby to
   the location where it is used and doesn't require scrolling to 
   the beginning of a function and the scope of the variable is is 
   much more obvious.
2. The compiler can optimize much better as it knows that a variable 
   can be discarded at the end of the block also by reusing stack 
   slots stack sapce can be used much more efficiently by the compiler.

I agree that in the case at hand the second argument is not too
relevant, it is more a coding style issue. If there is a coding
style requirement to have those definitions at the beginning of
the function I will create a new patch.


[..]

  +   blk_dev_desc = get_dev(argv[2], dev);
  +   if (!blk_dev_desc) {
  +   printf(%s: %s dev %d NOT available\n,
  +  __func__, argv[2], dev);
 I think it is not necessary since the mmc subsystem prints 'MMC Device not
 found'.

I've done a quick look over the code - of all subsystems MMC seems to be 
the only one which prints a message when its get_dev() method is called 
but no device is found. Therefore I'd prefer to leave this there.

 
 Except minor comments this patch looks good to me.
 I tested it on mmc device (Trats2) and works well.

Ok, thanks!

 
 Tested-by: Piotr Wilczek p.wilc...@samsung.com
 

Thanks a lot for testing!

Cheers,
Egbert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [Patch v3] cmd/gpt: Support gpt command for all devices

2013-10-04 Thread Egbert Eich
From: Egbert Eich e...@suse.com

The gpt command was only implemented for mmc devices. There is no reason
why this command should not be generalized and be applied all other
storage device classes.
This change both simplifies the implementation and eliminates a
build failure for systems that don't support mmcs.

Signed-off-by: Egbert Eich e...@suse.com
---
Changes for v2:
   - Coding style cleanup.
Changes for v3:
   - Removed wrong ''
   - Removed unused variable
   - Fixed argument checking
   Spotted by Piotr Wilczek p.wilc...@samsung.com

 common/cmd_gpt.c | 45 +++--
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index a46f5cc..17b1180 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -11,7 +11,6 @@
 #include common.h
 #include malloc.h
 #include command.h
-#include mmc.h
 #include part_efi.h
 #include exports.h
 #include linux/ctype.h
@@ -122,7 +121,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
 
-   debug(%s: MMC lba num: 0x%x %d\n, __func__,
+   debug(%s:  lba num: 0x%x %d\n, __func__,
  (unsigned int)dev_desc-lba, (unsigned int)dev_desc-lba);
 
if (str_part == NULL)
@@ -235,25 +234,18 @@ err:
return errno;
 }
 
-static int gpt_mmc_default(int dev, const char *str_part)
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
 {
int ret;
char *str_disk_guid;
u8 part_count = 0;
disk_partition_t *partitions = NULL;
 
-   struct mmc *mmc = find_mmc_device(dev);
-
-   if (mmc == NULL) {
-   printf(%s: mmc dev %d NOT available\n, __func__, dev);
-   return CMD_RET_FAILURE;
-   }
-
if (!str_part)
return -1;
 
/* fill partitions */
-   ret = set_gpt_info(mmc-block_dev, str_part,
+   ret = set_gpt_info(blk_dev_desc, str_part,
str_disk_guid, partitions, part_count);
if (ret) {
if (ret == -1)
@@ -266,7 +258,7 @@ static int gpt_mmc_default(int dev, const char *str_part)
}
 
/* save partitions layout to disk */
-   gpt_restore(mmc-block_dev, str_disk_guid, partitions, part_count);
+   gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
free(str_disk_guid);
free(partitions);
 
@@ -287,27 +279,28 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 {
int ret = CMD_RET_SUCCESS;
int dev = 0;
-   char *pstr;
 
if (argc  5)
return CMD_RET_USAGE;
 
/* command: 'write' */
if ((strcmp(argv[1], write) == 0)  (argc == 5)) {
-   /* device: 'mmc' */
-   if (strcmp(argv[2], mmc) == 0) {
-   /* check if 'dev' is a number */
-   for (pstr = argv[3]; *pstr != '\0'; pstr++)
-   if (!isdigit(*pstr)) {
-   printf('%s' is not a number\n,
-   argv[3]);
-   return CMD_RET_USAGE;
-   }
-   dev = (int)simple_strtoul(argv[3], NULL, 10);
-   /* write to mmc */
-   if (gpt_mmc_default(dev, argv[4]))
-   return CMD_RET_FAILURE;
+   char *ep;
+   block_dev_desc_t *blk_dev_desc;
+   dev = (int)simple_strtoul(argv[3], ep, 10);
+   if (!ep || ep[0] != '\0') {
+   printf('%s' is not a number\n, argv[3]);
+   return CMD_RET_USAGE;
}
+   blk_dev_desc = get_dev(argv[2], dev);
+   if (!blk_dev_desc) {
+   printf(%s: %s dev %d NOT available\n,
+  __func__, argv[2], dev);
+   return CMD_RET_FAILURE;
+   }
+
+   if (gpt_default(blk_dev_desc, argv[4]))
+   return CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] config: Define HAVE_BLOCK_DEVICE when CONFIG_CMD_GPT is set

2013-10-04 Thread Egbert Eich
From: Egbert Eich e...@suse.com

Signed-off-by: Egbert Eich e...@suse.com
---
 include/config_fallbacks.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/config_fallbacks.h b/include/config_fallbacks.h
index e59ee96..5c8acdb 100644
--- a/include/config_fallbacks.h
+++ b/include/config_fallbacks.h
@@ -48,6 +48,7 @@
defined(CONFIG_CMD_SCSI) || \
defined(CONFIG_CMD_USB) || \
defined(CONFIG_CMD_PART) || \
+   defined(CONFIG_CMD_GPT) || \
defined(CONFIG_MMC) || \
defined(CONFIG_SYSTEMACE)
 #define HAVE_BLOCK_DEVICE
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] config/sandbox: Add EFI and GPT support

2013-10-04 Thread Egbert Eich
From: Egbert Eich e...@suse.com

Signed-off-by: Egbert Eich e...@suse.com
---
 include/configs/sandbox.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index 4027030..b18cafb 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -44,6 +44,10 @@
 #define CONFIG_SANDBOX_GPIO
 #define CONFIG_SANDBOX_GPIO_COUNT  20
 
+#define CONFIG_CMD_GPT
+#define CONFIG_PARTITION_UUIDS
+#define CONFIG_EFI_PARTITION
+
 /*
  * Size of malloc() pool, although we don't actually use this yet.
  */
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3] fs/ext4: Support device block sizes != 512 bytes

2013-05-01 Thread Egbert Eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH v2 2/4] fs/fat: Don't multiply fatsize with sector size

2013-04-10 Thread Egbert Eich
From: Egbert Eich e...@suse.com

Bugfix:
Here at this place we need the fat size in sectors not bytes.
This was found during code review when adding support for storage
devices with blocksizes != 512.

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

 fs/fat/fat_write.c | 1 -
 1 file changed, 1 deletion(-)

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.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 1/4] disk/iso: Add Support for block sizes 512 byte to ISO partition support

2013-04-10 Thread Egbert Eich
From: Egbert Eich e...@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 e...@suse.com
---
Changes for v2:   
  - Coding style fixes.   

 disk/part_iso.c  | 3 +++
 include/common.h | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

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 53cc859..c080cb8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1011,7 +1011,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)));
\
+   __aligned(align);   \
\
static type *name = (type *)__##name
 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)\
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 0/4] Add Support for Storage Devices with Blocksizes != 512

2013-04-10 Thread Egbert Eich
From: Egbert Eich e...@suse.de

Storage devices with more than 2TB generally use blocksizes of 4096 bytes,
So far u-boot was unable to boot from those devices as block sizes were 
hard coded to 512 bytes.

This patchset adds support for blocksizes != 512 byte to:
 - the ISO partition table.
 - the ext4. 

To be useful, one most likely needs:
   disk/gpt: Fix GPT Partition handling for Blocksize != 512
which was posted earlier.

With those fixes in place u-boot loads the kernel and initrd flawlessly   
from an ext2 fs on my 3TB USB hard drive which is set up with a GPT.
  

I've also 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 and I thus can test.   

Egbert Eich (4):
  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  |  5 
 common/cmd_sata.c |  1 +
 common/cmd_scsi.c |  4 +++
 common/usb_storage.c  |  1 +
 disk/part_iso.c   |  3 +++
 drivers/block/ata_piix.c  |  1 +
 drivers/block/pata_bfin.c |  2 ++
 drivers/block/systemace.c |  1 +
 drivers/mmc/mmc.c |  1 +
 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 ++-
 fs/fat/fat_write.c|  1 -
 include/common.h  |  2 +-
 include/ext4fs.h  |  1 +
 include/ext_common.h  | 12 +++--
 include/part.h|  5 
 20 files changed, 120 insertions(+), 78 deletions(-)

-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 4/4] fs/ext4: Support device block sizes != 512 bytes

2013-04-10 Thread Egbert Eich
From: Egbert Eich e...@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 e...@suse.com
---
Changes for v2:   
  - Coding style fixes.   

 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

[U-Boot] [PATCH v2 3/4] part/dev_desc: Add log2 of blocksize to block_dev_desc data struct

2013-04-10 Thread Egbert Eich
From: Egbert Eich e...@suse.com

log2 of the device block size serves as the shift value used to calculate
the block number to read in file systems when implementing avaiable block
sizes.
It is needed quite often in file systems thus it is pre-calculated and
stored in the block device descriptor.

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

 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(+)

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 13b3d99..294d9f5 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

[U-Boot] [Patch v2] cmd/gpt: Support gpt command for all devices

2013-04-09 Thread Egbert Eich
From: Egbert Eich e...@suse.com

The gpt command was only implemented for mmc devices. There is no reason
why this command should not be generalized and be applied all other
storage device classes.
This change both simplifies the implementation and eliminates a
build failure for systems that don't support mmcs.

Signed-off-by: Egbert Eich e...@suse.com
---
Changes for v2:
  - Coding style cleanup.

 common/cmd_gpt.c | 44 +++-
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index efd7934..3594dca 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -23,7 +23,6 @@
 #include common.h
 #include malloc.h
 #include command.h
-#include mmc.h
 #include part_efi.h
 #include exports.h
 #include linux/ctype.h
@@ -134,7 +133,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
 
-   debug(%s: MMC lba num: 0x%x %d\n, __func__,
+   debug(%s:  lba num: 0x%x %d\n, __func__,
  (unsigned int)dev_desc-lba, (unsigned int)dev_desc-lba);
 
if (str_part == NULL)
@@ -247,25 +246,18 @@ err:
return errno;
 }
 
-static int gpt_mmc_default(int dev, const char *str_part)
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
 {
int ret;
char *str_disk_guid;
u8 part_count = 0;
disk_partition_t *partitions = NULL;
 
-   struct mmc *mmc = find_mmc_device(dev);
-
-   if (mmc == NULL) {
-   printf(%s: mmc dev %d NOT available\n, __func__, dev);
-   return CMD_RET_FAILURE;
-   }
-
if (!str_part)
return -1;
 
/* fill partitions */
-   ret = set_gpt_info(mmc-block_dev, str_part,
+   ret = set_gpt_info(blk_dev_desc, str_part,
str_disk_guid, partitions, part_count);
if (ret) {
if (ret == -1)
@@ -278,7 +270,7 @@ static int gpt_mmc_default(int dev, const char *str_part)
}
 
/* save partitions layout to disk */
-   gpt_restore(mmc-block_dev, str_disk_guid, partitions, part_count);
+   gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
free(str_disk_guid);
free(partitions);
 
@@ -306,20 +298,22 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 
/* command: 'write' */
if ((strcmp(argv[1], write) == 0)  (argc == 5)) {
-   /* device: 'mmc' */
-   if (strcmp(argv[2], mmc) == 0) {
-   /* check if 'dev' is a number */
-   for (pstr = argv[3]; *pstr != '\0'; pstr++)
-   if (!isdigit(*pstr)) {
-   printf('%s' is not a number\n,
-   argv[3]);
-   return CMD_RET_USAGE;
-   }
-   dev = (int)simple_strtoul(argv[3], NULL, 10);
-   /* write to mmc */
-   if (gpt_mmc_default(dev, argv[4]))
-   return CMD_RET_FAILURE;
+   char *ep;
+   block_dev_desc_t *blk_dev_desc;
+   dev = (int)simple_strtoul(argv[3], NULL, 10);
+   if (*ep) {
+   printf('%s' is not a number\n, argv[3]);
+   return CMD_RET_USAGE;
}
+   blk_dev_desc = get_dev(argv[2], dev);
+   if (!blk_dev_desc) {
+   printf(%s: %s dev %d NOT available\n,
+  __func__, argv[2], dev);
+   return CMD_RET_FAILURE;
+   }
+
+   if (gpt_default(blk_dev_desc, argv[4]))
+   return CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [Patch v2] disk/part_dos: check harder for partition table

2013-04-09 Thread Egbert Eich
From: Egbert Eich e...@suse.com

Devices that used to have a whole disk FAT filesystem but got then
partitioned will most likely still have a FAT or FAT32 signature
in the first sector as this sector does not get overwritten by
a partitioning tool (otherwise the tool would risk to kill the mbr).

The current partition search algorithm will erronously detects such
a device as a raw FAT device.

Instead of looking for the FAT or FAT32 signatures immediately we
use the same algorithm as used by the Linux kernel and first check
for a valid boot indicator flag on each of the 4 partitions.
If the value of this flag is invalid for the first entry we then
do the raw partition check.
If the flag for any higher partition is wrong we assume the device
is neiter a MBR nor PBR device.

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

 disk/part_dos.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 37087a6..ab984cd 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -74,13 +74,26 @@ static void print_one_part(dos_partition_t *p, int 
ext_part_sector,
 
 static int test_block_type(unsigned char *buffer)
 {
+   int slot;
+   struct dos_partition *p;
+
if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
(buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
return (-1);
} /* no DOS Signature at all */
-   if (strncmp((char *)buffer[DOS_PBR_FSTYPE_OFFSET],FAT,3)==0 ||
-   strncmp((char *)buffer[DOS_PBR32_FSTYPE_OFFSET],FAT32,5)==0) {
-   return DOS_PBR; /* is PBR */
+   p = (struct dos_partition *)buffer[DOS_PART_TBL_OFFSET];
+   for (slot = 0; slot  3; slot++) {
+   if (p-boot_ind != 0  p-boot_ind != 0x80) {
+   if (!slot 
+   (strncmp((char *)buffer[DOS_PBR_FSTYPE_OFFSET],
+FAT, 3) == 0 ||
+strncmp((char *)buffer[DOS_PBR32_FSTYPE_OFFSET],
+FAT32, 5) == 0)) {
+   return DOS_PBR; /* is PBR */
+   } else {
+   return -1;
+   }
+   }
}
return DOS_MBR; /* Is MBR */
 }
-- 
1.8.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [Patch v2] disk/gpt: Fix GPT partition handling for blocksize != 512

2013-04-09 Thread Egbert Eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH] cmd/gpt: Support gpt command for all devices.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@suse.com

The gpt command was only implemented for mmc devices. There is no reason
why this command should not be generalized and be applied all other
storage device classes.
This change both simplifies the implementation and eliminates a
build failure for systems that don't support mmcs.

Signed-off-by: Egbert Eich e...@suse.com
---
 common/cmd_gpt.c |   43 ++-
 1 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index efd7934..1a72e8e 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -23,7 +23,6 @@
 #include common.h
 #include malloc.h
 #include command.h
-#include mmc.h
 #include part_efi.h
 #include exports.h
 #include linux/ctype.h
@@ -134,7 +133,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
 
-   debug(%s: MMC lba num: 0x%x %d\n, __func__,
+   debug(%s:  lba num: 0x%x %d\n, __func__,
  (unsigned int)dev_desc-lba, (unsigned int)dev_desc-lba);
 
if (str_part == NULL)
@@ -247,25 +246,18 @@ err:
return errno;
 }
 
-static int gpt_mmc_default(int dev, const char *str_part)
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
 {
int ret;
char *str_disk_guid;
u8 part_count = 0;
disk_partition_t *partitions = NULL;
 
-   struct mmc *mmc = find_mmc_device(dev);
-
-   if (mmc == NULL) {
-   printf(%s: mmc dev %d NOT available\n, __func__, dev);
-   return CMD_RET_FAILURE;
-   }
-
if (!str_part)
return -1;
 
/* fill partitions */
-   ret = set_gpt_info(mmc-block_dev, str_part,
+   ret = set_gpt_info(blk_dev_desc, str_part,
str_disk_guid, partitions, part_count);
if (ret) {
if (ret == -1)
@@ -278,7 +270,7 @@ static int gpt_mmc_default(int dev, const char *str_part)
}
 
/* save partitions layout to disk */
-   gpt_restore(mmc-block_dev, str_disk_guid, partitions, part_count);
+   gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
free(str_disk_guid);
free(partitions);
 
@@ -306,20 +298,21 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 
/* command: 'write' */
if ((strcmp(argv[1], write) == 0)  (argc == 5)) {
-   /* device: 'mmc' */
-   if (strcmp(argv[2], mmc) == 0) {
-   /* check if 'dev' is a number */
-   for (pstr = argv[3]; *pstr != '\0'; pstr++)
-   if (!isdigit(*pstr)) {
-   printf('%s' is not a number\n,
-   argv[3]);
-   return CMD_RET_USAGE;
-   }
-   dev = (int)simple_strtoul(argv[3], NULL, 10);
-   /* write to mmc */
-   if (gpt_mmc_default(dev, argv[4]))
-   return CMD_RET_FAILURE;
+   char *ep;
+   block_dev_desc_t *blk_dev_desc;
+   dev = (int)simple_strtoul(argv[3], NULL, 10);
+   if (*ep) {
+   printf('%s' is not a number\n, argv[3]);
+   return CMD_RET_USAGE;
}
+   blk_dev_desc = get_dev(argv[2], dev);
+   if (!blk_dev_desc) {
+   printf(%s: %s dev %d NOT available\n, __func__, 
argv[2], dev);
+   return CMD_RET_FAILURE;
+   }
+
+   if (gpt_default(blk_dev_desc, argv[4]))
+   return CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}
-- 
1.7.7

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 0/5] Add Support for Storage Devices with Blocksizes != 512.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/5] disk/gpt: Fix GPT Partition handling for Blocksize != 512.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH 2/5] disk/iso: Add Support for Block Sizes 512 Byte to ISO partition support.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/5] fs/fat: Don't multiply fatsize with sector size.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@suse.com

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

Signed-off-by: Egbert Eich e...@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

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 4/5] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH 5/5] fs/ext4: Support device block sizes != 512 bytes.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH] cmd/gpt: Support gpt command for all devices.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@suse.com

The gpt command was only implemented for mmc devices. There is no reason
why this command should not be generalized and be applied all other
storage device classes.
This change both simplifies the implementation and eliminates a
build failure for systems that don't support mmcs.

Signed-off-by: Egbert Eich e...@suse.com
---
 common/cmd_gpt.c |   43 ++-
 1 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index efd7934..1a72e8e 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -23,7 +23,6 @@
 #include common.h
 #include malloc.h
 #include command.h
-#include mmc.h
 #include part_efi.h
 #include exports.h
 #include linux/ctype.h
@@ -134,7 +133,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
 
-   debug(%s: MMC lba num: 0x%x %d\n, __func__,
+   debug(%s:  lba num: 0x%x %d\n, __func__,
  (unsigned int)dev_desc-lba, (unsigned int)dev_desc-lba);
 
if (str_part == NULL)
@@ -247,25 +246,18 @@ err:
return errno;
 }
 
-static int gpt_mmc_default(int dev, const char *str_part)
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
 {
int ret;
char *str_disk_guid;
u8 part_count = 0;
disk_partition_t *partitions = NULL;
 
-   struct mmc *mmc = find_mmc_device(dev);
-
-   if (mmc == NULL) {
-   printf(%s: mmc dev %d NOT available\n, __func__, dev);
-   return CMD_RET_FAILURE;
-   }
-
if (!str_part)
return -1;
 
/* fill partitions */
-   ret = set_gpt_info(mmc-block_dev, str_part,
+   ret = set_gpt_info(blk_dev_desc, str_part,
str_disk_guid, partitions, part_count);
if (ret) {
if (ret == -1)
@@ -278,7 +270,7 @@ static int gpt_mmc_default(int dev, const char *str_part)
}
 
/* save partitions layout to disk */
-   gpt_restore(mmc-block_dev, str_disk_guid, partitions, part_count);
+   gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
free(str_disk_guid);
free(partitions);
 
@@ -306,20 +298,21 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 
/* command: 'write' */
if ((strcmp(argv[1], write) == 0)  (argc == 5)) {
-   /* device: 'mmc' */
-   if (strcmp(argv[2], mmc) == 0) {
-   /* check if 'dev' is a number */
-   for (pstr = argv[3]; *pstr != '\0'; pstr++)
-   if (!isdigit(*pstr)) {
-   printf('%s' is not a number\n,
-   argv[3]);
-   return CMD_RET_USAGE;
-   }
-   dev = (int)simple_strtoul(argv[3], NULL, 10);
-   /* write to mmc */
-   if (gpt_mmc_default(dev, argv[4]))
-   return CMD_RET_FAILURE;
+   char *ep;
+   block_dev_desc_t *blk_dev_desc;
+   dev = (int)simple_strtoul(argv[3], NULL, 10);
+   if (*ep) {
+   printf('%s' is not a number\n, argv[3]);
+   return CMD_RET_USAGE;
}
+   blk_dev_desc = get_dev(argv[2], dev);
+   if (!blk_dev_desc) {
+   printf(%s: %s dev %d NOT available\n, __func__, 
argv[2], dev);
+   return CMD_RET_FAILURE;
+   }
+
+   if (gpt_default(blk_dev_desc, argv[4]))
+   return CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}
-- 
1.7.7

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] disk: part_dos: check harder for partition table.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@suse.com

Devices that used to have a whole disk FAT filesystem but got then
partitioned will most likely still have a FAT or FAT32 signature
in the first sector as this sector does not get overwritten by
a partitioning tool (otherwise the tool would risk to kill the mbr).

The current partition search algorithm will erronosly detect such
a device as a raw FAT device.

Instead of looking for the FAT or FAT32 signatures immediately we
use the same algorithm as used by the Linux kernel and first check
for a valid boot indicator flag on each of the 4 partitions.
If the value of this flag is invalid for the first entry we then
do the raw partition check.
If the flag for any higher partition is wrong we assume the device
is neiter a MBR nor PBR device.

Signed-off-by: Egbert Eich e...@suse.com
---
 disk/part_dos.c |   16 +---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 37087a6..8a23495 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -74,13 +74,23 @@ static void print_one_part(dos_partition_t *p, int 
ext_part_sector,
 
 static int test_block_type(unsigned char *buffer)
 {
+   int slot;
+   struct dos_partition *p;
+
if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
(buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
return (-1);
} /* no DOS Signature at all */
-   if (strncmp((char *)buffer[DOS_PBR_FSTYPE_OFFSET],FAT,3)==0 ||
-   strncmp((char *)buffer[DOS_PBR32_FSTYPE_OFFSET],FAT32,5)==0) {
-   return DOS_PBR; /* is PBR */
+   p = ( struct dos_partition *)buffer[DOS_PART_TBL_OFFSET];
+   for (slot = 0; slot  3; slot++) {
+   if (p-boot_ind != 0  p-boot_ind != 0x80) {
+   if (!slot 
+   (strncmp((char 
*)buffer[DOS_PBR_FSTYPE_OFFSET],FAT,3)==0 ||
+strncmp((char 
*)buffer[DOS_PBR32_FSTYPE_OFFSET],FAT32,5)==0)) {
+   return DOS_PBR; /* is PBR */
+   } else
+   return -1;
+   }
}
return DOS_MBR; /* Is MBR */
 }
-- 
1.7.7

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2] fs/ext4: Support device block sizes != 512 bytes.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH v2] disk/gpt: Fix GPT Partition handling for Blocksize != 512.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH v2] part/dev_desc: Add log2 of Blocksize to block_dev_desc data struct.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@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 e...@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

[U-Boot] [PATCH v2] cmd/gpt: Support gpt command for all devices.

2013-03-26 Thread egbert . eich
From: Egbert Eich e...@suse.com

The gpt command was only implemented for mmc devices. There is no reason
why this command should not be generalized and be applied all other
storage device classes.
This change both simplifies the implementation and eliminates a
build failure for systems that don't support mmcs.

Signed-off-by: Egbert Eich e...@suse.com
---
 common/cmd_gpt.c |   44 +++-
 1 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index efd7934..3594dca 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -23,7 +23,6 @@
 #include common.h
 #include malloc.h
 #include command.h
-#include mmc.h
 #include part_efi.h
 #include exports.h
 #include linux/ctype.h
@@ -134,7 +133,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
 
-   debug(%s: MMC lba num: 0x%x %d\n, __func__,
+   debug(%s:  lba num: 0x%x %d\n, __func__,
  (unsigned int)dev_desc-lba, (unsigned int)dev_desc-lba);
 
if (str_part == NULL)
@@ -247,25 +246,18 @@ err:
return errno;
 }
 
-static int gpt_mmc_default(int dev, const char *str_part)
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
 {
int ret;
char *str_disk_guid;
u8 part_count = 0;
disk_partition_t *partitions = NULL;
 
-   struct mmc *mmc = find_mmc_device(dev);
-
-   if (mmc == NULL) {
-   printf(%s: mmc dev %d NOT available\n, __func__, dev);
-   return CMD_RET_FAILURE;
-   }
-
if (!str_part)
return -1;
 
/* fill partitions */
-   ret = set_gpt_info(mmc-block_dev, str_part,
+   ret = set_gpt_info(blk_dev_desc, str_part,
str_disk_guid, partitions, part_count);
if (ret) {
if (ret == -1)
@@ -278,7 +270,7 @@ static int gpt_mmc_default(int dev, const char *str_part)
}
 
/* save partitions layout to disk */
-   gpt_restore(mmc-block_dev, str_disk_guid, partitions, part_count);
+   gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
free(str_disk_guid);
free(partitions);
 
@@ -306,20 +298,22 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 
/* command: 'write' */
if ((strcmp(argv[1], write) == 0)  (argc == 5)) {
-   /* device: 'mmc' */
-   if (strcmp(argv[2], mmc) == 0) {
-   /* check if 'dev' is a number */
-   for (pstr = argv[3]; *pstr != '\0'; pstr++)
-   if (!isdigit(*pstr)) {
-   printf('%s' is not a number\n,
-   argv[3]);
-   return CMD_RET_USAGE;
-   }
-   dev = (int)simple_strtoul(argv[3], NULL, 10);
-   /* write to mmc */
-   if (gpt_mmc_default(dev, argv[4]))
-   return CMD_RET_FAILURE;
+   char *ep;
+   block_dev_desc_t *blk_dev_desc;
+   dev = (int)simple_strtoul(argv[3], NULL, 10);
+   if (*ep) {
+   printf('%s' is not a number\n, argv[3]);
+   return CMD_RET_USAGE;
}
+   blk_dev_desc = get_dev(argv[2], dev);
+   if (!blk_dev_desc) {
+   printf(%s: %s dev %d NOT available\n,
+  __func__, argv[2], dev);
+   return CMD_RET_FAILURE;
+   }
+
+   if (gpt_default(blk_dev_desc, argv[4]))
+   return CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}
-- 
1.7.7

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] disk/part_dos: check harder for partition table

2013-03-26 Thread Egbert Eich
From: Egbert Eich e...@suse.com

Devices that used to have a whole disk FAT filesystem but got then
partitioned will most likely still have a FAT or FAT32 signature
in the first sector as this sector does not get overwritten by
a partitioning tool (otherwise the tool would risk to kill the mbr).

The current partition search algorithm will erronously detect such
a device as a raw FAT device.

Instead of looking for the FAT or FAT32 signatures immediately we
use the same algorithm as used by the Linux kernel and first check
for a valid boot indicator flag on each of the 4 partitions.
If the value of this flag is invalid for the first entry we then
do the raw partition check.
If the flag for any higher partition is wrong we assume the device
is neiter a MBR nor PBR device.

v2: Coding style cleanup.

Signed-off-by: Egbert Eich e...@suse.com
---
 disk/part_dos.c |   18 +++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 37087a6..3fc8564 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -74,13 +74,25 @@ static void print_one_part(dos_partition_t *p, int 
ext_part_sector,
 
 static int test_block_type(unsigned char *buffer)
 {
+   int slot;
+   struct dos_partition *p;
+
if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
(buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
return (-1);
} /* no DOS Signature at all */
-   if (strncmp((char *)buffer[DOS_PBR_FSTYPE_OFFSET],FAT,3)==0 ||
-   strncmp((char *)buffer[DOS_PBR32_FSTYPE_OFFSET],FAT32,5)==0) {
-   return DOS_PBR; /* is PBR */
+   p = (struct dos_partition *)buffer[DOS_PART_TBL_OFFSET];
+   for (slot = 0; slot  3; slot++) {
+   if (p-boot_ind != 0  p-boot_ind != 0x80) {
+   if (!slot 
+   (strncmp((char *)buffer[DOS_PBR_FSTYPE_OFFSET],
+FAT, 3) == 0 ||
+strncmp((char *)buffer[DOS_PBR32_FSTYPE_OFFSET],
+FAT32, 5) == 0)) {
+   return DOS_PBR; /* is PBR */
+   } else
+   return -1;
+   }
}
return DOS_MBR; /* Is MBR */
 }
-- 
1.7.7

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot