From patchwork Wed Nov 30 11:01:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 700966 X-Patchwork-Delegate: scottwood@freescale.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 3tTHZ20cHvz9tl4 for ; Wed, 30 Nov 2016 22:02:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="znm/yISQ"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B3994A7600; Wed, 30 Nov 2016 12:02:32 +0100 (CET) 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 XSW6n98FyttY; Wed, 30 Nov 2016 12:02:32 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F8DBA75CC; Wed, 30 Nov 2016 12:02:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 48B74A75CC for ; Wed, 30 Nov 2016 12:02:29 +0100 (CET) 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 5G5KwU7ZrCP8 for ; Wed, 30 Nov 2016 12:02:29 +0100 (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-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by theia.denx.de (Postfix) with ESMTPS id 08F74A7580 for ; Wed, 30 Nov 2016 12:02:26 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id g23so28886492wme.1 for ; Wed, 30 Nov 2016 03:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4l/9r+VfuiTLUhAgE8ILZ2CId8WtRl/OSE4zRb9kixU=; b=znm/yISQEV6iyPXNVhGLMppIf10Tr6HPrCnnOGdNng1HW7h6QcK0hJmMeTa2rwabNY 0mCeqg5J2dqd/7PRv3Rz6T9+TF5LibkTQ25+h2Q3jytpvcLMyqpJ1y73OYlu4sNc53WM D3efFqrfR2yuDYiujgYUKLmEE80uXwYLmYI/iHN7WGfyoUnv9vDOfHWHxvKkFBiki/Rm f+fUtaQqqd2RkAaAf4HY4LAt1C+Z8oZ7fKdRCR/KHyb90wgGAM5kmx/QPEEsScVKZZ/l 2VKjMSe//Q8VknxH/ffhKceSe6cgxb5lIw5a8h9jGC8m2zRs6jn//JtznNFjbOD07lyJ YBEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4l/9r+VfuiTLUhAgE8ILZ2CId8WtRl/OSE4zRb9kixU=; b=StxVFBQQuMGpAcNO6M6f60wBzCmtSRWor50DM0x6i8YQYxh8a5fs04MyseOsZ78lIW H09OI3rhO0Uj48Jkb0IFZi6BkdHULMTT5XYU+1qKhMWHl9sZJsR48jeTR3n4ZK+Mdtok 3g2LFOW5dN1XtajpL5Q8BAD/1AlgBOZgOBGGx9iy95FitzQgq6w+ZXQrPBTKRYefM/go y+eSSUs4TSJq6RR7v/hVZ2RI7hNLy5l1wkJ2ELdXTIoWa7ILFMd5EgbvDHrIs/CvQ03Q Wk29nMat3qCVm4kg8d4+m4hj4tDUD9vmvTFc36j1hD/HzbUH05nYRZuSPxWHMXgtC4/h kppw== X-Gm-Message-State: AKaTC02hNVVl4s22u4ZxrtlT906vpxRBfEDvRhSgs62orOYG2kL73OBEkYYPVelywfVdMg== X-Received: by 10.28.147.81 with SMTP id v78mr30041219wmd.60.1480503745593; Wed, 30 Nov 2016 03:02:25 -0800 (PST) Received: from lmenx29a.st.com. ([37.167.0.81]) by smtp.gmail.com with ESMTPSA id ba10sm72300835wjb.32.2016.11.30.03.02.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Nov 2016 03:02:25 -0800 (PST) From: Patrick Delaunay To: u-boot@lists.denx.de Date: Wed, 30 Nov 2016 12:01:22 +0100 Message-Id: <1480503692-17255-3-git-send-email-patrick.delaunay73@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480503692-17255-1-git-send-email-patrick.delaunay73@gmail.com> References: <1480503692-17255-1-git-send-email-patrick.delaunay73@gmail.com> Cc: Ben Whitten , Franck Albesa , Stephen Warren , Patrick Delaunay , Gerald Baeza , Patrick Delaunay Subject: [U-Boot] [RFC PATCH v2 2/8] disk: part: refactor to prepare GPT over MTD X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Patrick Delaunay - udpate prepare_backup_gpt_header(): calculate partition_entry_lba and no more assumed last lba + 1 - split part_print_efi : create sub-functions part_print_gpt() part_get_disk_info() Signed-off-by: Patrick Delaunay Signed-off-by: Patrick Delaunay --- Changes in v2: None disk/part_efi.c | 115 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 1924338..a23c8ea 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -10,6 +10,7 @@ * when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this * limits the maximum size of addressable storage to < 2 Terra Bytes */ + #include #include #include @@ -159,11 +160,12 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h) uint64_t val; /* recalculate the values for the Backup GPT Header */ - val = le64_to_cpu(gpt_h->my_lba); - gpt_h->my_lba = gpt_h->alternate_lba; - gpt_h->alternate_lba = cpu_to_le64(val); - gpt_h->partition_entry_lba = - cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); + val = le64_to_cpu(gpt_h->alternate_lba); + gpt_h->alternate_lba = gpt_h->my_lba; + gpt_h->my_lba = cpu_to_le64(val); + val -= (le32_to_cpu(gpt_h->num_partition_entries) * + le32_to_cpu(gpt_h->sizeof_partition_entry)); + gpt_h->partition_entry_lba = cpu_to_le64(val); gpt_h->header_crc32 = 0; calc_crc32 = efi_crc32((const unsigned char *)gpt_h, @@ -171,36 +173,16 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h) gpt_h->header_crc32 = cpu_to_le32(calc_crc32); } + #ifdef CONFIG_EFI_PARTITION -/* - * Public Functions (include/part.h) - */ -void part_print_efi(struct blk_desc *dev_desc) +static void part_print_gpt(gpt_header *gpt_head, + gpt_entry *gpt_pte) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); - gpt_entry *gpt_pte = NULL; int i = 0; char uuid[37]; unsigned char *uuid_bin; - /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid Backup GPT ***\n", - __func__); - return; - } else { - printf("%s: *** Using Backup GPT ***\n", - __func__); - } - } - - debug("%s: gpt-entry at %p\n", __func__, gpt_pte); - printf("Part\tStart LBA\tEnd LBA\t\tName\n"); printf("\tAttributes\n"); printf("\tType GUID\n"); @@ -227,6 +209,60 @@ void part_print_efi(struct blk_desc *dev_desc) uuid_bin_to_str(uuid_bin, uuid, UUID_STR_FORMAT_GUID); printf("\tguid:\t%s\n", uuid); } +} + +static void part_get_disk_info(int part, unsigned int blksz, + gpt_entry *gpt_pte, disk_partition_t *info) +{ + /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */ + info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); + /* The ending LBA is inclusive, to calculate size, add 1 to it */ + info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 + - info->start; + info->blksz = blksz; + + sprintf((char *)info->name, "%s", print_efiname(&gpt_pte[part - 1])); + strcpy((char *)info->type, "U-Boot"); + info->bootable = is_bootable(&gpt_pte[part - 1]); +#ifdef CONFIG_PARTITION_UUIDS + uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, + UUID_STR_FORMAT_GUID); +#endif +#ifdef CONFIG_PARTITION_TYPE_GUID + uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, + info->type_guid, UUID_STR_FORMAT_GUID); +#endif + + debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__, + info->start, info->size, info->name); +} + +/* + * Public Functions (include/part.h) + */ +void part_print_efi(struct blk_desc *dev_desc) +{ + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); + gpt_entry *gpt_pte = NULL; + + /* This function validates AND fills in the GPT header and PTE */ + if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, + gpt_head, &gpt_pte) != 1) { + printf("%s: *** ERROR: Invalid GPT ***\n", __func__); + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), + gpt_head, &gpt_pte) != 1) { + printf("%s: *** ERROR: Invalid Backup GPT ***\n", + __func__); + return; + } else { + printf("%s: *** Using Backup GPT ***\n", + __func__); + } + } + + debug("%s: gpt-entry at %p\n", __func__, gpt_pte); + + part_print_gpt(gpt_head, gpt_pte); /* Remember to free pte */ free(gpt_pte); @@ -268,28 +304,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, return -1; } - /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */ - info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); - /* The ending LBA is inclusive, to calculate size, add 1 to it */ - info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 - - info->start; - info->blksz = dev_desc->blksz; - - sprintf((char *)info->name, "%s", - print_efiname(&gpt_pte[part - 1])); - strcpy((char *)info->type, "U-Boot"); - info->bootable = is_bootable(&gpt_pte[part - 1]); -#ifdef CONFIG_PARTITION_UUIDS - uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, - UUID_STR_FORMAT_GUID); -#endif -#ifdef CONFIG_PARTITION_TYPE_GUID - uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, - info->type_guid, UUID_STR_FORMAT_GUID); -#endif - - debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__, - info->start, info->size, info->name); + part_get_disk_info(part, dev_desc->blksz, gpt_pte, info); /* Remember to free pte */ free(gpt_pte);