8bc6b11
From: Thomas Huth <thuth@redhat.com>
8bc6b11
Date: Thu, 19 Jul 2018 14:46:24 +0200
8bc6b11
Subject: [PATCH] romfs/tools: Remove superfluous union around the rom header
8bc6b11
 struct
8bc6b11
8bc6b11
Accessing the struct with memset and memcpy can also be done without the
8bc6b11
union wrapper. While we're at it, also remove the FLASHFS_HEADER_DATA_SIZE
8bc6b11
macre and use sizeof(stHeader) instead.
8bc6b11
8bc6b11
Signed-off-by: Thomas Huth <thuth@redhat.com>
8bc6b11
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
8bc6b11
(cherry picked from commit d4443f17c956e77df7bb23b2d19462faae9f4b23)
8bc6b11
---
8bc6b11
 include/calculatecrc.h   |  1 -
8bc6b11
 romfs/tools/create_crc.c | 29 +++++++++++++----------------
8bc6b11
 2 files changed, 13 insertions(+), 17 deletions(-)
8bc6b11
8bc6b11
diff --git a/include/calculatecrc.h b/include/calculatecrc.h
8bc6b11
index a19a229..667ea81 100644
8bc6b11
--- a/include/calculatecrc.h
8bc6b11
+++ b/include/calculatecrc.h
8bc6b11
@@ -17,7 +17,6 @@
8bc6b11
 #define FLASHFS_HEADER_SIZE_ADDR 0x08	// uint64_t position of total flash header size value
8bc6b11
 
8bc6b11
 #define FLASHFS_ROMADDR 0x00		// uint64_t position of pointer to next file
8bc6b11
-#define FLASHFS_HEADER_DATA_SIZE 0x68	// 104 bytes of total header data size
8bc6b11
 #define CRC_METHODE Ethernet_32		// define the CRC genarator (CRC 16 bit to 64 is supported)
8bc6b11
 
8bc6b11
 //--- header format ---------------------------------
8bc6b11
diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c
8bc6b11
index 5a76b9c..e354339 100644
8bc6b11
--- a/romfs/tools/create_crc.c
8bc6b11
+++ b/romfs/tools/create_crc.c
8bc6b11
@@ -10,6 +10,7 @@
8bc6b11
  *     IBM Corporation - initial implementation
8bc6b11
  *****************************************************************************/
8bc6b11
 
8bc6b11
+#include <assert.h>
8bc6b11
 #include <stdint.h>
8bc6b11
 #include <stdio.h>
8bc6b11
 #include <stdlib.h>
8bc6b11
@@ -71,21 +72,18 @@ createHeaderImage(int notime)
8bc6b11
 	char dastr[16] = { 0, };
8bc6b11
 	unsigned long long da = 0;
8bc6b11
 
8bc6b11
-	union {
8bc6b11
-		unsigned char pcArray[FLASHFS_HEADER_DATA_SIZE];
8bc6b11
-		struct stH stHeader;
8bc6b11
-	} uHeader;
8bc6b11
+	struct stH stHeader;
8bc6b11
 
8bc6b11
 	/* initialize Header */
8bc6b11
-	memset(uHeader.pcArray, 0x00, FLASHFS_HEADER_DATA_SIZE);
8bc6b11
+	memset(&stHeader, 0x00, sizeof(stHeader));
8bc6b11
 
8bc6b11
 	/* read driver info */
8bc6b11
 	if (NULL != (pcVersion = getenv("DRIVER_NAME"))) {
8bc6b11
-		strncpy(uHeader.stHeader.version, pcVersion, 16);
8bc6b11
+		strncpy(stHeader.version, pcVersion, 16);
8bc6b11
 	} else if (NULL != (pcVersion = getenv("USER"))) {
8bc6b11
-		strncpy(uHeader.stHeader.version, pcVersion, 16);
8bc6b11
+		strncpy(stHeader.version, pcVersion, 16);
8bc6b11
 	} else if (pcVersion == NULL) {
8bc6b11
-		strncpy(uHeader.stHeader.version, "No known user!", 16);
8bc6b11
+		strncpy(stHeader.version, "No known user!", 16);
8bc6b11
 	}
8bc6b11
 
8bc6b11
 	if (!notime) {
8bc6b11
@@ -104,18 +102,18 @@ createHeaderImage(int notime)
8bc6b11
 		}
8bc6b11
 		da = cpu_to_be64(strtoll(dastr, NULL, 16));
8bc6b11
 	}
8bc6b11
-	memcpy(uHeader.stHeader.date, &da, 8);
8bc6b11
+	memcpy(stHeader.date, &da, 8);
8bc6b11
 
8bc6b11
 	/* write Magic value into data stream */
8bc6b11
-	strncpy(uHeader.stHeader.magic, FLASHFS_MAGIC, 8);
8bc6b11
+	strncpy(stHeader.magic, FLASHFS_MAGIC, 8);
8bc6b11
 	/* write platform name into data stream */
8bc6b11
-	strcpy(uHeader.stHeader.platform_name, FLASHFS_PLATFORM_MAGIC);
8bc6b11
+	strcpy(stHeader.platform_name, FLASHFS_PLATFORM_MAGIC);
8bc6b11
 	/* write platform revision into data stream */
8bc6b11
-	strcpy(uHeader.stHeader.platform_revision, FLASHFS_PLATFORM_REVISION);
8bc6b11
+	strcpy(stHeader.platform_revision, FLASHFS_PLATFORM_REVISION);
8bc6b11
 
8bc6b11
 
8bc6b11
 	/* fill end of file info (8 bytes of FF) into data stream */
8bc6b11
-	uHeader.stHeader.ui64FileEnd = -1;
8bc6b11
+	stHeader.ui64FileEnd = -1;
8bc6b11
 
8bc6b11
 	/* read address of next file and address of header date, both are 64 bit values */
8bc6b11
 	ui64RomAddr = 0;
8bc6b11
@@ -129,7 +127,7 @@ createHeaderImage(int notime)
8bc6b11
 
8bc6b11
 	/* calculate final flash-header-size and flash-file-size */
8bc6b11
 	/* calculate end addr of header */
8bc6b11
-	ui64globalHeaderSize = (uint32_t) ui64DataAddr + (uint32_t) FLASHFS_HEADER_DATA_SIZE;
8bc6b11
+	ui64globalHeaderSize = (uint32_t) ui64DataAddr + sizeof(stHeader);
8bc6b11
 	/* cut 64 bit to place CRC for File-End */
8bc6b11
 	ui64globalHeaderSize -= 8;
8bc6b11
 	/* add 64 bit to place CRC behind File-End */
8bc6b11
@@ -143,8 +141,7 @@ createHeaderImage(int notime)
8bc6b11
 	/* fill free space in Header with zeros */
8bc6b11
 	memset(&pucFileStream[ui64DataAddr], 0, (ui64RomAddr - ui64DataAddr));
8bc6b11
 	/* place data to header */
8bc6b11
-	memcpy(&pucFileStream[ui64DataAddr], uHeader.pcArray,
8bc6b11
-	       FLASHFS_HEADER_DATA_SIZE);
8bc6b11
+	memcpy(&pucFileStream[ui64DataAddr], &stHeader, sizeof(stHeader));
8bc6b11
 
8bc6b11
 	/* insert header length into data stream */
8bc6b11
 	*(uint64_t *) (pucFileStream + FLASHFS_HEADER_SIZE_ADDR) =