From patchwork Wed Jun 15 08:29:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Reber X-Patchwork-Id: 636162 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 AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rVR1l0DYJz9ssP for ; Thu, 16 Jun 2016 11:41:31 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rVR1k6ZRWzDqlg for ; Thu, 16 Jun 2016 11:41:30 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rV0FZ2wjpzDqjP for ; Wed, 15 Jun 2016 18:35:14 +1000 (AEST) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B929C2A0E54; Wed, 15 Jun 2016 08:35:12 +0000 (UTC) Received: from dcbz.localdomain (ovpn-116-49.ams2.redhat.com [10.36.116.49]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5F8YPMC023485; Wed, 15 Jun 2016 04:35:11 -0400 From: Adrian Reber To: Alexey Kardashevskiy Date: Wed, 15 Jun 2016 10:29:53 +0200 Message-Id: <1465979400-2964-7-git-send-email-adrian@lisas.de> In-Reply-To: <1465979400-2964-1-git-send-email-adrian@lisas.de> References: <1465979400-2964-1-git-send-email-adrian@lisas.de> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 15 Jun 2016 08:35:12 +0000 (UTC) X-Mailman-Approved-At: Thu, 16 Jun 2016 11:41:14 +1000 Subject: [SLOF] [PATCH 06/13] tools: added function to dump header X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , slof@lists.ozlabs.org, Adrian Reber MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" -d, --dump prints the information from the header, including the total number of files in flash image as well as the CRC. (cherry picked from commit 4d6f40c47d6b84cced86024a09ad68dfade45812) Cherry picked from https://lisas.de/~adrian/slof/slof.git/ Signed-off-by: Adrian Reber --- tools/sloffs.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/tools/sloffs.c b/tools/sloffs.c index 34a10c5..eca06d8 100644 --- a/tools/sloffs.c +++ b/tools/sloffs.c @@ -29,9 +29,13 @@ #ifdef _BIG_ENDIAN #define cpu_to_be64(x) (x) #define be64_to_cpu(x) (x) +#define be16_to_cpu(x) (x) +#define be32_to_cpu(x) (x) #else #define cpu_to_be64(x) bswap_64(x) #define be64_to_cpu(x) bswap_64(x) +#define be16_to_cpu(x) bswap_16(x) +#define be32_to_cpu(x) bswap_32(x) #endif @@ -61,6 +65,95 @@ next_file(struct sloffs *sloffs) be64_to_cpu(sloffs->next)); } +static struct sloffs * +find_file(const void *data, const char *name) +{ + struct sloffs *sloffs = (struct sloffs *)data; + + for (;;) { + if (!strcmp((char *)&sloffs->name, name)) + return sloffs; + + if (be64_to_cpu(sloffs->next) == 0) + break; + sloffs = next_file(sloffs); + } + return NULL; +} + +static void +sloffs_dump(const void *data) +{ + struct stH *header; + struct sloffs *sloffs; + int i; + uint64_t crc; + + /* find the "header" file with all the information about + * the flash image */ + sloffs = find_file(data, "header"); + if (!sloffs) { + printf("sloffs file \"header\" not found. aborting...\n"); + return; + } + + header = (struct stH *)((unsigned char *)sloffs + + be64_to_cpu(sloffs->data)); + + if (memcmp(FLASHFS_MAGIC, header->magic, strlen(FLASHFS_MAGIC))) { + printf("sloffs magic not found. " + "probably not a valid SLOF flash image. aborting...\n"); + return; + } + printf(" Magic : %s\n", header->magic); + printf(" Platform : %s\n", header->platform_name); + printf(" Version : %s\n", header->version); + printf(" Build Date : "); + /* there is a bug in the date position; + * it should be at header->date, but it is at (header->date + 2) */ + if (be64_to_cpu(*(uint64_t *)header->date)) { + printf("%04x", be16_to_cpu(*(uint16_t *)(header->date + 2))); + printf("-%02x", *(uint8_t *)(header->date + 4)); + printf("-%02x", *(uint8_t *)(header->date + 5)); + printf(" %02x:", *(uint8_t *)(header->date + 6)); + printf("%02x", *(uint8_t *)(header->date + 7)); + } else { + printf("N/A"); + } + printf("\n"); + printf(" Modify Date : "); + if (be64_to_cpu(*(uint64_t *)header->mdate)) { + printf("%04x", be16_to_cpu(*(uint16_t *)(header->mdate + 2))); + printf("-%02x", *(uint8_t *)(header->mdate + 4)); + printf("-%02x", *(uint8_t *)(header->mdate + 5)); + printf(" %02x:", *(uint8_t *)(header->mdate + 6)); + printf("%02x", *(uint8_t *)(header->mdate + 7)); + } else { + printf("N/A"); + } + printf("\n"); + printf(" Image Length: %lld", be64_to_cpu(header->flashlen)); + printf(" (0x%llx) bytes\n", be64_to_cpu(header->flashlen)); + printf(" Revision : %s\n", header->platform_revision); + crc = be64_to_cpu(header->ui64CRC); + printf(" Header CRC : 0x%016llx\n", crc); + crc = be64_to_cpu(header->flashlen); + crc = *(uint64_t *)(unsigned char *)(data + crc - 8); + crc = be64_to_cpu(crc); + printf(" Image CRC : 0x%016llx\n", crc); + + /* count number of files */ + sloffs = (struct sloffs *)data; + i = 0; + for (;;) { + i++; + if (be64_to_cpu(sloffs->next) == 0) + break; + sloffs = next_file(sloffs); + } + printf(" Files : %d\n", i); +} + static void sloffs_list(const void *data) { @@ -143,7 +236,7 @@ main(int argc, char *argv[]) }; const char *soption = "dhlv"; int c; - char mode; + char mode = 0; for (;;) { c = getopt_long(argc, argv, soption, loption, NULL); @@ -156,6 +249,9 @@ main(int argc, char *argv[]) case 'v': printf("sloffs (version %d)\n", VERSION); exit(0); + case 'd': + mode = 'd'; + break; case 'h': default: usage(); @@ -179,6 +275,9 @@ main(int argc, char *argv[]) case 'l': sloffs_list(file); break; + case 'd': + sloffs_dump(file); + break; } munmap(file, stat.st_size);