From patchwork Mon Oct 10 08:44:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Smith X-Patchwork-Id: 680248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sstzv01Gjz9ryT for ; Mon, 10 Oct 2016 19:47:39 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sstzt6NpXzDsx5 for ; Mon, 10 Oct 2016 19:47:38 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sstwT71xqzDsj4 for ; Mon, 10 Oct 2016 19:44:41 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9A8WbHr071712 for ; Mon, 10 Oct 2016 04:44:39 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 26050rysvp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 10 Oct 2016 04:44:39 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Oct 2016 02:44:38 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 10 Oct 2016 02:44:38 -0600 Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 3963519D801C for ; Mon, 10 Oct 2016 02:44:04 -0600 (MDT) Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9A8ib8s15401340; Mon, 10 Oct 2016 08:44:37 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9F0AAE034; Mon, 10 Oct 2016 04:44:36 -0400 (EDT) Received: from birb.localdomain (unknown [9.81.212.138]) by b01ledav005.gho.pok.ibm.com (Postfix) with SMTP id AC2E3AE03C; Mon, 10 Oct 2016 04:44:35 -0400 (EDT) Received: by birb.localdomain (Postfix, from userid 1000) id 4A175233520A; Mon, 10 Oct 2016 19:44:25 +1100 (AEDT) From: Stewart Smith To: skiboot@lists.ozlabs.org, cclaudio@linux.vnet.ibm.com Date: Mon, 10 Oct 2016 19:44:08 +1100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476089061-15197-1-git-send-email-stewart@linux.vnet.ibm.com> References: <1476089061-15197-1-git-send-email-stewart@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16101008-0012-0000-0000-000010D8A124 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005885; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000186; SDB=6.00766372; UDB=6.00366538; IPR=6.00542488; BA=6.00004798; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012933; XFM=3.00000011; UTC=2016-10-10 08:44:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16101008-0013-0000-0000-0000462D40B7 Message-Id: <1476089061-15197-28-git-send-email-stewart@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-10_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610100142 Subject: [Skiboot] [PATCH 27/40] core: add flash_subpart_info() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" From: Claudio Carvalho Currently, the CAPP lid has the TOC (4K) and one supartition (36K). For secure boot we can either build one container for the TOC and another one for the subpartition, or build one container for the whole CAPP partition. We decided implement the second option. The first option would require changes to the CAPP TOC layout in order to correlate the TOC with the subpartitions. Besides that, the first option also increases the boot time since we would need to verify and measure the CAPP TOC. This patch adds the flash_subpart_info function so the correct CAPP subpartition can be selected also outside of the flash API. Signed-off-by: Claudio Carvalho Signed-off-by: Stewart Smith --- core/flash.c | 144 +++++++++++++++++++++++++++++++----------------------- include/skiboot.h | 4 +- 2 files changed, 86 insertions(+), 62 deletions(-) diff --git a/core/flash.c b/core/flash.c index 0424479..24c34cf 100644 --- a/core/flash.c +++ b/core/flash.c @@ -457,8 +457,7 @@ static int flash_find_subpartition(struct blocklevel_device *bl, uint32_t subid, bool ecc) { struct flash_hostboot_header *header; - char eyecatcher[5]; - uint32_t i, partsize; + uint32_t partsize, offset, size; int rc; header = malloc(FLASH_SUBPART_HEADER_SIZE); @@ -478,66 +477,19 @@ static int flash_find_subpartition(struct blocklevel_device *bl, uint32_t subid, goto end; } - /* Perform sanity */ - i = be32_to_cpu(header->version); - if (i != 1) { - prerror("FLASH: flash subpartition TOC version unknown %i\n", i); - rc = OPAL_RESOURCE; + rc = flash_subpart_info(header, partsize, subid, &offset, &size); + if (rc) goto end; - } - /* NULL terminate eyecatcher */ - strncpy(eyecatcher, header->eyecatcher, 4); - eyecatcher[4] = 0; - prlog(PR_DEBUG, "FLASH: flash subpartition eyecatcher %s\n", - eyecatcher); - - rc = OPAL_RESOURCE; - for (i = 0; i< FLASH_HOSTBOOT_TOC_MAX_ENTRIES; i++) { - uint32_t ec, offset, size; - - ec = be32_to_cpu(header->toc[i].ec); - offset = be32_to_cpu(header->toc[i].offset); - size = be32_to_cpu(header->toc[i].size); - /* Check for null terminating entry */ - if (!ec && !offset && !size) { - prerror("FLASH: flash subpartition not found.\n"); - goto end; - } - - if (ec != subid) - continue; - /* Sanity check the offset and size. */ - if (offset + size > partsize) { - prerror("FLASH: flash subpartition too big: %i\n", i); - goto end; - } - if (!size) { - prerror("FLASH: flash subpartition zero size: %i\n", i); - goto end; - } - if (offset < FLASH_SUBPART_HEADER_SIZE) { - prerror("FLASH: flash subpartition " - "offset too small: %i\n", i); - goto end; - } - - prlog(PR_DEBUG, "FLASH: flash found subpartition: " - "%i size: %i offset %i\n", - i, size, offset); - - /* - * Adjust the start and size. The start location in the needs - * to account for ecc but the size doesn't. - */ - *start += offset; - *total_size = size; - if (ecc) { - *start += ecc_size(offset); - *total_size += ecc_size(size); - } - rc = 0; - goto end; + /* + * Adjust the start and size. The start location in the needs + * to account for ecc but the size doesn't. + */ + *start += offset; + *total_size = size; + if (ecc) { + *start += ecc_size(offset); + *total_size += ecc_size(size); } end: @@ -651,7 +603,7 @@ static int flash_load_resource(enum resource_id id, uint32_t subid, rc = flash_read_corrected(flash->bl, part_start, buf, size, ecc); if (rc) { - prerror("FLASH: failed to read %s partition\n", name); + prerror("FLASH: failed to read %s partition, rc %d\n", name, rc); goto out_free_ffs; } @@ -779,3 +731,73 @@ int flash_start_preload_resource(enum resource_id id, uint32_t subid, return OPAL_SUCCESS; } + +int flash_subpart_info(void *part_header, uint32_t part_size, uint32_t subid, + uint32_t *offset, uint32_t *size) +{ + struct flash_hostboot_header *header; + char eyecatcher[5]; + uint32_t i, ec; + + if (!part_header || !offset || !size) { + prlog(PR_ERR, "FLASH: invalid parameters: " + "ph %p of %p sz %p\n", part_header, offset, size); + return OPAL_PARAMETER; + } + + header = (struct flash_hostboot_header*) part_header; + + /* Perform sanity */ + i = be32_to_cpu(header->version); + if (i != 1) { + prerror("FLASH: flash subpartition TOC version unknown %i\n", i); + goto end; + } + + /* NULL terminate eyecatcher */ + strncpy(eyecatcher, header->eyecatcher, 4); + eyecatcher[4] = '\0'; + prlog(PR_DEBUG, "FLASH: flash subpartition eyecatcher %s\n", + eyecatcher); + + for (i = 0; i < FLASH_HOSTBOOT_TOC_MAX_ENTRIES; i++) { + + ec = be32_to_cpu(header->toc[i].ec); + *offset = be32_to_cpu(header->toc[i].offset); + *size = be32_to_cpu(header->toc[i].size); + + /* Check for null terminating entry */ + if (!ec && !*offset && !*size) { + prerror("FLASH: flash subpartition not found.\n"); + goto end; + } + + if (ec != subid) + continue; + + /* Sanity check the offset and size. */ + if (*offset + *size > part_size) { + prerror("FLASH: flash subpartition too big: %i\n", i); + goto end; + } + if (!*size) { + prerror("FLASH: flash subpartition zero size: %i\n", i); + goto end; + } + if (*offset < FLASH_SUBPART_HEADER_SIZE) { + prerror("FLASH: flash subpartition " + "offset too small: %i\n", i); + goto end; + } + + prlog(PR_DEBUG, "FLASH: flash found subpartition: " + "%i size: %i offset %i\n", + i, *size, *offset); + + return OPAL_SUCCESS; + } +end: + *size = 0; + *offset = 0; + return OPAL_RESOURCE; +} diff --git a/include/skiboot.h b/include/skiboot.h index 52a235b..2a9f5e2 100644 --- a/include/skiboot.h +++ b/include/skiboot.h @@ -223,7 +223,9 @@ extern int flash_start_preload_resource(enum resource_id id, uint32_t subid, extern int flash_resource_loaded(enum resource_id id, uint32_t idx); extern bool flash_reserve(void); extern void flash_release(void); - +extern int flash_subpart_info(void *part_header, uint32_t part_size, + uint32_t subid, uint32_t *offset, + uint32_t *size); /* NVRAM support */ extern void nvram_init(void);