Skip to content

Commit

Permalink
Update buildBpmFlashImages.pl to support configuration data binary ge…
Browse files Browse the repository at this point in the history
…neration

Currently, buildBpmFlashImages.pl will only generate the firmware
binaries for the BPM update for firmware versions less than 1.05. This
commit adds support for the configuration portion of the update for
version 1.05 and updates the script so that the generated firmware
binaries are compliant with v1.05 requirements.

Change-Id: I29b80b01fc8af85ffdefe8c4ad486206e557306e
RTC:212446
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/80198
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Matt Derksen <mderkse1@us.ibm.com>
Reviewed-by: Daniel M Crowell <dcrowell@us.ibm.com>
  • Loading branch information
MRaybuck authored and dcrowell77 committed Jul 23, 2019
1 parent 533e200 commit 72f32c4
Show file tree
Hide file tree
Showing 4 changed files with 575 additions and 94 deletions.
114 changes: 48 additions & 66 deletions src/build/buildpnor/bpm-utils/imageCrc.c
Expand Up @@ -29,15 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include "./i2c-dev.h" // Copied from i2c-tools package.
#include <getopt.h>
#include <termios.h>
#include <stdarg.h>
#include <time.h>

//#define DEBUG

Expand Down Expand Up @@ -65,47 +56,43 @@
#define ADDRESS_RESET_VECTOR (0xFFFE) // @FFFE, FFFF
#define LENGTH_IMAGE_CRC (0x2)

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef unsigned int bool;

bool true = 1;
bool false = 0;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;

typedef struct _CRC_CONTEXT {
u16 mainImageStartAddress;
u16 mainImageTotalLength;
uint16_t mainImageStartAddress;
uint16_t mainImageTotalLength;
} CRC_CONTEXT;

typedef struct _OFFSET_LIST {
u32 count;
u32 offset[4];
uint32_t count;
uint32_t offset[4];
} OFFSET_LIST;

char* readNextHex(const char* pLine, u32 *value);
char* readNextHex(const char* pLine, uint32_t *value);

u16 resetCrc(void);
uint16_t resetCrc(void);

u16 updateCrc(u8 byte);
uint16_t updateCrc(uint8_t byte);

u16 calculateCrc(u8* pData, int length);
uint16_t calculateCrc(uint8_t* pData, int length);

bool
parseLine(const char* pLine,
u32 *mMemoryAddress,
uint32_t *mMemoryAddress,
CRC_CONTEXT *context,
u8 *mainImageData);
uint8_t *mainImageData);

u16 mCrc = 0;
uint16_t mCrc = 0;

