From patchwork Mon Nov 12 22:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 996708 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42v5f11HJLz9s1x for ; Tue, 13 Nov 2018 09:53:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YNhdbggv"; 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 42v5f05bWBzF3N8 for ; Tue, 13 Nov 2018 09:53:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au 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="YNhdbggv"; 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:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YNhdbggv"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 42v5dx0ZnyzF3H2 for ; Tue, 13 Nov 2018 09:53:40 +1100 (AEDT) Received: by mail-pf1-x441.google.com with SMTP id v9-v6so5010516pff.2 for ; Mon, 12 Nov 2018 14:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IMfgECtF23NefDnOCpkWdACU+NLLjLlf0v/4iFpws74=; b=YNhdbggvbKMvVf52KM+0Ew+00Wz554/8tzXIWsiWwbusJ+b5n4vqnNKHFTtCVVCoq5 51eAxFJavBLJfZj3Ovj7DmCbA2VDTsbgjPA7rBzpdECjQ/KuYP/yp8Dp7sqdxKpxCDNt pA8oAk6eHnS5QON6GKH0PhhwA50PCtKnlv+OnxDY8vlmfqEIPudFvxgnpIi7NaMZT23F RRfZPZBKV0VG0o2LTg6TZsgv4cni0PHxS4N4zD0TpeDyihHvZqAwT/Mm5g5DONqhMWoS DhhBx8HN+r/1h1iokTknilUQ+tXpw9oaFWTywaeFv+YIFmMLNGgkwgL55reoPJ+tFszD yxvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=IMfgECtF23NefDnOCpkWdACU+NLLjLlf0v/4iFpws74=; b=fnmO5oX8Y/Xhhs9OkYqedSPT2hT52Qwp2EFWVfAmmU6m4p5Zaw6+Q3TGwg5v4QMCz/ QadNfQmm2CAyH9P2vremMvddcI4HWMgGGmzGKgrc2486dWCwf2uR+sZAq8RtDB9YmDfF KzMILnVGHmZiftbXPu5Di2CXU0Dn4kA7wgB3PUjnxDMiPwqt/81oLoRids/ojwhBHZAr 0BJJNdcxFDSxWK1HyeNwYEsk2LA47WkBSWg2jYERXZBpRHtbpny9oYFpSNUuvd/NOYEH +MA/feHmjJB8mIUaiHGwTcIKo9PnAMnqhzQaSTqgRtv3UCyioCsCSjNkIVffJ32jIfvK lB1Q== X-Gm-Message-State: AGRZ1gIJ6TRM8O4PsyFnClypJtAq+GeyQdGgpvfYqd3hYSjiIPt+Zqoz BYglxGDXuny+cxcylzwYi9l+lwsm X-Google-Smtp-Source: AJdET5duDnktrDV9uRg12Ta2J8Y+pwMeW2CZwbLzE7VTVgs+Cz4coHOo3wPHmTyb+YE7/J87AKVMuA== X-Received: by 2002:a62:6bc8:: with SMTP id g191-v6mr2818795pfc.134.1542063217888; Mon, 12 Nov 2018 14:53:37 -0800 (PST) Received: from aurora.jms.id.au ([45.124.203.15]) by smtp.gmail.com with ESMTPSA id z127-v6sm8678729pfz.135.2018.11.12.14.53.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Nov 2018 14:53:37 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 13 Nov 2018 09:23:31 +1030 From: Joel Stanley To: skiboot@lists.ozlabs.org Date: Tue, 13 Nov 2018 09:23:27 +1030 Message-Id: <20181112225327.8958-1-joel@jms.id.au> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Subject: [Skiboot] [PATCH stable] pflash: Add --skip option for reading X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" From: Adriana Kobylak Add a --skip=N option to pflash to skip N number of bytes when reading. This would allow users to print the VERSION partition without the STB header by specifying the --skip=4096 argument, and it's a more generic solution rather than making pflash depend on secure/trusted boot code. Signed-off-by: Adriana Kobylak Reviewed-by: Samuel Mendoza-Jonas [stewart: fix up pflash test] Signed-off-by: Stewart Smith (cherry picked from commit b6ebee077d915916989aa3057239a985981edb07) Signed-off-by: Joel Stanley --- external/pflash/pflash.c | 26 ++++++++++++++++--- external/pflash/test/results/00-usage.out | 3 +++ .../pflash/test/results/05-bad-numbers.out | 3 +++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 72b90fc895d2..c81520cb9039 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -471,7 +471,7 @@ out: } static int do_read_file(struct blocklevel_device *bl, const char *file, - uint32_t start, uint32_t size) + uint32_t start, uint32_t size, uint32_t skip_size) { int fd, rc = 0; uint32_t done = 0; @@ -481,6 +481,9 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, perror("Failed to open file"); return 1; } + start += skip_size; + size -= skip_size; + printf("Reading to \"%s\" from 0x%08x..0x%08x !\n", file, start, start + size); @@ -644,6 +647,8 @@ static void print_help(const char *pname) printf("\t\tTarget filename instead of actual flash.\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--skip=N\n"); + printf("\t\tSkip N number of bytes from the start when reading\n\n"); printf("\t-T, --toc\n"); printf("\t\tlibffs TOC on which to operate, defaults to 0.\n"); printf("\t\tleading 0x is required for interpretation of a hex value\n\n"); @@ -709,7 +714,7 @@ int main(int argc, char *argv[]) bool no_action = false, tune = false; char *write_file = NULL, *read_file = NULL, *part_name = NULL; bool ffs_toc_seen = false, direct = false, print_detail = false; - int flash_side = 0; + int flash_side = 0, skip_size = 0; int rc = 0; while(1) { @@ -735,6 +740,7 @@ int main(int argc, char *argv[]) {"version", no_argument, NULL, 'v'}, {"debug", no_argument, NULL, 'g'}, {"side", required_argument, NULL, 'S'}, + {"skip", required_argument, NULL, 'k'}, {"toc", required_argument, NULL, 'T'}, {"clear", no_argument, NULL, 'c'}, {NULL, 0, NULL, 0 } @@ -826,6 +832,13 @@ int main(int argc, char *argv[]) case 'S': flash_side = atoi(optarg); break; + case 'k': + skip_size = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + rc = 1; + no_action = true; + } + break; case 'T': if (!optarg) break; @@ -935,6 +948,13 @@ int main(int argc, char *argv[]) goto out; } + /* Skip only supported on read */ + if (skip_size && !do_read) { + fprintf(stderr, "--skip requires a --read command !\n"); + rc = 1; + goto out; + } + /* Program command should always come with a file */ if (program && !write_file) { fprintf(stderr, "Program with no file specified !\n"); @@ -1142,7 +1162,7 @@ int main(int argc, char *argv[]) } rc = 0; if (do_read) - rc = do_read_file(flash.bl, read_file, address, read_size); + rc = do_read_file(flash.bl, read_file, address, read_size, skip_size); if (!rc && erase_all) rc = erase_chip(&flash); else if (!rc && erase) diff --git a/external/pflash/test/results/00-usage.out b/external/pflash/test/results/00-usage.out index 3b54f456c534..caf7b8d8d580 100644 --- a/external/pflash/test/results/00-usage.out +++ b/external/pflash/test/results/00-usage.out @@ -43,6 +43,9 @@ Usage: ./pflash [options] commands... -S, --side Side of the flash on which to operate, 0 (default) or 1 + --skip=N + Skip N number of bytes from the start when reading + -T, --toc libffs TOC on which to operate, defaults to 0. leading 0x is required for interpretation of a hex value diff --git a/external/pflash/test/results/05-bad-numbers.out b/external/pflash/test/results/05-bad-numbers.out index 211bd6a01d3c..17db6650f591 100644 --- a/external/pflash/test/results/05-bad-numbers.out +++ b/external/pflash/test/results/05-bad-numbers.out @@ -43,6 +43,9 @@ Usage: ./pflash [options] commands... -S, --side Side of the flash on which to operate, 0 (default) or 1 + --skip=N + Skip N number of bytes from the start when reading + -T, --toc libffs TOC on which to operate, defaults to 0. leading 0x is required for interpretation of a hex value