[coreboot-gerrit] New patch to review for coreboot: mediatek/mt8173: Add gen-bl-img.py for mt8173 bootblock code
Patrick Georgi (pgeorgi@google.com)
gerrit at coreboot.org
Tue Dec 1 19:58:04 CET 2015
Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12613
-gerrit
commit 2b3539bd65fe81249c08c0ffdaca0577a647ef5f
Author: Yidi Lin <yidi.lin at mediatek.com>
Date: Fri Jul 31 17:10:48 2015 +0800
mediatek/mt8173: Add gen-bl-img.py for mt8173 bootblock code
BUG=none
TEST=emerge-oak coreboot
BRANCH=none
Change-Id: I7486e548d356c5bd27261851f1f1bed620715e91
Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
Original-Commit-Id: fbcd7959e0fda595de91899ace7236037ac833d3
Original-Change-Id: Ib9df440bfa95cf06e8041491ecdb34c357047acd
Original-Signed-off-by: Yidi Lin <yidi.lin at mediatek.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/292664
Original-Reviewed-by: Julius Werner <jwerner at chromium.org>
---
src/soc/mediatek/mt8173/Makefile.inc | 4 ++
util/mtkheader/gen-bl-img.py | 95 ++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
diff --git a/src/soc/mediatek/mt8173/Makefile.inc b/src/soc/mediatek/mt8173/Makefile.inc
index 53dc9ff..4321989 100644
--- a/src/soc/mediatek/mt8173/Makefile.inc
+++ b/src/soc/mediatek/mt8173/Makefile.inc
@@ -65,6 +65,10 @@ ramstage-y += wdt.c
################################################################################
+# Generate the actual coreboot bootblock code
+$(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.raw.bin
+ ./util/mtkheader/gen-bl-img.py mt8173 sf $< $@
+
CPPFLAGS_common += -Isrc/soc/mediatek/mt8173/include
endif
diff --git a/util/mtkheader/gen-bl-img.py b/util/mtkheader/gen-bl-img.py
new file mode 100755
index 0000000..700ebe0
--- /dev/null
+++ b/util/mtkheader/gen-bl-img.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+
+#
+# This file is part of the coreboot project.
+#
+# Copyright (c) 2015 MediaTek Inc.
+# Author: Tristan Shieh <tristan.shieh at mediatek.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+import struct
+import sys
+import hashlib
+
+def read(path):
+ with open(path, "rb") as f:
+ return f.read()
+
+def write(path, data):
+ with open(path, "wb") as f:
+ f.write(data)
+
+def padding(data, size, pattern = '\0'):
+ return data + pattern * (size - len(data))
+
+def align(data, size, pattern = '\0'):
+ return padding(data, (len(data) + (size - 1)) & ~(size - 1), pattern)
+
+gfh_infos = {
+ 'mt8173': struct.pack("44I",
+ 0x014d4d4d, 0x00000038, 0x454c4946, 0x464e495f,
+ 0x0000004f, 0x00000001, 0x01050001, 0x000C0f50,
+ 0xffffffff, 0x00020000, 0x000000a8, 0x00000020,
+ 0x000000B0, 0x00000001, 0x014d4d4d, 0x0001000c,
+ 0x00000001, 0x034d4d4d, 0x00070064, 0x00001182,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00006400, 0x00001388,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ )}
+
+def gen_emmc_header(data):
+ header = (padding(struct.pack("<12sII", "EMMC_BOOT", 1, 512), 512, '\xff') +
+ padding(struct.pack("<8sIIIIIIII", "BRLYT", 1, 2048, 2048 + len(data),
+ 0x42424242, 0x00010005, 2048, 2048 + len(data), 1) + '\0' * 140, 512, '\xff') +
+ '\0' * 1024)
+ return header
+
+def gen_sf_header(data):
+ header = (padding(struct.pack("<12sII", "SF_BOOT", 1, 512), 512, '\xff') +
+ padding(struct.pack("<8sIIIIIIII", "BRLYT", 1, 2048, 2048 + len(data),
+ 0x42424242, 0x00010007, 2048, 2048 + len(data), 1) + '\0' * 140, 512, '\xff') +
+ '\0' * 1024)
+ return header
+
+gen_dev_header = {
+ "emmc": gen_emmc_header,
+ "sf": gen_sf_header
+}
+
+def gen_preloader(chip_ver, flash_type, data):
+ gfh_info = gfh_infos[chip_ver]
+ gfh_info = gfh_info[0:32] + struct.pack("1I", len(data)+len(gfh_info)+32) + gfh_info[36:len(gfh_info)]
+
+ gfh_hash = hashlib.sha256(gfh_info + data).digest()
+
+ data = align(gfh_info + data + gfh_hash, 512, '\xff')
+ header = gen_dev_header[flash_type](data)
+ return header + data
+
+def main(argv):
+ if len(argv) != 5:
+ print "Usage: %s <chip> <flash_type> <input_file> <output_file>" % argv[0]
+ print "\t flash_type: emmc/sf"
+ print "\t chip : mt8173"
+
+ exit(1)
+ write(argv[4], gen_preloader(argv[1], argv[2], read(argv[3])))
+
+if __name__ == "__main__":
+ main(sys.argv)
More information about the coreboot-gerrit
mailing list