void
dumpImageData(u8 *data, u32 dataLength, OFFSET_LIST *offsetToSkipList)
dumpImageData(uint8_t *data, uint32_t dataLength, OFFSET_LIST *offsetToSkipList)
{
bool dontPrint = false;

u32 i, c;
u32 offsetToSkipCount = 0;
uint32_t i, c;
uint32_t offsetToSkipCount = 0;

if (offsetToSkipList != NULL) {
offsetToSkipCount = offsetToSkipList->count;
Expand Down Expand Up @@ -140,15 +127,15 @@ dumpImageData(u8 *data, u32 dataLength, OFFSET_LIST *offsetToSkipList)
printf("\n");
}

u16
uint16_t
resetCrc(void)
{
mCrc = 0xFFFF;
return mCrc;
}

u16
updateCrc(u8 byte)
uint16_t
updateCrc(uint8_t byte)
{
bool x;
int i;
Expand All @@ -163,8 +150,8 @@ updateCrc(u8 byte)
return mCrc;
}

u16
calculateCrc(u8* pData, int length)
uint16_t
calculateCrc(uint8_t* pData, int length)
{
//resetCrc();
for (; length; --length, ++pData) {
Expand All @@ -174,9 +161,9 @@ calculateCrc(u8* pData, int length)
}

char*
readNextHex(const char* pLine, u32 *pValue)
readNextHex(const char* pLine, uint32_t *pValue)
{
u32 value = 0;
uint32_t value = 0;

// Skip leading white space
while (*pLine != '\0' && *pLine <= ' ') {
Expand Down Expand Up @@ -208,26 +195,23 @@ readNextHex(const char* pLine, u32 *pValue)

bool
parseLine(const char* pLine,
u32 *mMemoryAddress,
uint32_t *mMemoryAddress,
CRC_CONTEXT *context,
u8 *mainImageData)
uint8_t *mainImageData)
{
u8 data[0x100];
uint8_t data[0x100];
int dataLength = 0;
u32 value;
int length = strlen(pLine);
u16 data16[2];
u8 value8;
uint32_t value;

u32 offsetToCopy = 0;
uint32_t offsetToCopy = 0;
#ifdef DEBUG
int i;
#endif

if (*pLine == '@') {
// This is a memory address
if (readNextHex(pLine + 1, &value) != NULL) {
*mMemoryAddress = (u16) value;
*mMemoryAddress = (uint16_t) value;
#ifdef DEBUG
printf("@Memory Address: 0x%x\n", *mMemoryAddress);
#endif // DEBUG
Expand Down Expand Up @@ -280,18 +264,21 @@ parseLine(const char* pLine,
//
// added by rananth to calculate the CRC of the main image data.
//
if ((*mMemoryAddress >= context->mainImageStartAddress) &&
(*mMemoryAddress < (context->mainImageStartAddress + context->mainImageTotalLength))) {
if ((*mMemoryAddress >= context->mainImageStartAddress) &&
(*mMemoryAddress <
(context->mainImageStartAddress + context->mainImageTotalLength)))
{

if ((context->mainImageStartAddress != 0) && (context->mainImageTotalLength != 0) &&
if ( (context->mainImageStartAddress != 0)
&& (context->mainImageTotalLength != 0) &&
(mainImageData != NULL)) {

//
// Copy the main image data bytes (Range: @8000, 0x8000) to the
// passed in data buffer.
//
offsetToCopy = *mMemoryAddress - context->mainImageStartAddress;
memcpy(mainImageData + offsetToCopy, data, dataLength);
memcpy(mainImageData + offsetToCopy, data, dataLength);

#ifdef DEBUG
printf("Copy data (%04x) dataLength (0x%x):",
Expand All @@ -312,21 +299,18 @@ parseLine(const char* pLine,
int
ProcessFile(char *pFilename, bool verbose)
{
bool error = false;
char buffer[0x100];
int length;
int retry;
int line;
int offset = 0;

u8 *mainImageData = 0;
uint8_t *mainImageData = 0;

u32 mMemoryAddress = 0;
u32 crc = 0;
u32 offsetToSkip;
u32 offsetToInsert;
u32 firstPortion = 0;
u32 secondPortion = 0;
uint32_t mMemoryAddress = 0;
uint32_t crc = 0;
uint32_t offsetToSkip;
uint32_t offsetToInsert;
uint32_t firstPortion = 0;
uint32_t secondPortion = 0;

CRC_CONTEXT context;
OFFSET_LIST offsetList;
Expand All @@ -343,20 +327,18 @@ ProcessFile(char *pFilename, bool verbose)
}
}

int lineCount = line;

// Rewind to the beginning of the file
fseek(pFile, 0, SEEK_SET);

//
// allocate memory for the main image data
// allocate memory for the main image data
//
mainImageData = (u8 *) malloc(FW_MAINIMAGE_MAX_LENGTH);
mainImageData = (uint8_t *) malloc(FW_MAINIMAGE_MAX_LENGTH);
memset(mainImageData, 0xFF, FW_MAINIMAGE_MAX_LENGTH);

memset(&context, 0, sizeof(CRC_CONTEXT));

bool validSection = true;
// Process the lines
for (line = 0; !feof(pFile); ++line) {
if (fgets(buffer, sizeof(buffer), pFile) == NULL) {
Expand Down Expand Up @@ -418,7 +400,7 @@ ProcessFile(char *pFilename, bool verbose)
offsetToSkip = ADDRESS_IMAGE_CRC - context.mainImageStartAddress;
mainImageData[offsetToSkip] = 0xFF;
mainImageData[offsetToSkip + 1] = 0xFF;

offsetToSkip = ADDRESS_RESET_VECTOR - context.mainImageStartAddress;
mainImageData[offsetToSkip] = 0xFF;
mainImageData[offsetToSkip + 1] = 0xFF;
Expand Down
50 changes: 30 additions & 20 deletions src/build/buildpnor/bpm-utils/insertBpmFwCrc.py
Expand Up @@ -27,6 +27,7 @@
#
#
# IBM_PROLOG_END_TAG

import os, sys, time, datetime, glob
from subprocess import Popen, PIPE
import shlex
Expand All @@ -36,7 +37,7 @@
# firmware image file, inFile, and to generate the
# signature file, outFile.
#
def InsertCrcSignature(inFile, outFile):
def InsertCrcSignature(inFile, outFile, crcProgram):

#
# Open the outFile
Expand Down Expand Up @@ -74,9 +75,7 @@ def InsertCrcSignature(inFile, outFile):
# ....

# Call imageCrc here
cmd = './imageCrc ' + inFile
cmdArgs = shlex.split(cmd)
proc = Popen(cmdArgs, stdout=PIPE, stderr=PIPE)
proc = Popen([crcProgram, inFile], stdout=PIPE, stderr=PIPE)
out,err = proc.communicate()
exitCode = proc.returncode

Expand All @@ -86,15 +85,15 @@ def InsertCrcSignature(inFile, outFile):
print "Command stderr - \n{0}".format(err)
sys.exit(999)
else:
print "\nCRC generation using imageCrc utility successful"
print "\nCRC generation using imageCrc utility successful"
print "Command output - \n{0}".format(out)

# Parse through output of imageCrc and get addr and signature
splitLines_crc = out.splitlines()
for counter in range(0, len(splitLines_crc)):

if splitLines_crc[counter].startswith("@"):
crcAddressLine = splitLines_crc[counter].strip()
crcAddressLine = splitLines_crc[counter]
crcSignature = splitLines_crc[counter+1].strip().upper()

# Open infile here
Expand All @@ -116,20 +115,22 @@ def InsertCrcSignature(inFile, outFile):
# If crc already in input file, check if it is equal to calculate value
# If equal, write only once, if not equal, write calculated value
if crcWritten == 0 and inputFileAddr == crcAddressLine:
outFileObj.write(line.strip()+'\n')
if ins.next().strip().upper() == crcSignature:
outFileObj.write(line.strip()+' \n')
if ins.next().upper() == crcSignature:
print "Correct crc already present at {0} in input file, will skip writing calculated crc again to output file".format(inputFileAddr)
else:
print "Incorrect crc present at {0} in input file, will write calculated crc {1} to output file".format(inputFileAddr, crcSignature)
outFileObj.write(crcSignature+'\n')
outFileObj.write(crcSignature+' \n')
crcWritten = 1
continue
# If crc not present, then write calculated value
elif crcWritten == 0 and inputFileAddr > crcAddressLine:
outFileObj.write(crcAddressLine+'\n')
outFileObj.write(crcSignature+'\n')
outFileObj.write(crcSignature+' \n')
crcWritten = 1
outFileObj.write(line.strip()+'\n')
outFileObj.write(inputFileAddr.strip()+'\n')
else:
outFileObj.write(line.strip()+' \n')

except Exception as e:
print "\nException {0} occured, args: {1!r}".format(type(e).__name__, e.args)
Expand All @@ -138,7 +139,7 @@ def InsertCrcSignature(inFile, outFile):
print("\nClosing Files\n")
outFileObj.close()

## End of insertCrcSignature #########
## End of insertCrcSignature #########


#
Expand All @@ -148,9 +149,10 @@ def InsertCrcSignature(inFile, outFile):

inFile=""
outFile=""
crcProgram=""

if (len(sys.argv) < 3):
print "\nUsage: %s <IN FILE> <OUT FILE>\n" % sys.argv[0]
if (len(sys.argv) < 4):
print "\nUsage: %s <IN FILE> <OUT FILE> <CRC PROGRAM>\n" % sys.argv[0]
sys.exit(1)
else:
#
Expand All @@ -164,18 +166,26 @@ def InsertCrcSignature(inFile, outFile):
print "\nInput File {0} does not exist or is zero in size".format(inFile)
#
# Name of the firmware image file to be generated with the signature
# Please check with Mike on the name for this.
#
outFile = sys.argv[2]
if '/' not in outFile:
outFile = os.getcwd() + '/' + outFile
outFile = os.getcwd() + '/' + outFile

if os.path.exists(outFile):
print "\nOutput File {0} already exists, will be wiped out if test successful, press CTRL-C in 5s to stop test if needed".format(outFile)
time.sleep(5)
print "\nOutput File {0} already exists, will be overwritten".format(outFile)

#
# Name of the CRC calculation program to be used to calculate the
# firmware image CRC
#
crcProgram = sys.argv[3]
if '/' not in crcProgram:
crcProgram = os.getcwd() + '/' + crcProgram

if not os.path.exists(crcProgram) or os.path.getsize(crcProgram) == 0:
print "\nCRC Program {0} does not exist or is zero in size".format(crcProgram)


#
# Call the function to insert the CRC signature
#
InsertCrcSignature(inFile, outFile)
InsertCrcSignature(inFile, outFile, crcProgram)

0 comments on commit 72f32c4

Please sign in to comment.