From patchwork Tue Mar 26 12:03:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: egbert.eich@gmail.com X-Patchwork-Id: 231199 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 624042C0091 for ; Wed, 27 Mar 2013 00:26:46 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 14CAE4A0AE; Tue, 26 Mar 2013 14:26:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DY5IaVUXoEZ3; Tue, 26 Mar 2013 14:26:20 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EB9E24A0F3; Tue, 26 Mar 2013 14:25:56 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C77B34A0AA for ; Tue, 26 Mar 2013 14:21:27 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XxB+HEuGmMC6 for ; Tue, 26 Mar 2013 14:21:26 +0100 (CET) X-Greylist: delayed 1619 seconds by postgrey-1.27 at theia; Tue, 26 Mar 2013 14:21:24 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ee0-f48.google.com (mail-ee0-f48.google.com [74.125.83.48]) by theia.denx.de (Postfix) with ESMTPS id 133DC4A0A9 for ; Tue, 26 Mar 2013 14:21:24 +0100 (CET) Received: by mail-ee0-f48.google.com with SMTP id b15so876159eek.35 for ; Tue, 26 Mar 2013 06:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ZluQOL6U/n/3RtCApsRFxrRDUMCGUSDBeaVAeoRsmJM=; b=J1pZ7M/Fe31dfH1pepLrv2h/DUSfMsMhhWVOulBWipOZYIw4TKItCOUDJu9oB+Xf8N uW569cOjtUUIPR8QM2Gf9tyW6LvzuCF4hNwNj84hfCRAG2kA2BMv7L1WKttDbHuvCNVK 20zwPiZ9MPE0Qkfp0kzf1H/ahTnE2gdH55uFI8+9pgDLJl1e5e8p/d3/CMPlwkhZnHwX z86Wld2b4cPHxxCuqq5AioWm+QIVK4IsWVAK86LiumBUqiluyATQ0TSC1abdtOITmQ0A /ozLf0rmYTXZgEU/DyCdZyKGlmkVaROmfWdIXukixBpKn8yMgFkuw54xZAHrtFu1v+LS yg7g== X-Received: by 10.15.111.202 with SMTP id cj50mr4745149eeb.6.1364302605189; Tue, 26 Mar 2013 05:56:45 -0700 (PDT) Received: from debian (p5DCF07C5.dip0.t-ipconnect.de. [93.207.7.197]) by mx.google.com with ESMTPS id d47sm24880977eem.9.2013.03.26.05.56.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Mar 2013 05:56:44 -0700 (PDT) Received: from sles11.fritz.box (sles11.fritz.box [192.168.178.22]) by debian (Postfix) with ESMTP id 28F9E3EB73; Tue, 26 Mar 2013 13:56:42 +0100 (CET) From: egbert.eich@gmail.com To: u-boot@lists.denx.de Date: Tue, 26 Mar 2013 08:03:45 -0400 Message-Id: <1364299425-24778-1-git-send-email-egbert.eich@gmail.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <20130326113056.E287B20063E@gemini.denx.de> References: <20130326113056.E287B20063E@gemini.denx.de> X-Mailman-Approved-At: Tue, 26 Mar 2013 14:25:51 +0100 Cc: Egbert Eich Subject: [U-Boot] [PATCH v2] disk/gpt: Fix GPT Partition handling for Blocksize != 512. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Egbert Eich 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 --- 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 {