diff options
author | Nick Sanders <nsanders@google.com> | 2011-03-03 11:37:54 -0800 |
---|---|---|
committer | Nick Sanders <nsanders@google.com> | 2011-03-03 11:37:54 -0800 |
commit | e328d563541eb5dfcb354bf4265a75103982bf35 (patch) | |
tree | 5ff60fbf34ffe08505856df819fd71feba479ea0 | |
parent | 8478ece80f50b4b890458559f82fc1f9a6fd0b54 (diff) | |
download | vboot-e328d563541eb5dfcb354bf4265a75103982bf35.tar.gz |
Bitmap generator for components files
BUG=chrome-os-partner:2558
TEST=some files are generated
Change-Id: I6a69bce20d626e9a273711db099d7ec5c3b08686
Review URL: http://codereview.chromium.org/6598091
-rw-r--r-- | scripts/newbitmaps/HWID.txt | 2 | ||||
-rwxr-xr-x | scripts/newbitmaps/make_bmp_from_components.py | 86 |
2 files changed, 87 insertions, 1 deletions
diff --git a/scripts/newbitmaps/HWID.txt b/scripts/newbitmaps/HWID.txt index faf9479c..eb10e33a 100644 --- a/scripts/newbitmaps/HWID.txt +++ b/scripts/newbitmaps/HWID.txt @@ -31,7 +31,7 @@ Here's how to generate a new bitmap blob with a modified HWID starts with "hwid:" to refer to your new hwid.bmp file (or replace the existing hwid bitmap file with your new one). -7. Run "bmpblock_utility -c unknown.yaml new_bitmaps.bin", to create the new +7. Run "bmpblk_utility -c unknown.yaml new_bitmaps.bin", to create the new bitmap blob. 8. Install the new_bitmaps.bin on your device (see below). diff --git a/scripts/newbitmaps/make_bmp_from_components.py b/scripts/newbitmaps/make_bmp_from_components.py new file mode 100755 index 00000000..ad4c3d4e --- /dev/null +++ b/scripts/newbitmaps/make_bmp_from_components.py @@ -0,0 +1,86 @@ +#!/usr/bin/python2.6 +# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Call on a directory with components_XXX_XXX files, to create +# bitmaps with the appropriate names and contents. + +import sys +import glob +import os +import re +import tempfile + + +if len(sys.argv) < 2: + print "usage: %s autotest/../hardware_Components/" % sys.argv[0] + sys.exit(1) + + +def MakeBmp(hwid, geom, bmp, directory): + """ Create the bitmap for this file. """ + tmpdir = tempfile.mkdtemp() + tmpfile = os.path.join(tmpdir, "hwid.txt") + tmpbmpname = os.path.join(tmpdir, "hwid.bmp") + f = open(tmpfile, "w") + f.write(hwid) + f.close() + + # Call bitmap making tools. + txt_to_bmp = ("~/trunk/src/platform/vboot_reference/" + "scripts/newbitmaps/strings/text_to_bmp") + imagedir = os.path.join( + "~/trunk/src/platform/vboot_reference/scripts/newbitmaps/images", geom) + yamlfile = os.path.join(imagedir, "unknown.yaml") + newyamlfile = os.path.join(imagedir, "hwid.yaml") + outputbmp = os.path.join(directory, bmp) + + os.system("%s %s > /dev/null" % (txt_to_bmp, tmpfile)) + os.system("cat %s | sed 's#hwid_unknown.bmp#%s#' > %s" % ( + yamlfile, tmpbmpname, newyamlfile)) + os.system("pushd %s >/dev/null; bmpblk_utility -c %s %s; popd >/dev/null" % ( + imagedir, newyamlfile, outputbmp)) + os.system("rm -rf %s" % tmpdir) + +def ProcessDir(directory): + """ Find all the components file in this dir. """ + # Regex to find the values we want. + re_bmp = re.compile(r'\'data_bitmap_fv\': \[\'(?P<bmp>.*)\'\],') + re_hwid = re.compile(r'\'part_id_hwqual\': \[\'(?P<hwid>.*)\'\],') + re_geom = re.compile(r'\'data_display_geometry\': \[\'(?P<geom>.*)\'\],') + + # Find the components files. + files = glob.glob(os.path.join(directory, "data_*/components_*")) + for file in files: + # Scan for the values. + f = open(file, "r") + bmp = None + hwid = None + geom = None + for line in f.readlines(): + m = re_bmp.search(line) + if m: + bmp = m.group('bmp') + + m = re_hwid.search(line) + if m: + hwid = m.group('hwid') + + m = re_geom.search(line) + if m: + geom = m.group('geom') + f.close() + if not ( bmp and hwid and geom): + print "Corrupt HWID configuration" + sys.exit(1) + print "HWID: %s, %s, %s" % (hwid, geom, bmp) + MakeBmp(hwid, geom, bmp, directory) + +def main(): + directory = os.path.abspath(sys.argv[1]) + print "Generating HWID bmp based on %s" % directory + ProcessDir(directory) + +if __name__ == '__main__': + main() |