From patchwork Wed Jun 26 12:32:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1123046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Yys02VvGz9s3C for ; Thu, 27 Jun 2019 08:49:40 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="sVRB2S0m"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45Yyrz75WtzDqWJ for ; Thu, 27 Jun 2019 08:49:39 +1000 (AEST) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="sVRB2S0m"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (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 45YjLY1pt5zDqWg for ; Wed, 26 Jun 2019 22:40:52 +1000 (AEST) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 956B7418A4 for ; Wed, 26 Jun 2019 12:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1561552331; x= 1563366732; bh=A0VrGb3PS61ahp4V0VpSz8akTMMIvJSE7hrX8RUx3vQ=; b=s VRB2S0mcvEPmMczx0rHZlcR/WUeNaopeYncvZWeADLa1lvQTBW37nDbZPhfz1bzx YcjCHHFZk4FqOgTDM4Qe61ZOh4v4k3KnDqy5d/50pq6MSn0u0X36utunsY3vftoC /U3CLTXDd9cq/Om8UsTAg8lYXz4IFbf1uMp0qW17aY= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hz7kkRqsPgKK for ; Wed, 26 Jun 2019 15:32:11 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id F3E67411FF for ; Wed, 26 Jun 2019 15:32:10 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Wed, 26 Jun 2019 15:32:10 +0300 Date: Wed, 26 Jun 2019 15:32:10 +0300 From: Maxim Polyakov To: Subject: [PATCH 4/5] discover/platform-powerpc: add mailbox message structure Message-ID: <20190626123209.GA16280@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-Mailman-Approved-At: Thu, 27 Jun 2019 08:48:55 +1000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Use structure for the IPMI response mailbox message instead of raw byte array as its done in the ipmitool utility: https://github.com/ipmitool/ipmitool/commit/62a04390e10f8e62ce16b7bc95bf6ced419b80eb Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 83 ++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index c874560..6500058 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -22,6 +22,29 @@ #include "ipmi.h" #include "dt.h" +#define CHASSIS_BOOT_MBOX_IANA_SZ 3 +#define CHASSIS_BOOT_MBOX_DATA_SZ 16 +#define CHASSIS_BOOT_MBOX_BLOCK0_DATA_SZ \ + (CHASSIS_BOOT_MBOX_DATA_SZ - CHASSIS_BOOT_MBOX_IANA_SZ) + +typedef struct __attribute__((packed)) { + uint8_t iana[CHASSIS_BOOT_MBOX_IANA_SZ]; + uint8_t data[CHASSIS_BOOT_MBOX_BLOCK0_DATA_SZ]; +} mbox_block0_t; + +typedef union { + uint8_t data[CHASSIS_BOOT_MBOX_DATA_SZ]; + mbox_block0_t b0; +} mbox_t; + +typedef struct __attribute__((packed)) { + uint8_t cc; + uint8_t param_version; + uint8_t param_valid; + uint8_t block_selector; + mbox_t mbox; +} ipmi_mbox_response_t; + static const char *partition = "common"; static const char *sysparams_dir = "/sys/firmware/opal/sysparams/"; static const char *devtree_dir = "/proc/device-tree/"; @@ -437,10 +460,10 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform, } static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, - char *buf, uint8_t block) + mbox_t *mailbox, uint8_t block) { size_t blocksize = 16; - uint8_t resp[3 + 1 + 16]; + ipmi_mbox_response_t ipmi_mbox_resp = { .cc = 0xFF }; uint16_t resp_len; char *debug_buf; int rc; @@ -449,59 +472,60 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, block, /* set selector */ 0x00, /* no block selector */ }; + size_t ipmi_header_len = sizeof(ipmi_mbox_response_t) - sizeof(mbox_t); - resp_len = sizeof(resp); + resp_len = sizeof(ipmi_mbox_response_t); rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS, IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS, req, sizeof(req), - resp, &resp_len, + (uint8_t*)&ipmi_mbox_resp, &resp_len, ipmi_timeout); if (rc) { pb_log("platform: error reading IPMI boot options\n"); return -1; } - if (resp_len > sizeof(resp)) { + if (resp_len > sizeof(ipmi_mbox_response_t)) { pb_debug("platform: invalid mailbox response size!\n"); return -1; } - if (resp_len < 4) { + if (resp_len < ipmi_header_len) { pb_log("platform: unexpected length (%d) in " "boot options mailbox response\n", resp_len); return -1; } - blocksize = resp_len - 4; + blocksize = resp_len - ipmi_header_len; pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", block, blocksize); - debug_buf = format_buffer(platform, resp, resp_len); + debug_buf = format_buffer(platform, (uint8_t*)&ipmi_mbox_resp, resp_len); pb_debug_fn("IPMI bootdev mailbox block %hu:\n%s\n", block, debug_buf); talloc_free(debug_buf); - if (resp[0] != 0) { + if (ipmi_mbox_resp.cc != 0) { pb_log("platform: non-zero completion code %d from IPMI req\n", - resp[0]); + ipmi_mbox_resp.cc); return -1; } /* check for correct parameter version */ - if ((resp[1] & 0xf) != 0x1) { + if ((ipmi_mbox_resp.param_version & 0xf) != 0x1) { pb_log("platform: unexpected version (0x%x) in " - "boot mailbox response\n", resp[0]); + "boot mailbox response\n", ipmi_mbox_resp.param_version); return -1; } /* check for valid paramters */ - if (resp[2] & 0x80) { + if (ipmi_mbox_resp.param_valid & 0x80) { pb_debug("platform: boot mailbox parameters are invalid/locked\n"); return -1; } /* check for block number */ - if (resp[3] != block) { + if (ipmi_mbox_resp.block_selector != block) { pb_debug("platform: returned boot mailbox block doesn't match " "requested\n"); return -1; @@ -512,8 +536,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return 0; } - - memcpy(buf, &resp[4], blocksize); + memcpy(mailbox, &ipmi_mbox_resp.mbox, blocksize); return blocksize; } @@ -522,12 +545,10 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, char **buf) { char *mailbox_buffer, *prefix; - const size_t blocksize = 16; - char block_buffer[blocksize]; + mbox_t mailbox; size_t mailbox_size; int content_size; uint8_t i; - int rc; mailbox_buffer = NULL; mailbox_size = 0; @@ -538,15 +559,15 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, * on higher numbers. */ for (i = 0; i < UCHAR_MAX; i++) { - rc = get_ipmi_boot_mailbox_block(platform, block_buffer, i); - if (rc < 3 && i == 0) { + int block_size = get_ipmi_boot_mailbox_block(platform, &mailbox, i); + if (block_size < CHASSIS_BOOT_MBOX_IANA_SZ && i == 0) { /* * Immediate failure, no blocks read or missing IANA * number. */ return -1; } - if (rc < 1) { + if (block_size < 1) { /* Error or no bytes read */ break; } @@ -557,25 +578,25 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, * Enterprise ID number. Check it matches the IBM * number, '2'. */ - if (block_buffer[0] != 0x02 || - block_buffer[1] != 0x00 || - block_buffer[2] != 0x00) { + if (mailbox.b0.iana[0] != 0x02 || + mailbox.b0.iana[1] != 0x00 || + mailbox.b0.iana[2] != 0x00) { pb_log_fn("IANA number unrecognised: 0x%x:0x%x:0x%x\n", - block_buffer[0], - block_buffer[1], - block_buffer[2]); + mailbox.b0.iana[0], + mailbox.b0.iana[1], + mailbox.b0.iana[2]); return -1; } } mailbox_buffer = talloc_realloc(platform, mailbox_buffer, - char, mailbox_size + rc); + char, mailbox_size + block_size); if (!mailbox_buffer) { pb_log_fn("Failed to allocate mailbox buffer\n"); return -1; } - memcpy(mailbox_buffer + mailbox_size, block_buffer, rc); - mailbox_size += rc; + memcpy(mailbox_buffer + mailbox_size, &mailbox.data, block_size); + mailbox_size += block_size; } if (i < 5)