From patchwork Tue Feb 27 05:20:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 878317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zr6V8139gz9s1X for ; Tue, 27 Feb 2018 16:20:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F44Ua5M9"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zr6V76N43zF1VD for ; Tue, 27 Feb 2018 16:20:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F44Ua5M9"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c01::235; helo=mail-pl0-x235.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F44Ua5M9"; dkim-atps=neutral Received: from mail-pl0-x235.google.com (mail-pl0-x235.google.com [IPv6:2607:f8b0:400e:c01::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zr6V04HgczF1V2 for ; Tue, 27 Feb 2018 16:20:40 +1100 (AEDT) Received: by mail-pl0-x235.google.com with SMTP id u13so10775245plq.1 for ; Mon, 26 Feb 2018 21:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=8cStF3z48SzBC5GAsX9CTz4J2A9liWZASCdIemWRpjM=; b=F44Ua5M9HPaHtOD89Nkcf9fjaZDMlrHbbkHn9CNmK4ZjWDvijn8Wu/IIcC/r4AddKs L4mccHLvqTAdFSqGPMJCAD0QtOK+W2i8ho3jKdaRyHSf2q8y5MV36iUeI4QtfHewYjur eQyFq+Ryh3ZoYHoJuBWUmPDQRb7SxjAN9Sroztp+U+e5MCodu83ZpMmtk5m1hHgmZJF9 E5VmznmFh1653MDFVq21grjLN64RadYzKteR6FAXCn2ZKs9Bt0E+fg3FBnmSGN0u6kqL mrNM9cD6OKOkfB9Jrs79DZnolrCN6JGVtMS2GH+HxpFczWe7E8phLhtR5ru52Fvfm+hU YQGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8cStF3z48SzBC5GAsX9CTz4J2A9liWZASCdIemWRpjM=; b=C4B9qFqge/2sgRa1B09wkGowGlAyEqiQF2PdLA6xE7WzHcLoYYIlJtofEjMa0DtBhU tL9RZJVjaW2V6vQAE0JExonsoJi7HpdrbvRZDbzcW6AR0nTPanAqsIHJiwmIV4njenWU /Puj7H4MGRY88/bsSgPfHJA43KdM95Fl4vfdWxxtYr+YKVCGGpHx4Px2Jt+OVP/XxevG uI9b/2yTmvVLPRfg7++aGPkGpRxgrxXIrCBV+Or0DXvneuRR5KLrAVNB/0yoI+DhzGEv 5jUFHbOOnAFyEYvA0kRo5cJedazEpEJkhnh9vdR+jd26WFqfTjii/EyVHj79PACXRs0n uxTg== X-Gm-Message-State: APf1xPBWhHknQUuqrjh6WUp6GyQr8qLhV79iWfOZ8vb63WOP0Cb3+nJy oOD1xLJT53Rw8QanLjZiECuA8Q== X-Google-Smtp-Source: AG47ELsIicIJ3S5jguqllRoYtfjE6bk1WsfEHqLW0RBJPDRwKDlTD3Yq1ZE7qTfyRHFci+WggMkB/g== X-Received: by 2002:a17:902:3341:: with SMTP id a59-v6mr8147952plc.20.1519708837911; Mon, 26 Feb 2018 21:20:37 -0800 (PST) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id o18sm14154154pgd.26.2018.02.26.21.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 21:20:37 -0800 (PST) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 27 Feb 2018 16:20:23 +1100 Message-Id: <20180227052023.16598-1-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 Subject: [Skiboot] [RFC PATCH] pflash: Print libflash error strings X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cyrilbur@gmail.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Seems like something we might want. Currently most errors just give a little bit of context and spit an error code at you which requires looking inside of libflash to work out the meaning of. Inspired-by: https://github.com/open-power/skiboot/issues/151 Cc: cyrilbur@gmail.com Cc: ppaidipe@linux.vnet.ibm.com --- external/pflash/pflash.c | 26 +++++++++++++++----------- libflash/errors.h | 7 +++++-- libflash/libflash.c | 31 +++++++++++++++++++++++++++++++ libflash/libflash.h | 5 +++++ 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 3ac948496e24..419461b2e34d 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -149,7 +149,7 @@ static struct ffs_handle *open_ffs(struct flash_details *flash) rc = ffs_init(flash->toc, flash->total_size, flash->bl, &ffsh, 0); if (rc) { - fprintf(stderr, "Error %d opening ffs !\n", rc); + fprintf(stderr, "Error %s (%d) opening ffs !\n", flash_error_str(rc), rc); if (flash->toc) { fprintf(stderr, "You specified 0x%" PRIx64 " as the libffs TOC\n" "Looks like it doesn't exist\n", flash->toc); @@ -293,7 +293,8 @@ static int erase_chip(struct flash_details *flash) } progress_end(); if (rc) { - fprintf(stderr, "Error %d erasing chip\n", rc); + fprintf(stderr, "Error %s (%d) erasing chip\n", + flash_error_str(rc), rc); return rc; } @@ -334,7 +335,8 @@ static int erase_range(struct flash_details *flash, rc = blocklevel_smart_erase(flash->bl, start, first_size); if (rc) { - fprintf(stderr, "Failed to blocklevel_smart_erase(): %d\n", rc); + fprintf(stderr, "Failed to blocklevel_smart_erase(): %s (%d)\n", + flash_error_str(rc), rc); return 1; } size -= first_size; @@ -345,7 +347,8 @@ static int erase_range(struct flash_details *flash, while (size & ~(erase_mask)) { rc = blocklevel_smart_erase(flash->bl, start, flash->erase_granule); if (rc) { - fprintf(stderr, "Failed to blocklevel_smart_erase(): %d\n", rc); + fprintf(stderr, "Failed to blocklevel_smart_erase(): %s (%d)\n", + flash_error_str(rc), rc); return 1; } start += flash->erase_granule; @@ -356,7 +359,8 @@ static int erase_range(struct flash_details *flash, if (size) { rc = blocklevel_smart_erase(flash->bl, start, size); if (rc) { - fprintf(stderr, "Failed to blocklevel_smart_erase(): %d\n", rc); + fprintf(stderr, "Failed to blocklevel_smart_erase(): %s (%d)\n", + flash_error_str(rc), rc); return 1; } done += size; @@ -456,8 +460,8 @@ static int program_file(struct blocklevel_device *bl, fprintf(stderr, "Verification failed for" " chunk at 0x%08x\n", start); else - fprintf(stderr, "Flash write error %d for" - " chunk at 0x%08x\n", rc, start); + fprintf(stderr, "Flash write error %s (%d) for" + " chunk at 0x%08x\n", flash_error_str(rc), rc, start); goto out; } start += len; @@ -531,7 +535,7 @@ static int enable_4B_addresses(struct blocklevel_device *bl) if (rc == -1) { fprintf(stderr, "Switching address mode not available on this architecture\n"); } else { - fprintf(stderr, "Error %d enabling 4b mode\n", rc); + fprintf(stderr, "Error %s (%d) enabling 4b mode\n", flash_error_str(rc), rc); } } @@ -549,7 +553,7 @@ static int disable_4B_addresses(struct blocklevel_device *bl) if (rc == -1) { fprintf(stderr, "Switching address mode not available on this architecture\n"); } else { - fprintf(stderr, "Error %d enabling 4b mode\n", rc); + fprintf(stderr, "Error %s (%d) enabling 4b mode\n", flash_error_str(rc), rc); } } @@ -566,8 +570,8 @@ static void print_partition_detail(struct ffs_handle *ffsh, uint32_t part_id) rc = ffs_part_info(ffsh, part_id, &ent_name, &start, &size, &act, NULL); if (rc) { - fprintf(stderr, "Partition with ID %d doesn't exist error: %d\n", - part_id, rc); + fprintf(stderr, "Partition with ID %d doesn't exist error: %s (%d)\n", + part_id, flash_error_str(rc), rc); goto out; } diff --git a/libflash/errors.h b/libflash/errors.h index d144e097ea0e..1ed6c02e635a 100644 --- a/libflash/errors.h +++ b/libflash/errors.h @@ -16,6 +16,7 @@ #ifndef __LIBFLASH_ERRORS_H #define __LIBFLASH_ERRORS_H +#define FLASH_ERR_SUCCESS 0 #define FLASH_ERR_MALLOC_FAILED 1 #define FLASH_ERR_CHIP_UNKNOWN 2 #define FLASH_ERR_PARM_ERROR 3 @@ -31,8 +32,10 @@ #define FLASH_ERR_CTRL_TIMEOUT 13 #define FLASH_ERR_ECC_INVALID 14 #define FLASH_ERR_BAD_READ 15 -#define FLASH_ERR_DEVICE_GONE 16 -#define FLASH_ERR_AGAIN 17 +#define FLASH_ERR_DEVICE_GONE 16 +#define FLASH_ERR_AGAIN 17 + +#define FLASH_ERR_LAST 18 /* increment when needed */ #ifdef __SKIBOOT__ #include diff --git a/libflash/libflash.c b/libflash/libflash.c index ad25b613357a..6bcd056d20a9 100644 --- a/libflash/libflash.c +++ b/libflash/libflash.c @@ -23,6 +23,37 @@ #include "ecc.h" #include "blocklevel.h" +static const char *error_str[FLASH_ERR_LAST] = { + [FLASH_ERR_SUCCESS] = "success", + [FLASH_ERR_MALLOC_FAILED] = "malloc failed", + [FLASH_ERR_CHIP_UNKNOWN] = "chip unknown", + [FLASH_ERR_PARM_ERROR] = "parameter error", + [FLASH_ERR_ERASE_BOUNDARY] = "erase boundary error", + [FLASH_ERR_WREN_TIMEOUT] = "wren timeout", + [FLASH_ERR_WIP_TIMEOUT] = "wip timeout", + [FLASH_ERR_BAD_PAGE_SIZE] = "bad page size", + [FLASH_ERR_VERIFY_FAILURE] = "verify failure", + [FLASH_ERR_4B_NOT_SUPPORTED] = "4b mode unsupported", + [FLASH_ERR_CTRL_CONFIG_MISMATCH] = "controller is misconfigured", + [FLASH_ERR_CHIP_ER_NOT_SUPPORTED] = "chip doesn't support erase", + [FLASH_ERR_CTRL_CMD_UNSUPPORTED] = "unsupported controller command", + [FLASH_ERR_CTRL_TIMEOUT] = "controller timeout", + [FLASH_ERR_ECC_INVALID] = "ecc invalid", + [FLASH_ERR_BAD_READ] = "bad read", + [FLASH_ERR_DEVICE_GONE] = "device gone", + [FLASH_ERR_AGAIN] = "try again" +}; + +const char *flash_error_str(int rc) +{ + if (rc >= FLASH_ERR_LAST) + return "unknown error"; + if (rc < 0) + return "backend error"; + + return error_str[rc]; +} + static const struct flash_info flash_info[] = { { 0xc22018, 0x01000000, FL_ERASE_ALL | FL_CAN_4B, "Macronix MXxxL12835F"}, { 0xc22019, 0x02000000, FL_ERASE_ALL | FL_CAN_4B, "Macronix MXxxL25635F"}, diff --git a/libflash/libflash.h b/libflash/libflash.h index 01b4d6052e7d..2d3b74a1a992 100644 --- a/libflash/libflash.h +++ b/libflash/libflash.h @@ -28,6 +28,11 @@ */ #include +/* + * Translates a libflash return code into something sensible. + */ +const char *flash_error_str(int rc) __attribute__((const)); + #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif