From patchwork Fri May 8 07:58:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 469915 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 BED2E140773 for ; Fri, 8 May 2015 18:09:12 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id AC50B1A0E0B for ; Fri, 8 May 2015 18:09:12 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 25E541A0935 for ; Fri, 8 May 2015 18:08:56 +1000 (AEST) Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 May 2015 18:08:55 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 8 May 2015 18:08:53 +1000 Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 699D42CE804E for ; Fri, 8 May 2015 18:08:53 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t4888jKG44695574 for ; Fri, 8 May 2015 18:08:53 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t4888LrA014401 for ; Fri, 8 May 2015 18:08:21 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t4888KD9013611 for ; Fri, 8 May 2015 18:08:20 +1000 Received: from cyril.ozlabs.ibm.com (unknown [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 17139A039A for ; Fri, 8 May 2015 17:58:52 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Fri, 8 May 2015 17:58:34 +1000 Message-Id: <1431071915-3917-4-git-send-email-cyril.bur@au1.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431071915-3917-1-git-send-email-cyril.bur@au1.ibm.com> References: <1431071915-3917-1-git-send-email-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15050808-0021-0000-0000-000001350613 Subject: [Skiboot] [PATCH 3/4] external/pflash: perform flashing on flash sides other than side 0 X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 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" Currently pflash only looks at the first ffs TOC it finds in order to locate an ffs partition. Problems arise when there are identical partitions in both sides of the flash as it is current impossible to specify the second side. This adds a parameter to specify the second side of the flash when pflash does the lookup for the partition. Signed-off-by: Cyril Bur --- external/pflash/pflash.c | 56 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 689f428..30cc142 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -29,6 +29,7 @@ static bool must_confirm = true; static bool dummy_run; static bool need_relock; static bool bmc_flash; +static int flash_side = 0; #ifdef __powerpc__ static bool using_sfc; #endif @@ -129,7 +130,7 @@ static void print_flash_info(void) print_ffs_info(0); } -static void lookup_partition(const char *name) +static int open_partition(const char *name) { uint32_t index; int rc; @@ -139,7 +140,7 @@ static void lookup_partition(const char *name) rc = ffs_open_flash(fl_chip, 0, 0, &ffsh); if (rc) { fprintf(stderr, "Error %d opening ffs !\n", rc); - exit(1); + return rc; } } @@ -147,14 +148,47 @@ static void lookup_partition(const char *name) rc = ffs_lookup_part(ffsh, name, &index); if (rc == FFS_ERR_PART_NOT_FOUND) { fprintf(stderr, "Partition '%s' not found !\n", name); - exit(1); + return rc; } if (rc) { fprintf(stderr, "Error %d looking for partition '%s' !\n", rc, name); - exit(1); + return rc; } + ffs_index = index; + return 0; +} + +static void lookup_partition(const char *name) +{ + int rc; + + if (flash_side == 1) { + uint32_t other_side_offset; + + rc = open_partition("OTHER_SIDE"); + if (rc == FFS_ERR_PART_NOT_FOUND) + fprintf(stderr, "side 1 was specified but there doesn't appear" + " to be a second side to this flash\n"); + if (rc) + exit(1); + + /* Just need to know where it starts */ + rc = ffs_part_info(ffsh, ffs_index, NULL, &other_side_offset, NULL, NULL, NULL); + if (rc) + exit(1); + + ffs_close(ffsh); + + rc = ffs_open_flash(fl_chip, other_side_offset, 0, &ffsh); + if (rc) + exit(1); + } + + rc = open_partition(name); + if (rc) + exit(1); } static void erase_chip(void) @@ -510,6 +544,8 @@ static void print_help(const char *pname) printf("\t-t, --tune\n"); printf("\t\tJust tune the flash controller & access size\n"); printf("\t\t(Implicit for all other operations)\n\n"); + printf("\t-S, --side\n"); + printf("\t\tSide of the flash on which to operate, 0 (default) or 1\n\n"); printf("\t-i, --info\n"); printf("\t\tDisplay some information about the flash.\n\n"); printf("\t-h, --help\n"); @@ -550,10 +586,11 @@ int main(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"debug", no_argument, NULL, 'g'}, + {"side", required_argument, NULL, 'S'}, }; int c, oidx = 0; - c = getopt_long(argc, argv, "a:s:P:r:43Eep:fdihlvbtg", + c = getopt_long(argc, argv, "a:s:P:r:43Eep:fdihlvbtgS:", long_opts, &oidx); if (c == EOF) break; @@ -615,6 +652,9 @@ int main(int argc, char *argv[]) case 'g': libflash_debug = true; break; + case 'S': + flash_side = atoi(optarg); + break; default: exit(1); } @@ -682,6 +722,12 @@ int main(int argc, char *argv[]) exit(1); } + /* Explicitly only support two sides */ + if (flash_side != 0 && flash_side != 1) { + fprintf(stderr, "Unexpected value for --side '%d'\n", flash_side); + exit(1); + } + /* If file specified but not size, get size from file */ if (write_file && !write_size) {