From 817e455d38d9ec6730fa27ee13e9ae123b1dc632 Mon Sep 17 00:00:00 2001 From: huang lin Date: Tue, 26 Aug 2014 17:31:28 +0800 Subject: add make_idb.py & update bootblock BUG=chrome-os-partner:29778 TEST=Build coreboot Change-Id: Ica7b2bf2cf649c2731933ce59a263692bb2c0282 Signed-off-by: Patrick Georgi Original-Commit-Id: ba9c36daedc749748f45e68a84f8c34c636adb1c Original-Change-Id: Ia0e4e39d4391674f25e630b40913eb99ff3f75c4 Original-Signed-off-by: Jeffy Chen Original-Signed-off-by: huang lin Original-Reviewed-on: https://chromium-review.googlesource.com/209427 Original-Reviewed-by: David Hendricks Original-Commit-Queue: Julius Werner Reviewed-on: http://review.coreboot.org/8862 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/rockchip/LICENSE | 25 ++++++++++ util/rockchip/make_idb.py | 124 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 util/rockchip/LICENSE create mode 100755 util/rockchip/make_idb.py (limited to 'util') diff --git a/util/rockchip/LICENSE b/util/rockchip/LICENSE new file mode 100644 index 0000000000..cb4d35b256 --- /dev/null +++ b/util/rockchip/LICENSE @@ -0,0 +1,25 @@ +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/util/rockchip/make_idb.py b/util/rockchip/make_idb.py new file mode 100755 index 0000000000..e95f5c2fd7 --- /dev/null +++ b/util/rockchip/make_idb.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import struct +import sys +from io import SEEK_SET, SEEK_END + +class IDBTool: + def __init__(self): + print "Initialize IDBTool" + + def p_rc4(self, buf, length): + key = (124,78,3,4,85,5,9,7,45,44,123,56,23,13,23,17) + K = key * 16 + S = [i for i in range(256)] + + j = 0 + for i in range(256): + j = (j + S[i] + K[i]) % 256 + temp = S[i]; S[i] = S[j]; S[j] = temp; + + i = j = k = 0 + for x in range(length): + i = (i+1) % 256 + j = (j + S[i]) % 256 + temp = S[i]; S[i] = S[j]; S[j] = temp + k = (S[i] + S[j]) % 256 + buf[x] = struct.pack('B', ord(buf[x]) ^ S[k]) + + def makeIDB(self, from_file, to_file, rc4_flag = False, align_flag = False): + try: + fin = open(from_file, 'rb') + except: + sys.exit("Failed to open file : " + from_file) + + try: + fin.seek(0, SEEK_END) + if (fin.tell() > 4 * 1024 * 1024): + sys.exit("Input file is more than 4MB") + fin.seek(0) + data = fin.read() + finally: + fin.close() + + data_len = len(data) + SECTOR_SIZE = 512 + PAGE_ALIGN = 4 + sectors = (data_len + 4 - 1) / SECTOR_SIZE + 1 + pages = (sectors - 1) / PAGE_ALIGN + 1 + sectors = pages * PAGE_ALIGN; + + buf = [B'\0'] * sectors * SECTOR_SIZE + buf[:4] = "RK32" + buf[4 : 4+data_len] = data + + idblock = [B'\0'] * 4 * SECTOR_SIZE + blank = [B'\0'] * 4 * SECTOR_SIZE + idblock[:4] = ['\x55', '\xAA', '\xF0', '\x0F'] + + if (not rc4_flag): + idblock[8:12] = struct.pack("