coreboot-kgpe-d16/util/qualcomm/mbncat.py

178 lines
5.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
# Copyright (c) 2014, The Linux Foundation. All rights reserved.
#
treewide: Replace BSD-3-Clause and ISC headers with SPDX headers Commands used: perl -i -p0e 's|\/\*[*\s]*Permission[*\s]*to[*\s]*use,[*\s]*copy,[*\s]*modify,[*\s]*and.or[*\s]*distribute[*\s]*this[*\s]*software[*\s]*for[*\s]*any[*\s]*purpose[*\s]*with[*\s]*or[*\s]*without[*\s]*fee[*\s]*is[*\s]*hereby[*\s]*granted,[*\s]*provided[*\s]*that[*\s]*the[*\s]*above[*\s]*copyright[*\s]*notice[*\s]*and[*\s]*this[*\s]*permission[*\s]*notice[*\s]*appear[*\s]*in[*\s]*all[*\s]*copies.[*\s]*THE[*\s]*SOFTWARE[*\s]*IS[*\s]*PROVIDED[*\s]*.*AS[*\s]*IS.*[*\s]*AND[*\s]*THE[*\s]*AUTHOR[*\s]*DISCLAIMS[*\s]*ALL[*\s]*WARRANTIES[*\s]*WITH[*\s]*REGARD[*\s]*TO[*\s]*THIS[*\s]*SOFTWARE[*\s]*INCLUDING[*\s]*ALL[*\s]*IMPLIED[*\s]*WARRANTIES[*\s]*OF[*\s]*MERCHANTABILITY[*\s]*AND[*\s]*FITNESS.[*\s]*IN[*\s]*NO[*\s]*EVENT[*\s]*SHALL[*\s]*THE[*\s]*AUTHOR[*\s]*BE[*\s]*LIABLE[*\s]*FOR[*\s]*ANY[*\s]*SPECIAL,[*\s]*DIRECT,[*\s]*INDIRECT,[*\s]*OR[*\s]*CONSEQUENTIAL[*\s]*DAMAGES[*\s]*OR[*\s]*ANY[*\s]*DAMAGES[*\s]*WHATSOEVER[*\s]*RESULTING[*\s]*FROM[*\s]*LOSS[*\s]*OF[*\s]*USE,[*\s]*DATA[*\s]*OR[*\s]*PROFITS,[*\s]*WHETHER[*\s]*IN[*\s]*AN[*\s]*ACTION[*\s]*OF[*\s]*CONTRACT,[*\s]*NEGLIGENCE[*\s]*OR[*\s]*OTHER[*\s]*TORTIOUS[*\s]*ACTION,[*\s]*ARISING[*\s]*OUT[*\s]*OF[*\s]*OR[*\s]*IN[*\s]*CONNECTION[*\s]*WITH[*\s]*THE[*\s]*USE[*\s]*OR[*\s]*PERFORMANCE[*\s]*OF[*\s]*THIS[*\s]*SOFTWARE.[*\s]*\*\/|/* SPDX-License-Identifier: ISC */|s' $(cat filelist) perl -i -p0e 's|(\#\#*)\s*Permission[\#\s]*to[\#\s]*use,[\#\s]*copy,[\#\s]*modify,[\#\s]*and.or[\#\s]*distribute[\#\s]*this[\#\s]*software[\#\s]*for[\#\s]*any[\#\s]*purpose[\#\s]*with[\#\s]*or[\#\s]*without[\#\s]*fee[\#\s]*is[\#\s]*hereby[\#\s]*granted,[\#\s]*provided[\#\s]*that[\#\s]*the[\#\s]*above[\#\s]*copyright[\#\s]*notice[\#\s]*and[\#\s]*this[\#\s]*permission[\#\s]*notice[\#\s]*appear[\#\s]*in[\#\s]*all[\#\s]*copies.[\#\s]*THE[\#\s]*SOFTWARE[\#\s]*IS[\#\s]*PROVIDED[\#\s]*.*AS[\#\s]*IS.*[\#\s]*AND[\#\s]*THE[\#\s]*AUTHOR[\#\s]*DISCLAIMS[\#\s]*ALL[\#\s]*WARRANTIES[\#\s]*WITH[\#\s]*REGARD[\#\s]*TO[\#\s]*THIS[\#\s]*SOFTWARE[\#\s]*INCLUDING[\#\s]*ALL[\#\s]*IMPLIED[\#\s]*WARRANTIES[\#\s]*OF[\#\s]*MERCHANTABILITY[\#\s]*AND[\#\s]*FITNESS.[\#\s]*IN[\#\s]*NO[\#\s]*EVENT[\#\s]*SHALL[\#\s]*THE[\#\s]*AUTHOR[\#\s]*BE[\#\s]*LIABLE[\#\s]*FOR[\#\s]*ANY[\#\s]*SPECIAL,[\#\s]*DIRECT,[\#\s]*INDIRECT,[\#\s]*OR[\#\s]*CONSEQUENTIAL[\#\s]*DAMAGES[\#\s]*OR[\#\s]*ANY[\#\s]*DAMAGES[\#\s]*WHATSOEVER[\#\s]*RESULTING[\#\s]*FROM[\#\s]*LOSS[\#\s]*OF[\#\s]*USE,[\#\s]*DATA[\#\s]*OR[\#\s]*PROFITS,[\#\s]*WHETHER[\#\s]*IN[\#\s]*AN[\#\s]*ACTION[\#\s]*OF[\#\s]*CONTRACT,[\#\s]*NEGLIGENCE[\#\s]*OR[\#\s]*OTHER[\#\s]*TORTIOUS[\#\s]*ACTION,[\#\s]*ARISING[\#\s]*OUT[\#\s]*OF[\#\s]*OR[\#\s]*IN[\#\s]*CONNECTION[\#\s]*WITH[\#\s]*THE[\#\s]*USE[\#\s]*OR[\#\s]*PERFORMANCE[\#\s]*OF[\#\s]*THIS[\#\s]*SOFTWARE.\s(\#* *\n)*|\1 SPDX-License-Identifier: ISC\n\n|s' $(cat filelist) perl -i -p0e 's|\/\*[*\s]*Redistribution[*\s]*and[*\s]*use[*\s]*in[*\s]*source[*\s]*and[*\s]*binary[*\s]*forms,[*\s]*with[*\s]*or[*\s]*without[*\s]*modification,[*\s]*are[*\s]*permitted[*\s]*provided[*\s]*that[*\s]*the[*\s]*following[*\s]*conditions[*\s]*are[*\s]*met:[*\s]*[1. ]*Redistributions[*\s]*of[*\s]*source[*\s]*code[*\s]*must[*\s]*retain[*\s]*the[*\s]*above[*\s]*copyright[*\s]*notice,[*\s]*this[*\s]*list[*\s]*of[*\s]*conditions[*\s]*and[*\s]*the[*\s]*following[*\s]*disclaimer.[*\s]*[*\s]*[2. ]*Redistributions[*\s]*in[*\s]*binary[*\s]*form[*\s]*must[*\s]*reproduce[*\s]*the[*\s]*above[*\s]*copyright[*\s]*notice,[*\s]*this[*\s]*list[*\s]*of[*\s]*conditions[*\s]*and[*\s]*the[*\s]*following[*\s]*disclaimer[*\s]*in[*\s]*the[*\s]*documentation[*\s]*and.or[*\s]*other[*\s]*materials[*\s]*provided[*\s]*with[*\s]*the[*\s]*distribution.[*\s]*[3. ]*.*used[*\s]*to[*\s]*endorse[*\s]*or[*\s]*promote[*\s]*products[*\s]*derived[*\s]*from[*\s]*this[*\s]*software[*\s]*without[*\s]*specific[*\s]*prior[*\s]*written[*\s]*permission.[*\s]*THIS[*\s]*SOFTWARE[*\s]*IS[*\s]*PROVIDED.*AS[*\s]*IS.*[*\s]*AND[*\s]*ANY[*\s]*EXPRESS[*\s]*OR[*\s]*IMPLIED[*\s]*WARRANTIES,[*\s]*INCLUDING,[*\s]*BUT[*\s]*NOT[*\s]*LIMITED[*\s]*TO,[*\s]*THE[*\s]*IMPLIED[*\s]*WARRANTIES[*\s]*OF[*\s]*MERCHANTABILITY.*FITNESS[*\s]*FOR[*\s]*A[*\s]*PARTICULAR[*\s]*PURPOSE.*ARE[*\s]*DISCLAIMED.[*\s]*IN[*\s]*NO[*\s]*EVENT[*\s]*SHALL.*LIABLE[*\s]*FOR[*\s]*ANY[*\s]*DIRECT,[*\s]*INDIRECT,[*\s]*INCIDENTAL,[*\s]*SPECIAL,[*\s]*EXEMPLARY,[*\s]*OR[*\s]*CONSEQUENTIAL[*\s]*DAMAGES[*\s]*.INCLUDING,[*\s]*BUT[*\s]*NOT[*\s]*LIMITED[*\s]*TO,[*\s]*PROCUREMENT[*\s]*OF[*\s]*SUBSTITUTE[*\s]*GOODS[*\s]*OR[*\s]*SERVICES;[*\s]*LOSS[*\s]*OF[*\s]*USE,[*\s]*DATA,[*\s]*OR[*\s]*PROFITS;[*\s]*OR[*\s]*BUSINESS[*\s]*INTERRUPTION.[*\s]*HOWEVER[*\s]*CAUSED[*\s]*AND[*\s]*ON[*\s]*ANY[*\s]*THEORY[*\s]*OF[*\s]*LIABILITY,[*\s]*WHETHER[*\s]*IN[*\s]*CONTRACT,[*\s]*STRICT[*\s]*LIABILITY,[*\s]*OR[*\s]*TORT[*\s]*.INCLUDING[*\s]*NEGLIGENCE[*\s]*OR[*\s]*OTHERWISE.[*\s]*ARISING[*\s]*IN[*\s]*ANY[*\s]*WAY[*\s]*OUT[*\s]*OF[*\s]*THE[*\s]*USE[*\s]*OF[*\s]*THIS[*\s]*SOFTWARE,[*\s]*EVEN[*\s]*IF[*\s]*ADVISED[*\s]*OF[*\s]*THE[*\s]*POSSIBILITY[*\s]*OF[*\s]*SUCH[*\s]*DAMAGE.[*\s]*\*\/|/* SPDX-License-Identifier: BSD-3-Clause */|s' $(cat filelist) $1 perl -i -p0e 's|(\#\#*) *Redistribution[\#\s]*and[\#\s]*use[\#\s]*in[\#\s]*source[\#\s]*and[\#\s]*binary[\#\s]*forms,[\#\s]*with[\#\s]*or[\#\s]*without[\#\s]*modification,[\#\s]*are[\#\s]*permitted[\#\s]*provided[\#\s]*that[\#\s]*the[\#\s]*following[\#\s]*conditions[\#\s]*are[\#\s]*met:[\#\s]*[*1. ]*Redistributions[\#\s]*of[\#\s]*source[\#\s]*code[\#\s]*must[\#\s]*retain[\#\s]*the[\#\s]*above[\#\s]*copyright[\#\s]*notice,[\#\s]*this[\#\s]*list[\#\s]*of[\#\s]*conditions[\#\s]*and[\#\s]*the[\#\s]*following[\#\s]*disclaimer.[\#\s]*[*2. ]*Redistributions[\#\s]*in[\#\s]*binary[\#\s]*form[\#\s]*must[\#\s]*reproduce[\#\s]*the[\#\s]*above[\#\s]*copyright[\#\s]*notice,[\#\s]*this[\#\s]*list[\#\s]*of[\#\s]*conditions[\#\s]*and[\#\s]*the[\#\s]*following[\#\s]*disclaimer[\#\s]*in[\#\s]*the[\#\s]*documentation[\#\s]*and.or[\#\s]*other[\#\s]*materials[\#\s]*provided[\#\s]*with[\#\s]*the[\#\s]*distribution.[\#\s]*[\#\s]*[*3. ]*.*used[\#\s]*to[\#\s]*endorse[\#\s]*or[\#\s]*promote[\#\s]*products[\#\s]*derived[\#\s]*from[\#\s]*this[\#\s]*software[\#\s]*without[\#\s]*specific[\#\s]*prior[\#\s]*written[\#\s]*permission.[\#\s]*THIS[\#\s]*SOFTWARE[\#\s]*IS[\#\s]*PROVIDED.*AS[\#\s]*IS.*[\#\s]*AND[\#\s]*ANY[\#\s]*EXPRESS[\#\s]*OR[\#\s]*IMPLIED[\#\s]*WARRANTIES,[\#\s]*INCLUDING,[\#\s]*BUT[\#\s]*NOT[\#\s]*LIMITED[\#\s]*TO,[\#\s]*THE[\#\s]*IMPLIED[\#\s]*WARRANTIES[\#\s]*OF[\#\s]*MERCHANTABILITY.*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.*ARE[\#\s]*DISCLAIMED.[\#\s]*IN[\#\s]*NO[\#\s]*EVENT[\#\s]*SHALL.*LIABLE[\#\s]*FOR[\#\s]*ANY[\#\s]*DIRECT,[\#\s]*INDIRECT,[\#\s]*INCIDENTAL,[\#\s]*SPECIAL,[\#\s]*EXEMPLARY,[\#\s]*OR[\#\s]*CONSEQUENTIAL[\#\s]*DAMAGES[\#\s]*.INCLUDING,[\#\s]*BUT[\#\s]*NOT[\#\s]*LIMITED[\#\s]*TO,[\#\s]*PROCUREMENT[\#\s]*OF[\#\s]*SUBSTITUTE[\#\s]*GOODS[\#\s]*OR[\#\s]*SERVICES;[\#\s]*LOSS[\#\s]*OF[\#\s]*USE,[\#\s]*DATA,[\#\s]*OR[\#\s]*PROFITS;[\#\s]*OR[\#\s]*BUSINESS[\#\s]*INTERRUPTION.[\#\s]*HOWEVER[\#\s]*CAUSED[\#\s]*AND[\#\s]*ON[\#\s]*ANY[\#\s]*THEORY[\#\s]*OF[\#\s]*LIABILITY,[\#\s]*WHETHER[\#\s]*IN[\#\s]*CONTRACT,[\#\s]*STRICT[\#\s]*LIABILITY,[\#\s]*OR[\#\s]*TORT[\#\s]*.INCLUDING[\#\s]*NEGLIGENCE[\#\s]*OR[\#\s]*OTHERWISE.[\#\s]*ARISING[\#\s]*IN[\#\s]*ANY[\#\s]*WAY[\#\s]*OUT[\#\s]*OF[\#\s]*THE[\#\s]*USE[\#\s]*OF[\#\s]*THIS[\#\s]*SOFTWARE,[\#\s]*EVEN[\#\s]*IF[\#\s]*ADVISED[\#\s]*OF[\#\s]*THE[\#\s]*POSSIBILITY[\#\s]*OF[\#\s]*SUCH[\#\s]*DAMAGE.\s(\#* *\n)*|\1 SPDX-License-Identifier: BSD-3-Clause\n\n|s' $(cat filelist) Change-Id: I7ff9c503a2efe1017a4666baf0b1a758a04f5634 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/41204 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
2020-05-10 18:47:05 +02:00
# SPDX-License-Identifier: BSD-3-Clause
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
import struct
import sys
import os
"""A utility to generate ipq8064 uber SBL..
The very first blob (aka 'uber SBL') read out of NOR SPI flash by the IPQ8064
maskrom is supposed to be a concatenation of up to three binaries: one to run
on the RPM, another one to run on the AP, and the third one - the actual
coreboot bootblock.
The uber SBL starts with the combined header descriptor of 80 bytes, with the
first two 4 byte words set to certain values, and the total size of the
payload saved at offsets 28 and 32.
To generate the uber SBL this utility expects two or three input file names in
the command line, the first file including the described header, and the
following one(s) - in QCA MBN format. This allows to create the uber SBL in
one or two invocations.
The input files are concatenated together aligned at 256 byte boundary offset
from the combined header. See Usage() below for more details.
The resulting uber SBL file is prepended by the same combined header adjusted
to reflect the new total file size.
"""
DEFAULT_OUTPUT_FILE_NAME = 'sbl-ro.mbn'
class NorSbl:
"""Object representing the uber SBL."""
NOR_SBL1_HEADER = '<II72s'
NOR_SBL1_HEADER_SZ = struct.calcsize(NOR_SBL1_HEADER)
ALIGNMENT = 256 # Make sure this == UBER_SBL_PAD_SIZE
NOR_CODE_WORD = 0x844bdcd1
MAGIC_NUM = 0x73d71034
def __init__(self, sbl1, verbose):
"""Initialize the object and verify the first file in the sequence.
Args:
sbl1: string, the name of the first out of the three input blobs,
must be prepended by the combined header.
verbose: boolean, if True - print debug information on the console.
"""
self.verbose = verbose
self.mbn_file_names = []
if self.verbose:
print('Reading ' + sbl1)
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
try:
self.sbl1 = open(sbl1, 'rb').read()
except IOError as e:
print('I/O error({0}): {1}'.format(e.errno, e.strerror))
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
raise
(codeword, magic, _) = struct.unpack_from(
self.NOR_SBL1_HEADER, self.sbl1)
if codeword != self.NOR_CODE_WORD:
print('\n\nError: Unexpected Codeword!')
print('Codeword : ' + ('0x%x' % self.NOR_CODE_WORD) + \
' != ' + ('0x%x' % codeword))
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
sys.exit(-1)
if magic != self.MAGIC_NUM:
print('\n\nError: Unexpected Magic!')
print('Magic : ' + ('0x%x' % self.MAGIC_NUM) + \
' != ' + ('0x%x' % magic))
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
sys.exit(-1)
def Append(self, src):
"""Add a file to the list of files to be concatenated"""
self.mbn_file_names.append(src)
def PadOutput(self, outfile, size):
"""Pad output file to the required alignment.
Adds 0xff to the passed in file to get its size to the ALIGNMENT
boundary.
Args:
outfile: file handle of the file to be padded
size: int, current size of the file
Returns number of bytes in the added padding.
"""
# Is padding needed?
overflow = size % self.ALIGNMENT
if overflow:
pad_size = self.ALIGNMENT - overflow
pad = b'\377' * pad_size
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
outfile.write(pad)
if self.verbose:
print('Added %d byte padding' % pad_size)
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
return pad_size
return 0
def Create(self, out_file_name):
"""Create the uber SBL.
Concatenate input files with the appropriate padding and update the
combined header to reflect the new blob size.
Args:
out_file_name: string, name of the file to save the generated uber
SBL in.
"""
outfile = open(out_file_name, 'wb')
total_size = len(self.sbl1) - self.NOR_SBL1_HEADER_SZ
outfile.write(self.sbl1)
for mbn_file_name in self.mbn_file_names:
total_size += self.PadOutput(outfile, total_size)
mbn_file_data = open(mbn_file_name, 'rb').read()
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
outfile.write(mbn_file_data)
if self.verbose:
print('Added %s (%d bytes)' % (mbn_file_name,
len(mbn_file_data)))
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
total_size += len(mbn_file_data)
outfile.seek(28)
outfile.write(struct.pack('<I', total_size))
outfile.write(struct.pack('<I', total_size))
def Usage(v):
print('%s: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock]' % (
os.path.basename(sys.argv[0])))
print()
print('Concatenates up to three mbn files: two SBLs and a coreboot bootblock')
print(' -h This message')
print(' -v verbose')
print(' -o Output file name, (default: %s)\n' % DEFAULT_OUTPUT_FILE_NAME)
util/ipqheader: Add utility to create uber-SBL for IPQ8064 With the Storm image layout reworked, the very first blob read out of NOR SPI flash by the IPQ8064 maskrom is supposed to be a concatenation of three binaries: one to run on RPM, another one to run on AP, and the third one - the actual coreboot bootblock. This layout allows to greatly reduce the size and complexity of the two first blobs, as they do not need to include the SPI driver. The first binary in the input file list starts with the combined header, describing the rest of the blob. This utility copies the first input file into output, updating the combined header with the total size of the concatenated binaries. The second and third binaries in the combined image are required to be aligned at 256 byte offsets in the file as counted from the end of the combined header. The new utility allows to concatenate two or three files, always expecting the first file to be prepended by the combined header. For further reference below is the utility's help message: mbncat.py: [-v] [-h] [-o Output MBN] sbl1 sbl2 [bootblock] Concatenates up to three mbn files: two SBLs and a coreboot bootblock -h This message -v verbose -o Output file name, (default: sbl-ro.mbn) BRANCH=none BUG=chrome-os-partner:34161 TEST=run the new utility and compare the result with the output of the vendor provided tool. The output files are exactly the same. Change-Id: I1d3b3634ecc3f46ea88adb9b6c4fbfc017cc06ac Signed-off-by: Stefan Reinauer <reinauer@chromium.org> Original-Commit-Id: 94008340bc5eaf19d286b3feaa4091e5c5e285aa Original-Change-Id: I00724f7c75703fc90d7971c3cb337c33ca96f2b5 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/232047 Original-Reviewed-by: Manoj Juneja <mjuneja@qti.qualcomm.com> Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: http://review.coreboot.org/9572 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-11-30 22:05:38 +01:00
sys.exit(v)
def main():
verbose = 0
mbn_output = DEFAULT_OUTPUT_FILE_NAME
i = 0
while i < (len(sys.argv) - 1):
i += 1
if (sys.argv[i] == '-h'):
Usage(0) # doesn't return
if (sys.argv[i] == '-o'):
mbn_output = sys.argv[i + 1]
i += 1
continue
if (sys.argv[i] == '-v'):
verbose = 1
continue
break
argv = sys.argv[i:]
if len(argv) < 2 or len(argv) > 3:
Usage(-1)
nsbl = NorSbl(argv[0], verbose)
for mbnf in argv[1:]:
nsbl.Append(mbnf)
nsbl.Create(mbn_output)
if __name__ == '__main__':
main()