From patchwork Tue Sep 18 03:05:32 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: 970900 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 ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42DnvY3Gpcz9sCR for ; Tue, 18 Sep 2018 13:06:33 +1000 (AEST) 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="chaKI+M1"; 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 42DnvY1n4YzF310 for ; Tue, 18 Sep 2018 13:06:33 +1000 (AEST) 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="chaKI+M1"; 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::42c; helo=mail-pf1-x42c.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="chaKI+M1"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 42Dntj3wGtzF0wf for ; Tue, 18 Sep 2018 13:05:49 +1000 (AEST) Received: by mail-pf1-x42c.google.com with SMTP id b11-v6so269050pfo.3 for ; Mon, 17 Sep 2018 20:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+Cq+349X8kdMS4kRNiNUtkeYfOKL3GrCfqi9/Itq4/M=; b=chaKI+M1vvMcyCfwusAwZAcBdoVh45RA58xCelLqVEDaQPTnj5zZ97cCfkxck9nlLN DrR7DEBZ3oon8f8ZZlcuViBCgg4816gpuJHEakbNJzmrdWx/zD74r/f3AUaeJZeVC1KH /8/Ip5a1KQOLnHBaIxpDTd17ylCJY3yx6n2mE6Gkm/MRPxGaye90oIfK0k0DA27XqsGm S7bTEydKNuInnmAquD8QWisxckxgenRbCDIoSadxe7aH1zQefDuIOvTkLZegkK/sUepE PXAM1Znb5m7awoxOdeJMgVglssH2JwrxHHsIC9hGXviw4R6oV4rIPjska80p41Yt0WkU suog== 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:in-reply-to :references; bh=+Cq+349X8kdMS4kRNiNUtkeYfOKL3GrCfqi9/Itq4/M=; b=c4KLs5O1oBWWVLiiZxq4CA3Gm3q9nybEjJs53rJFatEE05KTta8zpK01qiSKP/wsJ8 0121yAQRhcZcZmDhyiblPSmuHDLlLsb/+c+8W5G/Di9fjvFvhqOnFeJ1b38uLdu2M8Cb qvGDjPjBtYSFUmagviVAoDUlTgG65c1H3CKCqUz4uYzEBI1LO5iz1b5nNSIpEgkXUmjk HHZNifnV9lusLtig68HEVcLBnk/RolV0T7CkPQq0/JPaPm/LZXceBRHWh6W/BHH4pNal oXNhBNoN61dipRhwscG/EYscTEAiLkth0YSIJToi40kb9ItO5NQT5bvS8w2Z5xnyYVXp OKMw== X-Gm-Message-State: APzg51BaOXoDRIXpIOB/Zw1P7Dq5kevNnsAh1VD21OAtUeP/Yn3uTNoq aFjZvFkS6y/UjjhkdxTYuTAbgT5+ X-Google-Smtp-Source: ANB0VdYipyktoUJSBMI2mPLZsuOxGSO9DNoPOP39aCw6wLcfKlkRT4Dq7crCQtPd4jWCa4ENR9c+5Q== X-Received: by 2002:a63:bc0a:: with SMTP id q10-v6mr25661421pge.60.1537239946965; Mon, 17 Sep 2018 20:05:46 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id u9-v6sm22500228pfi.104.2018.09.17.20.05.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 20:05:46 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 18 Sep 2018 13:05:32 +1000 Message-Id: <20180918030532.22525-3-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180918030532.22525-1-oohall@gmail.com> References: <20180918030532.22525-1-oohall@gmail.com> Subject: [Skiboot] [PATCH 2/2] xscom-utils: Rework getsram 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: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Allow specifying a file on the command line to read OCC SRAM data into. If no file is specified then we print it to stdout as text. This is a bit inconsistent, but it retains compatibility with the existing tool. Signed-off-by: Oliver O'Halloran --- external/xscom-utils/getsram.c | 54 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/external/xscom-utils/getsram.c b/external/xscom-utils/getsram.c index 65acc191ace1..18c52c7b139e 100644 --- a/external/xscom-utils/getsram.c +++ b/external/xscom-utils/getsram.c @@ -26,9 +26,12 @@ static void print_usage(int code) { - printf("usage: getsram [-c|--chip chip-id] addr\n"); - printf(" [--occ-channel|n ]\n"); - printf(" getsram -v|--version\n"); + printf("usage: getsram [opts] addr\n"); + printf(" -c|--chip \n"); + printf(" -l|--length \n"); + printf(" -n|--occ-channel \n"); + printf(" -f|--file \n"); + printf(" -v|--version\n"); exit(code); } @@ -36,10 +39,12 @@ extern const char version[]; int main(int argc, char *argv[]) { - uint64_t val, addr = -1ull; + uint64_t val, addr = -1ull, length = 8; uint32_t def_chip, chip_id = 0xffffffff; int rc; int occ_channel = 0; + char *filename = NULL; + FILE *f = stdout; while(1) { static struct option long_opts[] = { @@ -47,10 +52,12 @@ int main(int argc, char *argv[]) {"occ-channel", required_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, + {"length", required_argument, NULL, 'l'}, + {"file", required_argument, NULL, 'f'}, }; int c, oidx = 0; - c = getopt_long(argc, argv, "-c:n:hlv", long_opts, &oidx); + c = getopt_long(argc, argv, "-c:n:hl:vf:", long_opts, &oidx); if (c == EOF) break; switch(c) { @@ -73,6 +80,13 @@ int main(int argc, char *argv[]) case 'v': printf("xscom utils version %s\n", version); exit(0); + case 'f': + filename = optarg; + break; + case 'l': + length = strtoul(optarg, NULL, 0); + length = (length + 7) & ~0x7; /* round up to an eight byte interval */ + break; default: exit(1); } @@ -91,11 +105,37 @@ int main(int argc, char *argv[]) if (chip_id == 0xffffffff) chip_id = def_chip; - rc = sram_read(chip_id, occ_channel, addr, &val); + if (filename) { + f = fopen(filename, "wb"); + if (!f) { + fprintf(stderr, "unable to open %s for writing\n", filename); + exit(1); + } + } + + rc = 0; + while (length) { + rc = sram_read(chip_id, occ_channel, addr, &val); + if (rc) + break; + + if (f) { + int i; + + /* make sure we write it out big endian */ + for (i = 1; i <= 8; i++) + fputc((val >> (64 - i * 8)) & 0xff, f); + } else { + printf("OCC%d: %" PRIx64 "\n", occ_channel, val); + } + + length -= 8; + addr += 8; + } + if (rc) { fprintf(stderr,"Error %d reading XSCOM\n", rc); exit(1); } - printf("OCC%d: %" PRIx64 "\n", occ_channel, val); return 0; }