summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-08-10 16:36:24 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-07 17:23:01 -0700
commitad546b47f698ef1bd4ec26cbd157334f61b50958 (patch)
tree38c8782412dbfbef29fcaa879ea061b60a7fdd4e
parentdde7e4c51831d542a52f166fa3fa2634b5b9b615 (diff)
downloadvboot-ad546b47f698ef1bd4ec26cbd157334f61b50958.tar.gz
Remove code for displaying screen from GBB
This patch removes the code displaying vboot screens using bitmap and layout data stored in GBB. bmpblk_utility, and futility support for BmpBlock is also removed. BUG=chromium:622501,chrome-os-partner:54619,b:124141368 BRANCH=none CQ-DEPEND=CL:373123 TEST=Verified screens on eve && emerge-eve chromeos-bootimage && make runtests Change-Id: I1a8dd8ff0162965e81df121d5a87ea64310a0854 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/367882 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org>
-rw-r--r--Makefile27
-rw-r--r--firmware/include/bmpblk_header.h149
-rw-r--r--firmware/lib/include/bmpblk_font.h63
-rw-r--r--firmware/lib/include/vboot_display.h2
-rw-r--r--firmware/lib/vboot_display.c1
-rw-r--r--futility/file_type_bios.c19
-rw-r--r--tests/bitmaps/Background.bmpbin60062 -> 0 bytes
-rw-r--r--tests/bitmaps/FontFile.binbin2608 -> 0 bytes
-rw-r--r--tests/bitmaps/NotReallyA.bmpbin1024 -> 0 bytes
-rwxr-xr-xtests/bitmaps/TestBmpBlock.py195
-rw-r--r--tests/bitmaps/Word.bmpbin7894 -> 0 bytes
-rw-r--r--tests/bitmaps/case_badbmp.yaml21
-rw-r--r--tests/bitmaps/case_nobmp.yaml19
-rw-r--r--tests/bitmaps/case_order1.yaml36
-rw-r--r--tests/bitmaps/case_order2.yaml36
-rw-r--r--tests/bitmaps/case_reuse.yaml28
-rw-r--r--tests/bitmaps/case_simple.yaml27
-rw-r--r--tests/futility/expect_output/show.tests_futility_data_bios_mario_mp.bin1
-rw-r--r--tests/futility/expect_output/show.tests_futility_data_bios_zgb_mp.bin1
-rw-r--r--tests/futility/expect_output/show.tests_futility_data_fw_gbb.bin5
-rwxr-xr-xtests/futility/test_gbb_utility.sh30
-rw-r--r--tests/vboot_display_tests.c1
-rw-r--r--utility/bmpblk_font.c229
-rw-r--r--utility/bmpblk_util.c455
-rw-r--r--utility/bmpblk_utility.cc777
-rw-r--r--utility/image_types.c71
-rw-r--r--utility/include/bmpblk_util.h13
-rw-r--r--utility/include/bmpblk_utility.h125
-rw-r--r--utility/include/image_types.h25
29 files changed, 3 insertions, 2353 deletions
diff --git a/Makefile b/Makefile
index a3b4a808..1b8e6cab 100644
--- a/Makefile
+++ b/Makefile
@@ -623,8 +623,6 @@ endif
ifeq (${MINIMAL},)
UTIL_NAMES += \
utility/bdb_extend \
- utility/bmpblk_font \
- utility/bmpblk_utility \
utility/eficompress \
utility/efidecompress \
utility/load_kernel_test \
@@ -1262,23 +1260,6 @@ ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
-${BUILD}/utility/bmpblk_utility: LD = ${CXX}
-${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
-
-BMPBLK_UTILITY_DEPS = \
- ${BUILD}/utility/bmpblk_util.o \
- ${BUILD}/utility/image_types.o \
- ${BUILD}/utility/eficompress_for_lib.o \
- ${BUILD}/utility/efidecompress_for_lib.o
-
-${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
-${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
-ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
-
-${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
-${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
-ALL_OBJS += ${BUILD}/utility/image_types.o
-
# Allow multiple definitions, so tests can mock functions from other libraries
${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
${BUILD}/tests/%: LDLIBS += -lrt -luuid
@@ -1335,7 +1316,7 @@ test_targets:: runcgpttests runmisctests run2tests runbdbtests
ifeq (${MINIMAL},)
# Bitmap utility isn't compiled for minimal variant
-test_targets:: runbmptests runfutiltests
+test_targets:: runfutiltests
# Scripts don't work under qemu testing
# TODO: convert scripts to makefile so they can be called directly
test_targets:: runtestscripts
@@ -1378,11 +1359,6 @@ gentestcases: utils test_setup
genfuzztestcases: utils test_setup
tests/gen_fuzz_test_cases.sh
-.PHONY: runbmptests
-runbmptests: test_setup
- cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
- ./TestBmpBlock.py -v
-
.PHONY: runcgpttests
runcgpttests: test_setup
${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
@@ -1417,7 +1393,6 @@ endif
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_detach_menu_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
- ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
.PHONY: run2tests
diff --git a/firmware/include/bmpblk_header.h b/firmware/include/bmpblk_header.h
deleted file mode 100644
index fec309d8..00000000
--- a/firmware/include/bmpblk_header.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/* Copyright (c) 2013 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.
- *
- * Data structure definitions for firmware screen block (BMPBLOCK).
- *
- * The BmpBlock structure looks like:
- * +-----------------------------------------+
- * | BmpBlock Header |
- * +-----------------------------------------+
- * | ScreenLayout[0] | \
- * +-----------------------------------------+ |
- * | ScreenLayout[1] | |
- * +-----------------------------------------+ Localization[0]
- * | ... | |
- * +-----------------------------------------+ |
- * | ScreenLayout[number_of_screenlayouts-1] | /
- * +-----------------------------------------+
- * | ScreenLayout[0] | \
- * +-----------------------------------------+ Localization[1]
- * | ... | /
- * +-----------------------------------------+ ...
- * | ScreenLayout[0] | \
- * +-----------------------------------------+ Localization[
- * | ... | / number_of_localizations-1]
- * +-----------------------------------------+
- * | ImageInfo[0] |
- * +-----------------------------------------+
- * | Image Content |
- * +-----------------------------------------+
- * | ImageInfo[2] | ImageInfo is 4-byte aligned.
- * +-----------------------------------------+
- * | Image Content |
- * +-----------------------------------------+
- * | ... |
- * +-----------------------------------------+
- * | ImageInfo[number_fo_images-1] |
- * +-----------------------------------------+
- * | Image Content |
- * +-----------------------------------------+
- * | List of locale names |
- * +-----------------------------------------+
- */
-#ifndef VBOOT_REFERENCE_BMPBLK_HEADER_H_
-#define VBOOT_REFERENCE_BMPBLK_HEADER_H_
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define BMPBLOCK_SIGNATURE "$BMP"
-#define BMPBLOCK_SIGNATURE_SIZE (4)
-
-#define BMPBLOCK_MAJOR_VERSION (0x0002)
-#define BMPBLOCK_MINOR_VERSION (0x0000)
-
-#define MAX_IMAGE_IN_LAYOUT (16)
-
-/* BMPBLOCK header, describing how many screen layouts and image infos */
-typedef struct BmpBlockHeader {
- /* BMPBLOCK_SIGNATURE $BMP */
- uint8_t signature[BMPBLOCK_SIGNATURE_SIZE];
- uint16_t major_version; /* see BMPBLOCK_MAJOR_VER */
- uint16_t minor_version; /* see BMPBLOCK_MINOR_VER */
- uint32_t number_of_localizations; /* Number of localizations */
- /* Number of screen layouts in each localization */
- uint32_t number_of_screenlayouts;
- uint32_t number_of_imageinfos; /* Number of image infos */
- /* Offset of locale-translation string */
- uint32_t locale_string_offset;
- uint32_t reserved[2];
-} __attribute__((packed)) BmpBlockHeader;
-
-/* Screen layout, describing how to stack multiple images on screen */
-typedef struct ScreenLayout {
- /*
- * Images contained in the screen. Will be rendered from 0 to
- * (number_of_images-1).
- */
- struct {
- /* (X,Y) offset of image to be rendered */
- uint32_t x;
- uint32_t y;
- /* Offset of image info from start of BMPBLOCK; 0=end it. */
- uint32_t image_info_offset;
- } images[MAX_IMAGE_IN_LAYOUT];
-} __attribute__((packed)) ScreenLayout;
-
-/* Constants for screen index */
-typedef enum ScreenIndex {
- SCREEN_DEVELOPER_WARNING = 0,
- SCREEN_RECOVERY_REMOVE,
- SCREEN_RECOVERY_NO_GOOD,
- SCREEN_RECOVERY_INSERT,
- SCREEN_RECOVERY_TO_DEV,
- SCREEN_DEVELOPER_TO_NORM,
- SCREEN_WAIT,
- SCREEN_TO_NORM_CONFIRMED,
- SCREEN_OS_BROKEN,
- MAX_VALID_SCREEN_INDEX,
- SCREEN_BLANK = ~0UL,
-} ScreenIndex;
-
-/* Image info, describing the information of the image block */
-typedef struct ImageInfo {
- uint32_t tag; /* Tag it as a special image, like HWID */
- uint32_t width; /* Width of the image */
- uint32_t height; /* Height of the image */
- uint32_t format; /* File format of the image */
- uint32_t compression; /* Compression method for the image file */
- uint32_t original_size; /* Size of the original uncompressed image */
- /*
- * Size of the compressed image; if image is not compressed, this will
- * be the same as the original size.
- */
- uint32_t compressed_size;
- uint32_t reserved;
- /* NOTE: The actual image content (if any) follows immediately. */
-} __attribute__((packed)) ImageInfo;
-
-/* Constants for ImageInfo.tag */
-typedef enum ImageTag {
- TAG_NONE = 0,
- TAG_HWID,
- TAG_HWID_RTOL, /* "right-to-left", ie, right-justified HWID */
-} ImageTag;
-
-/* Constants for ImageInfo.format */
-typedef enum ImageFormat {
- FORMAT_INVALID = 0,
- FORMAT_BMP,
- FORMAT_FONT,
-} ImageFormat;
-
-/*
- * These magic image names can be used in the .yaml file to indicate that the
- * ASCII HWID should be displayed. For RENDER_HWID, the image coordinates
- * specify upper-left corner of the HWID string. For RENDER_HWID_RTOL, they
- * indicate the upper-right corner (handy for right-to-left languages).
- */
-#define RENDER_HWID "$HWID"
-#define RENDER_HWID_RTOL "$HWID.rtol"
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* VBOOT_REFERENCE_BMPBLK_HEADER_H_ */
diff --git a/firmware/lib/include/bmpblk_font.h b/firmware/lib/include/bmpblk_font.h
deleted file mode 100644
index 24f908ea..00000000
--- a/firmware/lib/include/bmpblk_font.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright (c) 2013 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.
- *
- * This describes the internal format used to pack a set of character glpyhs so
- * we can render strings by drawing one character at a time.
- *
- * The format is this:
- *
- * +-------------------------+
- * | FontArrayHeader |
- * +-------------------------+
- * | FontArrayEntryHeader[0] |
- * +-------------------------+
- * | raw image data[0] |
- * +-------------------------+
- * | FontArrayEntryHeader[1] |
- * +-------------------------+
- * | raw image data[1] |
- * +-------------------------+
- * | FontArrayEntryHeader[2] |
- * +-------------------------+
- * | raw image data[2] |
- * +-------------------------+
- * ...
- * +-------------------------+
- * | FontArrayEntryHeader[n] |
- * +-------------------------+
- * | raw image data[n] |
- * +-------------------------+
- *
- * The FontArrayHeader describes how many characters will be encoded.
- * Each character encoding consists of a FontArrayEntryHeader followed
- * immediately by the raw image data for that character.
- */
-
-#ifndef VBOOT_REFERENCE_BMPBLK_FONT_H_
-#define VBOOT_REFERENCE_BMPBLK_FONT_H_
-
-#include "bmpblk_header.h"
-
-#define FONT_SIGNATURE "FONT"
-#define FONT_SIGNATURE_SIZE 4
-
-typedef struct FontArrayHeader {
- uint8_t signature[FONT_SIGNATURE_SIZE];
- uint32_t num_entries; /* Number of chars encoded here. */
-} __attribute__((packed)) FontArrayHeader;
-
-typedef struct FontArrayEntryHeader {
- uint32_t ascii; /* What to show. Could even be UTF? */
- ImageInfo info; /* Describes the bitmap. */
-
- /*
- * The image to use follows immediately, NOT compressed. It's
- * uncompressed because each glyph is only a few hundred bytes, but
- * they have much in common (colormaps, for example). When we add the
- * whole font blob to the bmpblk, it will be compressed as a single
- * item there.
- */
-} __attribute__((packed)) FontArrayEntryHeader;
-
-#endif /* VBOOT_REFERENCE_BMPBLK_FONT_H_ */
diff --git a/firmware/lib/include/vboot_display.h b/firmware/lib/include/vboot_display.h
index 99e49f1a..ed259a0c 100644
--- a/firmware/lib/include/vboot_display.h
+++ b/firmware/lib/include/vboot_display.h
@@ -8,8 +8,6 @@
#ifndef VBOOT_REFERENCE_VBOOT_DISPLAY_H_
#define VBOOT_REFERENCE_VBOOT_DISPLAY_H_
-struct vb2_context;
-
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force,
const VbScreenData *data);
VbError_t VbDisplayMenu(struct vb2_context *ctx,
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index c4b4f87a..c43becec 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -12,7 +12,6 @@
#include "2misc.h"
#include "2nvstorage.h"
#include "2sha.h"
-#include "bmpblk_font.h"
#include "gbb_access.h"
#include "gbb_header.h"
#include "utility.h"
diff --git a/futility/file_type_bios.c b/futility/file_type_bios.c
index d9d132a5..d79e76f8 100644
--- a/futility/file_type_bios.c
+++ b/futility/file_type_bios.c
@@ -9,7 +9,6 @@
#include <stdio.h>
#include <string.h>
-#include "bmpblk_header.h"
#include "fmap.h"
#include "file_type.h"
#include "file_type_bios.h"
@@ -55,7 +54,6 @@ int ft_show_gbb(const char *name, uint8_t *buf, uint32_t len, void *data)
{
GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader *)buf;
struct bios_state_s *state = (struct bios_state_s *)data;
- BmpBlockHeader *bmp;
int retval = 0;
uint32_t maxlen = 0;
@@ -130,23 +128,6 @@ int ft_show_gbb(const char *name, uint8_t *buf, uint32_t len, void *data)
printf(" Recovery Key: <invalid>\n");
}
- bmp = (BmpBlockHeader *)(buf + gbb->bmpfv_offset);
- if (0 != memcmp(bmp, BMPBLOCK_SIGNATURE, BMPBLOCK_SIGNATURE_SIZE)) {
- printf(" BmpBlock: <invalid>\n");
- /* We don't support older BmpBlock formats, so we can't
- * be strict about this. */
- } else {
- printf(" BmpBlock:\n");
- printf(" Version: %d.%d\n",
- bmp->major_version, bmp->minor_version);
- printf(" Localizations: %d\n",
- bmp->number_of_localizations);
- printf(" Screen layouts: %d\n",
- bmp->number_of_screenlayouts);
- printf(" Image infos: %d\n",
- bmp->number_of_imageinfos);
- }
-
if (!retval && state)
state->area[BIOS_FMAP_GBB].is_valid = 1;
diff --git a/tests/bitmaps/Background.bmp b/tests/bitmaps/Background.bmp
deleted file mode 100644
index a83c995c..00000000
--- a/tests/bitmaps/Background.bmp
+++ /dev/null
Binary files differ
diff --git a/tests/bitmaps/FontFile.bin b/tests/bitmaps/FontFile.bin
deleted file mode 100644
index 5ca0ea8a..00000000
--- a/tests/bitmaps/FontFile.bin
+++ /dev/null
Binary files differ
diff --git a/tests/bitmaps/NotReallyA.bmp b/tests/bitmaps/NotReallyA.bmp
deleted file mode 100644
index a51e27e3..00000000
--- a/tests/bitmaps/NotReallyA.bmp
+++ /dev/null
Binary files differ
diff --git a/tests/bitmaps/TestBmpBlock.py b/tests/bitmaps/TestBmpBlock.py
deleted file mode 100755
index 01f85540..00000000
--- a/tests/bitmaps/TestBmpBlock.py
+++ /dev/null
@@ -1,195 +0,0 @@
-#!/usr/bin/python2 -tt
-#
-# 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.
-
-"""Unit tests for bmpblk_utility.
-"""
-
-import os
-import sys
-import subprocess
-import tempfile
-import unittest
-
-def runprog(*args):
- """Runs specified program and args, returns (exitcode, stdout, stderr)."""
- p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- return (p.returncode, out, err)
-
-
-class TempDirTestCase(unittest.TestCase):
- """A TestCase that sets up self.tempdir with a temporary directory."""
-
- def setUp(self):
- self.tempdir = tempfile.mkdtemp(prefix='tmp_test_bmp_block')
- self.tempfile = os.path.join(self.tempdir, 'FOO')
- self._cwd = os.getcwd()
-
- def tearDown(self):
- os.chdir(self._cwd)
- runprog('rm', '-rf', self.tempdir)
-
-
-class TestFailures(TempDirTestCase):
-
- def testNoArgs(self):
- """Running with no args should print usage and fail."""
- rc, out, err = runprog(prog)
- self.assertNotEqual(0, rc)
- self.assertTrue(err.count("missing BMPBLOCK name"))
- self.assertTrue(out.count("bmpblk_utility"))
-
- def testMissingBmp(self):
- """Missing a bmp specified in the yaml is an error."""
- rc, out, err = runprog(prog, '-c', 'case_nobmp.yaml', self.tempfile)
- self.assertNotEqual(0, rc)
- self.assertTrue(err.count("No such file or directory"))
-
- def testInvalidBmp(self):
- """A .bmp file that isn't really a BMP should fail."""
- rc, out, err = runprog(prog, '-c', 'case_badbmp.yaml', self.tempfile)
- self.assertNotEqual(0, rc)
- self.assertTrue(err.count("Unsupported image format"))
-
- def testBadCompression(self):
- """Wrong compression types should fail."""
- rc, out, err = runprog(prog, '-z', '99', '-c', 'case_simple.yaml', self.tempfile)
- self.assertNotEqual(0, rc)
- self.assertTrue(err.count("compression type"))
-
-
-class TestOverWrite(TempDirTestCase):
-
- def testOverwrite(self):
- """Create, unpack, unpack again, with and without -f"""
- rc, out, err = runprog(prog, '-c', 'case_simple.yaml', self.tempfile)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, self.tempfile)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, self.tempfile)
- self.assertNotEqual(0, rc)
- self.assertTrue(err.count("File exists"))
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, '-f', self.tempfile)
- self.assertEqual(0, rc)
-
-
-class TestPackUnpack(TempDirTestCase):
-
- def testPackUnpack(self):
- """Create, unpack, recreate without compression"""
- foo = os.path.join(self.tempdir, 'FOO')
- bar = os.path.join(self.tempdir, 'BAR')
- rc, out, err = runprog(prog, '-c', 'case_simple.yaml', foo)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, foo)
- self.assertEqual(0, rc)
- os.chdir(self.tempdir)
- rc, out, err = runprog(prog, '-c', 'config.yaml', bar)
- self.assertEqual(0, rc)
- rc, out, err = runprog('/usr/bin/cmp', foo, bar)
- self.assertEqual(0, rc)
-
- def doPackUnpackZ(self, comp):
- """Create, unpack, recreate with a given compression"""
- foo = os.path.join(self.tempdir, 'FOO')
- bar = os.path.join(self.tempdir, 'BAR')
- rc, out, err = runprog(prog, '-z', comp, '-c', 'case_simple.yaml', foo)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, foo)
- self.assertEqual(0, rc)
- os.chdir(self.tempdir)
- rc, out, err = runprog(prog, '-z', comp, '-c', 'config.yaml', bar)
- self.assertEqual(0, rc)
- rc, out, err = runprog('/usr/bin/cmp', foo, bar)
- self.assertEqual(0, rc)
-
- def testPackUnpackZ1(self):
- """Create, unpack, recreate with EFIv1 compression"""
- self.doPackUnpackZ('1')
-
- def testPackUnpackZ2(self):
- """Create, unpack, recreate with LZMA compression"""
- self.doPackUnpackZ('2')
-
- def doPackUnpackImplicitZ(self, comp, noncomp):
- """Create with given compression, unpack, repack without specifying"""
- foo = os.path.join(self.tempdir, 'FOO')
- bar = os.path.join(self.tempdir, 'BAR')
- # create with the specified compression scheme
- rc, out, err = runprog(prog, '-z', comp, '-c', 'case_simple.yaml', foo)
- self.assertEqual(0, rc)
- # unpack. yaml file should have compression scheme in it
- rc, out, err = runprog(prog, '-f', '-x', '-d', self.tempdir, foo)
- self.assertEqual(0, rc)
- os.chdir(self.tempdir)
- # create with no compression specified, should use default from yaml
- rc, out, err = runprog(prog, '-c', 'config.yaml', bar)
- self.assertEqual(0, rc)
- # so new output should match original
- rc, out, err = runprog('/usr/bin/cmp', foo, bar)
- self.assertEqual(0, rc)
- # Now make sure that specifying a compression arg will override the default
- for mycomp in noncomp:
- # create with compression scheme different from default
- rc, out, err = runprog(prog, '-z', str(mycomp), '-c', 'config.yaml', bar)
- self.assertEqual(0, rc)
- # should be different binary
- rc, out, err = runprog('/usr/bin/cmp', foo, bar)
- self.assertNotEqual(0, rc)
-
- def testPackUnpackImplicitZ(self):
- """Create, unpack, recreate with implicit compression"""
- self._allowed = range(3)
- for c in self._allowed:
- os.chdir(self._cwd)
- self.doPackUnpackImplicitZ(str(c), [x for x in self._allowed if x != c])
-
-
-class TestReproducable(TempDirTestCase):
-
- def disabledTestReproduce(self):
- """Equivalent yaml files should produce identical bmpblocks"""
- # TODO: This test is currently broken because bmpblock_utility
- # uses a map to hold the images, and the map doesn't preserve image
- # order. So a simple compare is insufficient to determine that
- # the bmpblocks are equivalent. See crosbug.com/19541.
- order1 = os.path.join(self.tempdir, 'ORDER1')
- order2 = os.path.join(self.tempdir, 'ORDER2')
- rc, out, err = runprog(prog, '-c', 'case_order1.yaml', order1)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-c', 'case_order2.yaml', order2)
- self.assertEqual(0, rc)
- rc, out, err = runprog('/usr/bin/cmp', order1, order2)
- self.assertEqual(0, rc)
-
-
-class TestReuse(TempDirTestCase):
-
- def testReuse(self):
- """Reusing screens in the yaml file should be okay"""
- foo = os.path.join(self.tempdir, 'FOO')
- bar = os.path.join(self.tempdir, 'BAR')
- rc, out, err = runprog(prog, '-c', 'case_reuse.yaml', foo)
- self.assertEqual(0, rc)
- rc, out, err = runprog(prog, '-x', '-d', self.tempdir, foo)
- self.assertEqual(0, rc)
- os.chdir(self.tempdir)
- rc, out, err = runprog(prog, '-c', 'config.yaml', bar)
- self.assertEqual(0, rc)
- rc, out, err = runprog('/usr/bin/cmp', foo, bar)
- self.assertEqual(0, rc)
-
-
-# Run these tests
-if __name__ == '__main__':
- varname = 'BMPBLK'
- if varname not in os.environ:
- print('You must specify the path to bmpblk_utility in the $%s '
- 'environment variable.' % varname)
- sys.exit(1)
- prog = os.environ[varname]
- print "Testing prog...", prog
- unittest.main()
diff --git a/tests/bitmaps/Word.bmp b/tests/bitmaps/Word.bmp
deleted file mode 100644
index ba4a0e0c..00000000
--- a/tests/bitmaps/Word.bmp
+++ /dev/null
Binary files differ
diff --git a/tests/bitmaps/case_badbmp.yaml b/tests/bitmaps/case_badbmp.yaml
deleted file mode 100644
index 8772e2e7..00000000
--- a/tests/bitmaps/case_badbmp.yaml
+++ /dev/null
@@ -1,21 +0,0 @@
-# Invalid specification: requests missing image file.
-
-bmpblock: 2.0
-
-# These are the individual images which are layered to produce a screen layout.
-images:
- devmode: NotReallyA.bmp
- $HWID: FontFile.bin
-
-# These are all of the distinct layouts that we know how to display.
-screens:
- dev_en:
- - [0, 0, devmode]
- - [100, 100, $HWID]
-
-
-# To customize the images for a particular locale, just reorder this list so
-# that the default language appears first.
-localizations:
- - [ dev_en, dev_en, dev_en, dev_en ]
-
diff --git a/tests/bitmaps/case_nobmp.yaml b/tests/bitmaps/case_nobmp.yaml
deleted file mode 100644
index 02b44a35..00000000
--- a/tests/bitmaps/case_nobmp.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-# Invalid specification: requests missing image file.
-
-bmpblock: 2.0
-
-# These are the individual images which are layered to produce a screen layout.
-images:
- devmode: NoSuchFile.bmp
-
-# These are all of the distinct layouts that we know how to display.
-screens:
- dev_en:
- - [0, 0, devmode]
-
-
-# To customize the images for a particular locale, just reorder this list so
-# that the default language appears first.
-localizations:
- - [ dev_en, dev_en, dev_en, dev_en ]
-
diff --git a/tests/bitmaps/case_order1.yaml b/tests/bitmaps/case_order1.yaml
deleted file mode 100644
index c116ee45..00000000
--- a/tests/bitmaps/case_order1.yaml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-bmpblock: 2.0
-
-images:
- image0: Background.bmp
- image1: Word.bmp
-
-screens:
- scr_a0:
- - [0, 0, image0]
-
- scr_b0:
- - [0, 0, image0]
-
- scr_c0:
- - [0, 0, image0]
-
- scr_d0:
- - [0, 0, image0]
-
- scr_a1:
- - [45, 45, image1 ]
-
- scr_b1:
- - [45, 400, image1 ]
-
- scr_c1:
- - [400, 400, image1 ]
-
- scr_d1:
- - [400, 45, image1 ]
-
-localizations:
- - [ scr_a0, scr_b0, scr_c0, scr_d0 ]
- - [ scr_a1, scr_b1, scr_c1, scr_d1 ]
-
diff --git a/tests/bitmaps/case_order2.yaml b/tests/bitmaps/case_order2.yaml
deleted file mode 100644
index cd9018f5..00000000
--- a/tests/bitmaps/case_order2.yaml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-bmpblock: 2.0
-
-images:
- zmage0: Background.bmp
- image1: Word.bmp
-
-screens:
- scr_a4:
- - [0, 0, zmage0]
-
- scr_b4:
- - [0, 0, zmage0]
-
- scr_c4:
- - [0, 0, zmage0]
-
- scr_d4:
- - [0, 0, zmage0]
-
- scr_a1:
- - [45, 45, image1 ]
-
- scr_b1:
- - [45, 400, image1 ]
-
- scr_c1:
- - [400, 400, image1 ]
-
- scr_d1:
- - [400, 45, image1 ]
-
-localizations:
- - [ scr_a4, scr_b4, scr_c4, scr_d4 ]
- - [ scr_a1, scr_b1, scr_c1, scr_d1 ]
-
diff --git a/tests/bitmaps/case_reuse.yaml b/tests/bitmaps/case_reuse.yaml
deleted file mode 100644
index 1265d3c0..00000000
--- a/tests/bitmaps/case_reuse.yaml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-bmpblock: 2.0
-
-images:
- image0: Background.bmp
- image1: Word.bmp
-
-screens:
- scr_a0:
- - [0, 0, image0]
-
- scr_b0:
- - [0, 0, image0]
-
- scr_c0:
- - [0, 0, image0]
-
- scr_d0:
- - [0, 0, image0]
-
- scr_z:
- - [45, 45, image1 ]
-
-localizations:
- - [ scr_a0, scr_b0, scr_c0, scr_d0 ]
- - [ scr_a0, scr_b0, scr_c0, scr_z ]
-
-
diff --git a/tests/bitmaps/case_simple.yaml b/tests/bitmaps/case_simple.yaml
deleted file mode 100644
index c30a0645..00000000
--- a/tests/bitmaps/case_simple.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-bmpblock: 2.0
-
-images:
- background: Background.bmp
- text: Word.bmp
-
-screens:
- scr_1:
- - [0, 0, background]
- - [45, 45, text ]
-
- scr_2:
- - [0, 0, background]
- - [45, 400, text ]
-
- scr_3:
- - [0, 0, background]
- - [400, 400, text ]
-
- scr_4:
- - [0, 0, background]
- - [400, 45, text ]
-
-
-localizations:
- - [ scr_1, scr_2, scr_3, scr_4 ]
diff --git a/tests/futility/expect_output/show.tests_futility_data_bios_mario_mp.bin b/tests/futility/expect_output/show.tests_futility_data_bios_mario_mp.bin
index 882b9782..36c9ab8b 100644
--- a/tests/futility/expect_output/show.tests_futility_data_bios_mario_mp.bin
+++ b/tests/futility/expect_output/show.tests_futility_data_bios_mario_mp.bin
@@ -21,7 +21,6 @@ GBB content:
Algorithm: 11 RSA8192 SHA512
Key Version: 1
Key sha1sum: 5d0d163b824cab5ae4f23fb2cc012e2a4124f4fe
- BmpBlock: <invalid>
Firmware body: Firmware A Data
Offset: 0x00040000
Size: 0x000d0000
diff --git a/tests/futility/expect_output/show.tests_futility_data_bios_zgb_mp.bin b/tests/futility/expect_output/show.tests_futility_data_bios_zgb_mp.bin
index 6a29c909..5dfa5874 100644
--- a/tests/futility/expect_output/show.tests_futility_data_bios_zgb_mp.bin
+++ b/tests/futility/expect_output/show.tests_futility_data_bios_zgb_mp.bin
@@ -21,7 +21,6 @@ GBB content:
Algorithm: 11 RSA8192 SHA512
Key Version: 1
Key sha1sum: 9bd99a594c45b6739899a17ec29ac2289ee75463
- BmpBlock: <invalid>
Firmware body: FW_MAIN_A
Offset: 0x00030000
Size: 0x000dffc0
diff --git a/tests/futility/expect_output/show.tests_futility_data_fw_gbb.bin b/tests/futility/expect_output/show.tests_futility_data_fw_gbb.bin
index ea202bfd..3f81d86e 100644
--- a/tests/futility/expect_output/show.tests_futility_data_fw_gbb.bin
+++ b/tests/futility/expect_output/show.tests_futility_data_fw_gbb.bin
@@ -20,8 +20,3 @@ GBB content:
Algorithm: 11 RSA8192 SHA512
Key Version: 1
Key sha1sum: bf39d0d3e30cbf6a121416d04df4603ad5310779
- BmpBlock:
- Version: 2.0
- Localizations: 18
- Screen layouts: 10
- Image infos: 269
diff --git a/tests/futility/test_gbb_utility.sh b/tests/futility/test_gbb_utility.sh
index 58855711..bdfa2628 100755
--- a/tests/futility/test_gbb_utility.sh
+++ b/tests/futility/test_gbb_utility.sh
@@ -35,28 +35,22 @@ ${FUTILITY} gbb -g ${TMP}.blob | grep "0123456789ABCDE"
# too long
dd if=/dev/urandom bs=17 count=1 of=${TMP}.data1.toolong
dd if=/dev/urandom bs=17 count=1 of=${TMP}.data2.toolong
-dd if=/dev/urandom bs=17 count=1 of=${TMP}.data3.toolong
if ${FUTILITY} gbb -s --rootkey ${TMP}.data1.toolong ${TMP}.blob; then false; fi
if ${FUTILITY} gbb -s --recoverykey ${TMP}.data2.toolong ${TMP}.blob; then false; fi
-if ${FUTILITY} gbb -s --bmpfv ${TMP}.data3.toolong ${TMP}.blob; then false; fi
# shorter than max should be okay, though
dd if=/dev/urandom bs=10 count=1 of=${TMP}.data1.short
dd if=/dev/urandom bs=10 count=1 of=${TMP}.data2.short
-dd if=/dev/urandom bs=10 count=1 of=${TMP}.data3.short
${FUTILITY} gbb -s \
--rootkey ${TMP}.data1.short \
- --recoverykey ${TMP}.data2.short \
- --bmpfv ${TMP}.data3.short ${TMP}.blob
+ --recoverykey ${TMP}.data2.short ${TMP}.blob
# read 'em back
${FUTILITY} gbb -g \
--rootkey ${TMP}.read1 \
- --recoverykey ${TMP}.read2 \
- --bmpfv ${TMP}.read3 ${TMP}.blob
+ --recoverykey ${TMP}.read2 ${TMP}.blob
# Verify (but remember, it's short)
cmp -n 10 ${TMP}.data1.short ${TMP}.read1
cmp -n 10 ${TMP}.data2.short ${TMP}.read2
-cmp -n 10 ${TMP}.data3.short ${TMP}.read3
# Okay
dd if=/dev/urandom bs=16 count=1 of=${TMP}.data1
@@ -64,16 +58,13 @@ dd if=/dev/urandom bs=16 count=1 of=${TMP}.data2
dd if=/dev/urandom bs=16 count=1 of=${TMP}.data3
${FUTILITY} gbb -s --rootkey ${TMP}.data1 ${TMP}.blob
${FUTILITY} gbb -s --recoverykey ${TMP}.data2 ${TMP}.blob
-${FUTILITY} gbb -s --bmpfv ${TMP}.data3 ${TMP}.blob
# Read 'em back.
${FUTILITY} gbb -g --rootkey ${TMP}.read1 ${TMP}.blob
${FUTILITY} gbb -g --recoverykey ${TMP}.read2 ${TMP}.blob
-${FUTILITY} gbb -g --bmpfv ${TMP}.read3 ${TMP}.blob
# Verify
cmp ${TMP}.data1 ${TMP}.read1
cmp ${TMP}.data2 ${TMP}.read2
-cmp ${TMP}.data3 ${TMP}.read3
# Okay, creating GBB blobs seems to work. Now let's make sure that corrupted
@@ -147,12 +138,6 @@ if ${FUTILITY} gbb ${TMP}.blob.bad; then false; fi
cat ${TMP}.blob | ${REPLACE} 0x18 0x00 > ${TMP}.blob.bad
if ${FUTILITY} gbb ${TMP}.blob.bad; then false; fi
-# bmpfv_offset < GBB_HEADER_SIZE is invalid
-cat ${TMP}.blob | ${REPLACE} 0x20 0x7f > ${TMP}.blob.bad
-if ${FUTILITY} gbb ${TMP}.blob.bad; then false; fi
-cat ${TMP}.blob | ${REPLACE} 0x20 0x00 > ${TMP}.blob.bad
-if ${FUTILITY} gbb ${TMP}.blob.bad; then false; fi
-
# recovery_key_offset < GBB_HEADER_SIZE is invalid
cat ${TMP}.blob | ${REPLACE} 0x28 0x7f > ${TMP}.blob.bad
if ${FUTILITY} gbb ${TMP}.blob.bad; then false; fi
@@ -171,12 +156,6 @@ ${FUTILITY} gbb -g ${TMP}.blob.bad
cat ${TMP}.blob | ${REPLACE} 0x1c 0x31 > ${TMP}.blob.bad
if ${FUTILITY} gbb -g ${TMP}.blob.bad; then false; fi
-# bmpfv: offset + size == end of file is okay; beyond is invalid
-cat ${TMP}.blob | ${REPLACE} 0x24 0x20 > ${TMP}.blob.bad
-${FUTILITY} gbb -g ${TMP}.blob.bad
-cat ${TMP}.blob | ${REPLACE} 0x24 0x21 > ${TMP}.blob.bad
-if ${FUTILITY} gbb -g ${TMP}.blob.bad; then false; fi
-
# recovery_key: offset + size == end of file is okay; beyond is invalid
cat ${TMP}.blob | ${REPLACE} 0x2c 0x10 > ${TMP}.blob.bad
${FUTILITY} gbb -g ${TMP}.blob.bad
@@ -193,11 +172,6 @@ cat ${TMP}.blob | ${REPLACE} 0x1c 0x00 > ${TMP}.blob.bad
${FUTILITY} gbb -g --rootkey ${TMP}.read1 ${TMP}.blob.bad
if ${FUTILITY} gbb -s --rootkey ${TMP}.data1 ${TMP}.blob.bad; then false; fi
-# bmpfv_size == 0 gives warning, gets nothing, can't be set
-cat ${TMP}.blob | ${REPLACE} 0x24 0x00 > ${TMP}.blob.bad
-${FUTILITY} gbb -g --bmpfv ${TMP}.read3 ${TMP}.blob.bad
-if ${FUTILITY} gbb -s --bmpfv ${TMP}.data3 ${TMP}.blob.bad; then false; fi
-
# recovery_key_size == 0 gives warning, gets nothing, can't be set
cat ${TMP}.blob | ${REPLACE} 0x2c 0x00 > ${TMP}.blob.bad
${FUTILITY} gbb -g --recoverykey ${TMP}.read2 ${TMP}.blob.bad
diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c
index f010ddd6..986bb270 100644
--- a/tests/vboot_display_tests.c
+++ b/tests/vboot_display_tests.c
@@ -14,7 +14,6 @@
#include "2common.h"
#include "2misc.h"
#include "2nvstorage.h"
-#include "bmpblk_font.h"
#include "gbb_access.h"
#include "gbb_header.h"
#include "host_common.h"
diff --git a/utility/bmpblk_font.c b/utility/bmpblk_font.c
deleted file mode 100644
index 75c33859..00000000
--- a/utility/bmpblk_font.c
+++ /dev/null
@@ -1,229 +0,0 @@
-// 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.
-
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "bmpblk_font.h"
-#include "image_types.h"
-#include "vboot_api.h"
-
-static char *progname;
-
-static void error(const char *fmt, ...)
-{
- va_list args;
- va_start( args, fmt );
- fprintf(stderr, "%s: ", progname);
- vfprintf( stderr, fmt, args );
- va_end( args );
-}
-#define fatal(args...) do { error(args); exit(1); } while(0)
-
-
-/* Command line options */
-enum {
- OPT_OUTFILE = 1000,
-};
-
-#define DEFAULT_OUTFILE "font.bin"
-
-
-static struct option long_opts[] = {
- {"outfile", 1, 0, OPT_OUTFILE },
- {NULL, 0, 0, 0}
-};
-
-
-/* Print help and return error */
-static void HelpAndDie(void) {
- fprintf(stderr,
- "\n"
- "%s - Create a vboot fontfile from a set of BMP files.\n"
- "\n"
- "Usage: %s [OPTIONS] BMPFILE [BMPFILE...]\n"
- "\n"
- "Each BMP file must match *_HEX.bmp, where HEX is the hexadecimal\n"
- "representation of the character that the file displays. The images\n"
- "will be encoded in the given order. Typically the first image is\n"
- "reused to represent any missing characters.\n"
- "\n"
- "OPTIONS are:\n"
- " --outfile <filename> Output file (default is %s)\n"
- "\n", progname, progname, DEFAULT_OUTFILE);
- exit(1);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-// Returns pointer to buffer containing entire file, sets length.
-static void *read_entire_file(const char *filename, size_t *length) {
- int fd;
- struct stat sbuf;
- void *ptr;
-
- *length = 0; // just in case
-
- if (0 != stat(filename, &sbuf)) {
- error("Unable to stat %s: %s\n", filename, strerror(errno));
- return 0;
- }
-
- if (!sbuf.st_size) {
- error("File %s is empty\n", filename);
- return 0;
- }
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- error("Unable to open %s: %s\n", filename, strerror(errno));
- return 0;
- }
-
- ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (MAP_FAILED == ptr) {
- error("Unable to mmap %s: %s\n", filename, strerror(errno));
- close(fd);
- return 0;
- }
-
- *length = sbuf.st_size;
-
- close(fd);
-
- return ptr;
-}
-
-
-// Reclaims buffer from read_entire_file().
-static void discard_file(void *ptr, size_t length) {
- munmap(ptr, length);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-
-
-int main(int argc, char* argv[]) {
- char* outfile = DEFAULT_OUTFILE;
- int numimages = 0;
- int parse_error = 0;
- int i;
- FILE *ofp;
- FontArrayHeader header;
- FontArrayEntryHeader entry;
-
- progname = strrchr(argv[0], '/');
- if (progname)
- progname++;
- else
- progname = argv[0];
-
- while ((i = getopt_long(argc, argv, "", long_opts, NULL)) != -1) {
- switch (i) {
- case OPT_OUTFILE:
- outfile = optarg;
- break;
-
- default:
- /* Unhandled option */
- printf("Unknown option\n");
- parse_error = 1;
- break;
- }
- }
-
- numimages = argc - optind;
-
- if (parse_error || numimages < 1)
- HelpAndDie();
-
- printf("outfile is %s\n", outfile);
- printf("numimages is %d\n", numimages);
-
- ofp = fopen(outfile, "wb");
- if (!ofp)
- fatal("Unable to open %s: %s\n", outfile, strerror(errno));
-
- memcpy(&header.signature, FONT_SIGNATURE, FONT_SIGNATURE_SIZE);
- header.num_entries = numimages;
- if (1 != fwrite(&header, sizeof(header), 1, ofp)) {
- error("Can't write header to %s: %s\n", outfile, strerror(errno));
- goto bad1;
- }
-
- for(i=0; i<numimages; i++) {
- char *imgfile = argv[optind+i];
- char *s;
- uint32_t ascii;
- void *imgdata = 0;
- size_t imgsize, filesize, diff;
-
- s = strrchr(imgfile, '_');
- if (!s || 1 != sscanf(s, "_%x.bmp", &ascii)) { // This is not foolproof.
- error("Unable to parse the character from filename %s\n", imgfile);
- goto bad1;
- }
-
- imgdata = read_entire_file(imgfile, &imgsize);
- if (!imgdata)
- goto bad1;
-
- if (FORMAT_BMP != identify_image_type(imgdata, imgsize, &entry.info)) {
- error("%s does not contain a valid BMP image\n", imgfile);
- goto bad1;
- }
-
- // Pad the image to align it on a 4-byte boundary.
- filesize = imgsize;
- if (imgsize % 4)
- filesize = ((imgsize + 4) / 4) * 4;
- diff = filesize - imgsize;
-
- entry.ascii = ascii;
- entry.info.tag = TAG_NONE;
- entry.info.compression = COMPRESS_NONE; // we'll compress it all later
- entry.info.original_size = filesize;
- entry.info.compressed_size = filesize;
-
- printf("%s => 0x%x %dx%d\n", imgfile, entry.ascii,
- entry.info.width, entry.info.height);
-
- if (1 != fwrite(&entry, sizeof(entry), 1, ofp)) {
- error("Can't write entry to %s: %s\n", outfile, strerror(errno));
- goto bad1;
- }
- if (1 != fwrite(imgdata, imgsize, 1, ofp)) {
- error("Can't write image to %s: %s\n", outfile, strerror(errno));
- goto bad1;
- }
- if (diff && 1 != fwrite("\0\0\0\0\0\0\0\0", diff, 1, ofp)) {
- error("Can't write padding to %s: %s\n", outfile, strerror(errno));
- goto bad1;
- }
-
-
- discard_file(imgdata, imgsize);
- }
-
- fclose(ofp);
- return 0;
-
-bad1:
- fclose(ofp);
- error("Aborting\n");
- (void) unlink(outfile);
- exit(1);
-}
diff --git a/utility/bmpblk_util.c b/utility/bmpblk_util.c
deleted file mode 100644
index abcac0d3..00000000
--- a/utility/bmpblk_util.c
+++ /dev/null
@@ -1,455 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <lzma.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "bmpblk_util.h"
-#include "eficompress.h"
-#include "vboot_api.h"
-
-// Returns pointer to buffer containing entire file, sets length.
-static void *read_entire_file(const char *filename, size_t *length) {
- int fd;
- struct stat sbuf;
- void *ptr;
-
- *length = 0; // just in case
-
- if (0 != stat(filename, &sbuf)) {
- fprintf(stderr, "Unable to stat %s: %s\n", filename, strerror(errno));
- return 0;
- }
-
- if (!sbuf.st_size) {
- fprintf(stderr, "File %s is empty\n", filename);
- return 0;
- }
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Unable to open %s: %s\n", filename, strerror(errno));
- return 0;
- }
-
- ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (MAP_FAILED == ptr) {
- fprintf(stderr, "Unable to mmap %s: %s\n", filename, strerror(errno));
- close(fd);
- return 0;
- }
-
- *length = sbuf.st_size;
-
- close(fd);
-
- return ptr;
-}
-
-
-// Reclaims buffer from read_entire_file().
-static void discard_file(void *ptr, size_t length) {
- munmap(ptr, length);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-static int require_dir(const char *dirname) {
- struct stat sbuf;
-
- if (0 == stat(dirname, &sbuf)) {
- // Something's there. Is it a directory?
- if (S_ISDIR(sbuf.st_mode)) {
- return 0;
- }
- fprintf(stderr, "%s already exists and is not a directory\n", dirname);
- return 1;
- }
-
- // dirname doesn't exist. Try to create it.
- if (ENOENT == errno) {
- if (0 != mkdir(dirname, 0777)) {
- fprintf(stderr, "Unable to create directory %s: %s\n",
- dirname, strerror(errno));
- return 1;
- }
- return 0;
- }
-
- fprintf(stderr, "Unable to stat %s: %s\n", dirname, strerror(errno));
- return 1;
-}
-
-
-
-static void *do_efi_decompress(ImageInfo *img) {
- void *ibuf;
- void *sbuf;
- void *obuf;
- uint32_t isize;
- uint32_t ssize;
- uint32_t osize;
- EFI_STATUS r;
-
- ibuf = (void*)(img + 1);
- isize = img->compressed_size;
-
- r = EfiGetInfo(ibuf, isize, &osize, &ssize);
- if (EFI_SUCCESS != r) {
- fprintf(stderr, "EfiGetInfo() failed with code %d\n",
- r);
- return 0;
- }
-
- sbuf = malloc(ssize);
- if (!sbuf) {
- fprintf(stderr, "Can't allocate %d bytes: %s\n",
- ssize,
- strerror(errno));
- return 0;
- }
-
- obuf = malloc(osize);
- if (!obuf) {
- fprintf(stderr, "Can't allocate %d bytes: %s\n",
- osize,
- strerror(errno));
- free(sbuf);
- return 0;
- }
-
- r = EfiDecompress(ibuf, isize, obuf, osize, sbuf, ssize);
- if (r != EFI_SUCCESS) {
- fprintf(stderr, "EfiDecompress failed with code %d\n", r);
- free(obuf);
- free(sbuf);
- return 0;
- }
-
- free(sbuf);
- return obuf;
-}
-
-
-
-static void *do_lzma_decompress(ImageInfo *img) {
- void *ibuf;
- void *obuf;
- uint32_t isize;
- uint32_t osize;
- lzma_stream stream = LZMA_STREAM_INIT;
- lzma_ret result;
-
- ibuf = (void*)(img + 1);
- isize = img->compressed_size;
- osize = img->original_size;
- obuf = malloc(osize);
- if (!obuf) {
- fprintf(stderr, "Can't allocate %d bytes: %s\n",
- osize,
- strerror(errno));
- return 0;
- }
-
- result = lzma_auto_decoder(&stream, -1, 0);
- if (result != LZMA_OK) {
- fprintf(stderr, "Unable to initialize auto decoder (error: %d)!\n",
- result);
- free(obuf);
- return 0;
- }
-
- stream.next_in = ibuf;
- stream.avail_in = isize;
- stream.next_out = obuf;
- stream.avail_out = osize;
- result = lzma_code(&stream, LZMA_FINISH);
- if (result != LZMA_STREAM_END) {
- fprintf(stderr, "Unalbe to decode data (error: %d)!\n", result);
- free(obuf);
- return 0;
- }
- lzma_end(&stream);
- return obuf;
-}
-
-
-
-// Show what's inside. If todir is NULL, just print. Otherwise unpack.
-int dump_bmpblock(const char *infile, int show_as_yaml,
- const char *todir, int overwrite) {
- void *ptr, *data_ptr;
- size_t length = 0;
- BmpBlockHeader *hdr;
- ImageInfo *img;
- ScreenLayout *scr;
- int loc_num;
- int screen_num;
- int i;
- int offset;
- int free_data;
- char image_name[80];
- char full_path_name[PATH_MAX];
- int yfd, bfd;
- FILE *yfp = stdout;
- FILE *bfp = stdout;
-
- ptr = (void *)read_entire_file(infile, &length);
- if (!ptr)
- return 1;
-
- if (length < sizeof(BmpBlockHeader)) {
- fprintf(stderr, "File %s is too small to be a BMPBLOCK\n", infile);
- discard_file(ptr, length);
- return 1;
- }
-
- if (0 != memcmp(ptr, BMPBLOCK_SIGNATURE, BMPBLOCK_SIGNATURE_SIZE)) {
- fprintf(stderr, "File %s is not a BMPBLOCK\n", infile);
- discard_file(ptr, length);
- return 1;
- }
-
- if (todir) {
- // Unpacking everything. Create the output directory if needed.
- if (0 != require_dir(todir)) {
- discard_file(ptr, length);
- return 1;
- }
-
- // Open yaml output.
- show_as_yaml = 1;
-
- sprintf(full_path_name, "%s/%s", todir, "config.yaml");
- yfd = open(full_path_name,
- O_WRONLY | O_CREAT | O_TRUNC | (overwrite ? 0 : O_EXCL),
- 0666);
- if (yfd < 0) {
- fprintf(stderr, "Unable to open %s: %s\n", full_path_name,
- strerror(errno));
- discard_file(ptr, length);
- return 1;
- }
-
- yfp = fdopen(yfd, "wb");
- if (!yfp) {
- fprintf(stderr, "Unable to fdopen %s: %s\n", full_path_name,
- strerror(errno));
- close(yfd);
- discard_file(ptr, length);
- return 1;
- }
- }
-
- hdr = (BmpBlockHeader *)ptr;
-
- if (!show_as_yaml) {
- printf("%s:\n", infile);
- printf(" version %d.%d\n", hdr->major_version, hdr->minor_version);
- printf(" %d screens\n", hdr->number_of_screenlayouts);
- printf(" %d localizations\n", hdr->number_of_localizations);
- printf(" %d discrete images\n", hdr->number_of_imageinfos);
- discard_file(ptr, length);
- return 0;
- }
-
- // Write out yaml
- fprintf(yfp, "bmpblock: %d.%d\n", hdr->major_version, hdr->minor_version);
- offset = sizeof(BmpBlockHeader) +
- (sizeof(ScreenLayout) *
- hdr->number_of_localizations *
- hdr->number_of_screenlayouts);
- // FIXME(chromium-os:12134): The bmbblock structure allows each image to be
- // compressed differently, but we haven't provided a way for the yaml file to
- // specify that. Additionally, we allow the yaml file to specify a default
- // compression scheme for all images, but only if that line appears in the
- // yaml file before any images. Accordingly, we'll just check the first image
- // to see if it has any compression, and if it does, we'll write that out as
- // the default. When this bug is fixed, we should just write each image's
- // compression setting separately.
- img = (ImageInfo *)(ptr + offset);
- if (img->compression)
- fprintf(yfp, "compression: %d\n", img->compression);
- fprintf(yfp, "images:\n");
- for(i=0; i<hdr->number_of_imageinfos; i++) {
- img = (ImageInfo *)(ptr + offset);
- if (img->compressed_size) {
- sprintf(image_name, "img_%08x.bmp", offset);
- if (img->tag == TAG_HWID) {
- fprintf(yfp, " %s: %s # %dx%d %d/%d tag=%d fmt=%d\n",
- RENDER_HWID, image_name,
- img->width, img->height,
- img->compressed_size, img->original_size,
- img->tag, img->format);
- } else if (img->tag == TAG_HWID_RTOL) {
- fprintf(yfp, " %s: %s # %dx%d %d/%d tag=%d fmt=%d\n",
- RENDER_HWID_RTOL, image_name,
- img->width, img->height,
- img->compressed_size, img->original_size,
- img->tag, img->format);
- } else {
- fprintf(yfp, " img_%08x: %s # %dx%d %d/%d tag=%d fmt=%d\n",
- offset, image_name,
- img->width, img->height,
- img->compressed_size, img->original_size,
- img->tag, img->format);
- }
- if (todir) {
- sprintf(full_path_name, "%s/%s", todir, image_name);
- bfd = open(full_path_name,
- O_WRONLY | O_CREAT | O_TRUNC | (overwrite ? 0 : O_EXCL),
- 0666);
- if (bfd < 0) {
- fprintf(stderr, "Unable to open %s: %s\n", full_path_name,
- strerror(errno));
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- bfp = fdopen(bfd, "wb");
- if (!bfp) {
- fprintf(stderr, "Unable to fdopen %s: %s\n", full_path_name,
- strerror(errno));
- close(bfd);
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- switch(img->compression) {
- case COMPRESS_NONE:
- data_ptr = ptr + offset + sizeof(ImageInfo);
- free_data = 0;
- break;
- case COMPRESS_EFIv1:
- data_ptr = do_efi_decompress(img);
- if (!data_ptr) {
- fclose(bfp);
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- free_data = 1;
- break;
- case COMPRESS_LZMA1:
- data_ptr = do_lzma_decompress(img);
- if (!data_ptr) {
- fclose(bfp);
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- free_data = 1;
- break;
- default:
- fprintf(stderr, "Unsupported compression method encountered.\n");
- fclose(bfp);
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- if (1 != fwrite(data_ptr, img->original_size, 1, bfp)) {
- fprintf(stderr, "Unable to write %s: %s\n", full_path_name,
- strerror(errno));
- fclose(bfp);
- fclose(yfp);
- discard_file(ptr, length);
- return 1;
- }
- fclose(bfp);
- if (free_data)
- free(data_ptr);
- }
- }
- offset += sizeof(ImageInfo);
- offset += img->compressed_size;
- // 4-byte aligned
- if ((offset & 3) > 0)
- offset = (offset & ~3) + 4;
- }
- fprintf(yfp, "screens:\n");
- for(loc_num = 0;
- loc_num < hdr->number_of_localizations;
- loc_num++) {
- for(screen_num = 0;
- screen_num < hdr->number_of_screenlayouts;
- screen_num++) {
- fprintf(yfp, " scr_%d_%d:\n", loc_num, screen_num);
- i = loc_num * hdr->number_of_screenlayouts + screen_num;
- offset = sizeof(BmpBlockHeader) + i * sizeof(ScreenLayout);
- scr = (ScreenLayout *)(ptr + offset);
- for(i=0; i<MAX_IMAGE_IN_LAYOUT; i++) {
- if (scr->images[i].image_info_offset) {
- ImageInfo *iptr =
- (ImageInfo *)(ptr + scr->images[i].image_info_offset);
- if (iptr->tag == TAG_HWID) {
- fprintf(yfp, " - [%d, %d, %s] # tag=%d fmt=%d c=%d %d/%d\n",
- scr->images[i].x, scr->images[i].y,
- RENDER_HWID, iptr->tag, iptr->format, iptr->compression,
- iptr->compressed_size, iptr->original_size);
- } else if (iptr->tag == TAG_HWID_RTOL) {
- fprintf(yfp, " - [%d, %d, %s] # tag=%d fmt=%d c=%d %d/%d\n",
- scr->images[i].x, scr->images[i].y,
- RENDER_HWID_RTOL, iptr->tag,
- iptr->format, iptr->compression,
- iptr->compressed_size, iptr->original_size);
- } else {
- fprintf(yfp, " - [%d, %d, img_%08x]"
- " # tag=%d fmt=%d c=%d %d/%d\n",
- scr->images[i].x, scr->images[i].y,
- scr->images[i].image_info_offset,
- iptr->tag, iptr->format, iptr->compression,
- iptr->compressed_size, iptr->original_size);
- }
- }
- }
- }
- }
- fprintf(yfp, "localizations:\n");
- for(loc_num = 0;
- loc_num < hdr->number_of_localizations;
- loc_num++) {
- fprintf(yfp, " - [");
- for(screen_num = 0;
- screen_num < hdr->number_of_screenlayouts;
- screen_num++) {
- fprintf(yfp, " scr_%d_%d", loc_num, screen_num);
- if (screen_num != hdr->number_of_screenlayouts - 1)
- fprintf(yfp, ",");
- }
- fprintf(yfp, " ]\n");
- }
-
- if (hdr->locale_string_offset) {
- char *loc_ptr = (char *)ptr + hdr->locale_string_offset;
- char c;
- fprintf(yfp, "locale_index:\n");
- while ((c = *loc_ptr) != '\0') {
- fprintf(yfp, " - ");
- do {
- fputc(c, yfp);
- loc_ptr++;
- } while((c = *loc_ptr) != '\0');
- loc_ptr++;
- fputc('\n', yfp);
- }
- }
-
- if (todir)
- fclose(yfp);
-
- discard_file(ptr, length);
-
- return 0;
-}
-
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc
deleted file mode 100644
index 51a35eed..00000000
--- a/utility/bmpblk_utility.cc
+++ /dev/null
@@ -1,777 +0,0 @@
-// Copyright (c) 2010 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.
-//
-// Utility for manipulating firmware screen block (BMPBLOCK) in GBB.
-//
-
-#include <assert.h>
-#include <errno.h>
-#include <getopt.h>
-#include <lzma.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <yaml.h>
-
-#include "bmpblk_utility.h"
-#include "image_types.h"
-#include "vboot_api.h"
-
-extern "C" {
-#include "eficompress.h"
-}
-
-
-static void error(const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "ERROR: ");
- vfprintf(stderr, format, ap);
- va_end(ap);
- exit(1);
-}
-
-///////////////////////////////////////////////////////////////////////
-// BmpBlock Utility implementation
-
-namespace vboot_reference {
-
- BmpBlockUtil::BmpBlockUtil(bool debug) {
- major_version_ = BMPBLOCK_MAJOR_VERSION;
- minor_version_ = BMPBLOCK_MINOR_VERSION;
- config_.config_filename.clear();
- memset(&config_.header, '\0', BMPBLOCK_SIGNATURE_SIZE);
- config_.images_map.clear();
- config_.screens_map.clear();
- config_.localizations.clear();
- bmpblock_.clear();
- set_compression_ = false;
- compression_ = COMPRESS_NONE;
- debug_ = debug;
- render_hwid_ = true;
- support_font_ = true;
- got_font_ = false;
- got_rtol_font_ = false;
- }
-
- BmpBlockUtil::~BmpBlockUtil() {
- }
-
- void BmpBlockUtil::force_compression(uint32_t compression) {
- compression_ = compression;
- set_compression_ = true;
- }
-
- void BmpBlockUtil::load_from_config(const char *filename) {
- load_yaml_config(filename);
- fill_bmpblock_header();
- load_all_image_files();
- }
-
- void BmpBlockUtil::load_yaml_config(const char *filename) {
- yaml_parser_t parser;
-
- config_.config_filename = filename;
- config_.images_map.clear();
- config_.screens_map.clear();
- config_.localizations.clear();
- config_.locale_names.clear();
-
- FILE *fp = fopen(filename, "rb");
- if (!fp) {
- perror(filename);
- exit(errno);
- }
-
- yaml_parser_initialize(&parser);
- yaml_parser_set_input_file(&parser, fp);
- parse_config(&parser);
- yaml_parser_delete(&parser);
- fclose(fp);
-
-
- // TODO: Check the yaml file for self-consistency. Warn on any problems.
- // All images should be used somewhere in the screens.
- // All images referenced in the screens should be defined.
- // All screens should be used somewhere in the localizations.
- // All screens referenced in the localizations should be defined.
- // The number of localizations should match the number of locale_index
-
- if (debug_) {
- printf("%zd image_names\n", config_.image_names.size());
- for (unsigned int i = 0; i < config_.image_names.size(); ++i) {
- printf(" %d: \"%s\"\n", i, config_.image_names[i].c_str());
- }
- printf("%zd images_map\n", config_.images_map.size());
- for (StrImageConfigMap::iterator it = config_.images_map.begin();
- it != config_.images_map.end();
- ++it) {
- printf(" \"%s\": filename=\"%s\" offset=0x%x tag=%d fmt=%d\n",
- it->first.c_str(),
- it->second.filename.c_str(),
- it->second.offset,
- it->second.data.tag,
- it->second.data.format);
- }
- printf("%zd screens_map\n", config_.screens_map.size());
- for (StrScreenConfigMap::iterator it = config_.screens_map.begin();
- it != config_.screens_map.end();
- ++it) {
- printf(" \"%s\":\n", it->first.c_str());
- for (int k=0; k<MAX_IMAGE_IN_LAYOUT; k++) {
- printf(" %d: \"%s\" (%d,%d) ofs=0x%x\n",
- k,
- it->second.image_names[k].c_str(),
- it->second.data.images[k].x,
- it->second.data.images[k].y,
- it->second.data.images[k].image_info_offset);
- }
- }
- }
- }
-
- void BmpBlockUtil::expect_event(yaml_parser_t *parser,
- const yaml_event_type_e type) {
- yaml_event_t event;
- yaml_parser_parse(parser, &event);
- if (event.type != type) {
- error("Syntax error.\n");
- }
- yaml_event_delete(&event);
- }
-
- void BmpBlockUtil::parse_config(yaml_parser_t *parser) {
- expect_event(parser, YAML_STREAM_START_EVENT);
- expect_event(parser, YAML_DOCUMENT_START_EVENT);
- parse_first_layer(parser);
- expect_event(parser, YAML_DOCUMENT_END_EVENT);
- expect_event(parser, YAML_STREAM_END_EVENT);
- }
-
- void BmpBlockUtil::parse_first_layer(yaml_parser_t *parser) {
- yaml_event_t event;
- string keyword;
- expect_event(parser, YAML_MAPPING_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SCALAR_EVENT:
- keyword = (char*)event.data.scalar.value;
- if (keyword == "bmpblock") {
- parse_bmpblock(parser);
- } else if (keyword == "compression") {
- parse_compression(parser);
- } else if (keyword == "images") {
- parse_images(parser);
- } else if (keyword == "screens") {
- parse_screens(parser);
- } else if (keyword == "localizations") {
- parse_localizations(parser);
- } else if (keyword == "locale_index") {
- parse_locale_index(parser);
- }
- break;
- case YAML_MAPPING_END_EVENT:
- yaml_event_delete(&event);
- return;
- default:
- error("Syntax error in parsing config file.\n");
- }
- yaml_event_delete(&event);
- }
- }
-
- void BmpBlockUtil::parse_bmpblock(yaml_parser_t *parser) {
- yaml_event_t event;
- yaml_parser_parse(parser, &event);
- if (event.type != YAML_SCALAR_EVENT) {
- error("Syntax error in parsing bmpblock.\n");
- }
- string gotversion = (char*)event.data.scalar.value;
- if (gotversion != "2.0") {
- error("Unsupported version specified in config file (%s)\n",
- gotversion.c_str());
- }
- yaml_event_delete(&event);
- }
-
- void BmpBlockUtil::parse_compression(yaml_parser_t *parser) {
- yaml_event_t event;
- yaml_parser_parse(parser, &event);
- if (event.type != YAML_SCALAR_EVENT) {
- error("Syntax error in parsing bmpblock.\n");
- }
- char *comp_str = (char *)event.data.scalar.value;
- char *e = 0;
- uint32_t comp = (uint32_t)strtoul(comp_str, &e, 0);
- if (!*comp_str || (e && *e) || comp >= MAX_COMPRESS) {
- error("Invalid compression specified in config file (%d)\n", comp);
- }
- if (!set_compression_) {
- compression_ = comp;
- }
- yaml_event_delete(&event);
- }
-
- void BmpBlockUtil::parse_images(yaml_parser_t *parser) {
- yaml_event_t event;
- string image_name, image_filename;
- expect_event(parser, YAML_MAPPING_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SCALAR_EVENT:
- image_name = (char*)event.data.scalar.value;
- yaml_event_delete(&event);
- yaml_parser_parse(parser, &event);
- if (event.type != YAML_SCALAR_EVENT) {
- error("Syntax error in parsing images.\n");
- }
- image_filename = (char*)event.data.scalar.value;
- config_.image_names.push_back(image_name);
- config_.images_map[image_name] = ImageConfig();
- config_.images_map[image_name].filename = image_filename;
- if (image_name == RENDER_HWID) {
- got_font_ = true;
- }
- if (image_name == RENDER_HWID_RTOL) {
- got_rtol_font_ = true;
- }
- break;
- case YAML_MAPPING_END_EVENT:
- yaml_event_delete(&event);
- return;
- default:
- error("Syntax error in parsing images.\n");
- }
- yaml_event_delete(&event);
- }
- }
-
- void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
- yaml_event_t event;
- int depth = 0, index1 = 0, index2 = 0;
- expect_event(parser, YAML_SEQUENCE_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SEQUENCE_START_EVENT:
- depth++;
- break;
- case YAML_SCALAR_EVENT:
- switch (index2) {
- case 0:
- screen.data.images[index1].x = atoi((char*)event.data.scalar.value);
- break;
- case 1:
- screen.data.images[index1].y = atoi((char*)event.data.scalar.value);
- break;
- case 2:
- screen.image_names[index1] = (char*)event.data.scalar.value;
- // Detect the special case where we're rendering the HWID string
- // instead of displaying a bitmap. The image name may not
- // exist in the list of images (v1.1), but we will still need an
- // ImageInfo struct to remember where to draw the text.
- // Note that v1.2 requires that the image name DOES exist, because
- // the corresponding file is used to hold the font glpyhs.
- if (render_hwid_) {
- if (screen.image_names[index1] == RENDER_HWID) {
- config_.images_map[RENDER_HWID].data.tag = TAG_HWID;
- if (support_font_ && !got_font_)
- error("Font required in 'image:' section for %s\n",
- RENDER_HWID);
- } else if (screen.image_names[index1] == RENDER_HWID_RTOL) {
- config_.images_map[RENDER_HWID_RTOL].data.tag = TAG_HWID_RTOL;
- if (support_font_ && !got_rtol_font_)
- error("Font required in 'image:' section for %s\n",
- RENDER_HWID_RTOL);
- }
- }
- break;
- default:
- error("Syntax error in parsing layout\n");
- }
- index2++;
- break;
- case YAML_SEQUENCE_END_EVENT:
- if (depth == 1) {
- index1++;
- index2 = 0;
- } else if (depth == 0) {
- yaml_event_delete(&event);
- return;
- }
- depth--;
- break;
- default:
- error("Syntax error in paring layout.\n");
- }
- yaml_event_delete(&event);
- }
- }
-
- void BmpBlockUtil::parse_screens(yaml_parser_t *parser) {
- yaml_event_t event;
- string screen_name;
- expect_event(parser, YAML_MAPPING_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SCALAR_EVENT:
- screen_name = (char*)event.data.scalar.value;
- config_.screens_map[screen_name] = ScreenConfig();
- parse_layout(parser, config_.screens_map[screen_name]);
- break;
- case YAML_MAPPING_END_EVENT:
- yaml_event_delete(&event);
- return;
- default:
- error("Syntax error in parsing screens.\n");
- }
- yaml_event_delete(&event);
- }
- }
-
- void BmpBlockUtil::parse_localizations(yaml_parser_t *parser) {
- yaml_event_t event;
- int depth = 0, index = 0;
- expect_event(parser, YAML_SEQUENCE_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SEQUENCE_START_EVENT:
- config_.localizations.push_back(vector<string>());
- depth++;
- break;
- case YAML_SCALAR_EVENT:
- config_.localizations[index].push_back((char*)event.data.scalar.value);
- break;
- case YAML_SEQUENCE_END_EVENT:
- if (depth == 1) {
- index++;
- } else if (depth == 0) {
- yaml_event_delete(&event);
- return;
- }
- depth--;
- break;
- default:
- error("Syntax error in parsing localizations.\n");
- }
- yaml_event_delete(&event);
- }
- }
-
- void BmpBlockUtil::parse_locale_index(yaml_parser_t *parser) {
- yaml_event_t event;
- expect_event(parser, YAML_SEQUENCE_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
- case YAML_SCALAR_EVENT:
- config_.locale_names.append((char*)event.data.scalar.value);
- config_.locale_names.append(1, (char)'\0'); // '\0' to delimit
- break;
- case YAML_SEQUENCE_END_EVENT:
- yaml_event_delete(&event);
- config_.locale_names.append(1, (char)'\0'); // double '\0' to terminate
- return;
- default:
- error("Syntax error in parsing localizations.\n");
- }
- }
- }
-
- void BmpBlockUtil::load_all_image_files() {
- for (unsigned int i = 0; i < config_.image_names.size(); i++) {
- StrImageConfigMap::iterator it =
- config_.images_map.find(config_.image_names[i]);
- if (debug_) {
- printf("loading image \"%s\" from \"%s\"\n",
- config_.image_names[i].c_str(),
- it->second.filename.c_str());
- }
- const string &content = read_image_file(it->second.filename.c_str());
- it->second.raw_content = content;
- it->second.data.original_size = content.size();
- it->second.data.format =
- identify_image_type(content.c_str(),
- (uint32_t)content.size(), &it->second.data);
- if (FORMAT_INVALID == it->second.data.format) {
- error("Unsupported image format in %s\n", it->second.filename.c_str());
- }
- switch(compression_) {
- case COMPRESS_NONE:
- it->second.data.compression = compression_;
- it->second.compressed_content = content;
- it->second.data.compressed_size = content.size();
- break;
- case COMPRESS_EFIv1:
- {
- // The content will always compress smaller (so sez the docs).
- uint32_t tmpsize = content.size();
- uint8_t *tmpbuf = (uint8_t *)malloc(tmpsize);
- // The size of the compressed content is also returned.
- if (EFI_SUCCESS != EfiCompress((uint8_t *)content.c_str(), tmpsize,
- tmpbuf, &tmpsize)) {
- error("Unable to compress!\n");
- }
- it->second.data.compression = compression_;
- it->second.compressed_content.assign((const char *)tmpbuf, tmpsize);
- it->second.data.compressed_size = tmpsize;
- free(tmpbuf);
- }
- break;
- case COMPRESS_LZMA1:
- {
- // Calculate the worst case of buffer size.
- uint32_t tmpsize = lzma_stream_buffer_bound(content.size());
- uint8_t *tmpbuf = (uint8_t *)malloc(tmpsize);
- lzma_stream stream = LZMA_STREAM_INIT;
- lzma_options_lzma options;
- lzma_ret result;
-
- lzma_lzma_preset(&options, 9);
- result = lzma_alone_encoder(&stream, &options);
- if (result != LZMA_OK) {
- error("Unable to initialize easy encoder (error: %d)!\n", result);
- }
-
- stream.next_in = (uint8_t *)content.data();
- stream.avail_in = content.size();
- stream.next_out = tmpbuf;
- stream.avail_out = tmpsize;
- result = lzma_code(&stream, LZMA_FINISH);
- if (result != LZMA_STREAM_END) {
- error("Unable to encode data (error: %d)!\n", result);
- }
-
- it->second.data.compression = compression_;
- it->second.compressed_content.assign((const char *)tmpbuf,
- tmpsize - stream.avail_out);
- it->second.data.compressed_size = tmpsize - stream.avail_out;
- lzma_end(&stream);
- free(tmpbuf);
- }
- break;
- default:
- error("Unsupported compression method attempted.\n");
- }
- }
- }
-
- const string BmpBlockUtil::read_image_file(const char *filename) {
- string content;
- vector<char> buffer;
-
- FILE *fp = fopen(filename, "rb");
- if (!fp) {
- perror(filename);
- exit(errno);
- }
-
- if (fseek(fp, 0, SEEK_END) == 0) {
- buffer.resize(ftell(fp));
- rewind(fp);
- }
-
- if (!buffer.empty()) {
- if(fread(&buffer[0], buffer.size(), 1, fp) != 1) {
- perror(filename);
- buffer.clear();
- } else {
- content.assign(buffer.begin(), buffer.end());
- }
- }
-
- fclose(fp);
- return content;
- }
-
- void BmpBlockUtil::fill_bmpblock_header() {
- memset(&config_.header, '\0', sizeof(config_.header));
- memcpy(&config_.header.signature, BMPBLOCK_SIGNATURE,
- BMPBLOCK_SIGNATURE_SIZE);
- config_.header.major_version = major_version_;
- config_.header.minor_version = minor_version_;
- config_.header.number_of_localizations = config_.localizations.size();
- config_.header.number_of_screenlayouts = config_.localizations[0].size();
- // NOTE: this is part of the yaml consistency check
- for (unsigned int i = 1; i < config_.localizations.size(); ++i) {
- assert(config_.header.number_of_screenlayouts ==
- config_.localizations[i].size());
- }
- config_.header.number_of_imageinfos = config_.images_map.size();
- config_.header.locale_string_offset = 0; // Filled by pack_bmpblock()
- }
-
- void BmpBlockUtil::pack_bmpblock() {
- bmpblock_.clear();
-
- /* Compute the ImageInfo offsets from start of BMPBLOCK. */
- uint32_t current_offset = sizeof(BmpBlockHeader) +
- sizeof(ScreenLayout) * (config_.header.number_of_localizations *
- config_.header.number_of_screenlayouts);
- for (StrImageConfigMap::iterator it = config_.images_map.begin();
- it != config_.images_map.end();
- ++it) {
- it->second.offset = current_offset;
- if (debug_)
- printf(" \"%s\": filename=\"%s\" offset=0x%x tag=%d fmt=%d\n",
- it->first.c_str(),
- it->second.filename.c_str(),
- it->second.offset,
- it->second.data.tag,
- it->second.data.format);
- current_offset += sizeof(ImageInfo) +
- it->second.data.compressed_size;
- /* Make it 4-byte aligned. */
- if ((current_offset & 3) > 0) {
- current_offset = (current_offset & ~3) + 4;
- }
- }
- /* And leave room for the locale_index string */
- if (config_.locale_names.size()) {
- config_.header.locale_string_offset = current_offset;
- current_offset += config_.locale_names.size();
- }
-
- bmpblock_.resize(current_offset);
-
- /* Fill BmpBlockHeader struct. */
- string::iterator current_filled = bmpblock_.begin();
- std::copy(reinterpret_cast<char*>(&config_.header),
- reinterpret_cast<char*>(&config_.header + 1),
- current_filled);
- current_filled += sizeof(config_.header);
- current_offset = sizeof(config_.header);
-
- /* Fill all ScreenLayout structs. */
- for (unsigned int i = 0; i < config_.localizations.size(); ++i) {
- for (unsigned int j = 0; j < config_.localizations[i].size(); ++j) {
- ScreenConfig &screen = config_.screens_map[config_.localizations[i][j]];
- for (unsigned int k = 0;
- k < MAX_IMAGE_IN_LAYOUT && !screen.image_names[k].empty();
- ++k) {
- if (config_.images_map.find(screen.image_names[k]) ==
- config_.images_map.end()) {
- error("Invalid image name \"%s\"\n", screen.image_names[k].c_str());
- }
- if (debug_)
- printf("i=%d j=%d k=%d=\"%s\" (%d,%d) ofs=%x\n", i,j,k,
- screen.image_names[k].c_str(),
- screen.data.images[k].x, screen.data.images[k].y,
- config_.images_map[screen.image_names[k]].offset
- );
- screen.data.images[k].image_info_offset =
- config_.images_map[screen.image_names[k]].offset;
- }
- std::copy(reinterpret_cast<char*>(&screen.data),
- reinterpret_cast<char*>(&screen.data + 1),
- current_filled);
- current_filled += sizeof(screen.data);
- if (debug_)
- printf("S: current offset is 0x%08x\n", current_offset);
- current_offset += sizeof(screen.data);
- }
- }
-
- /* Fill all ImageInfo structs and image contents. */
- for (StrImageConfigMap::iterator it = config_.images_map.begin();
- it != config_.images_map.end();
- ++it) {
- current_filled = bmpblock_.begin() + it->second.offset;
- current_offset = it->second.offset;
- if (debug_)
- printf("I0: current offset is 0x%08x\n", current_offset);
- std::copy(reinterpret_cast<char*>(&it->second.data),
- reinterpret_cast<char*>(&it->second.data + 1),
- current_filled);
- current_filled += sizeof(it->second.data);
- current_offset += sizeof(it->second.data);
- if (debug_)
- printf("I1: current offset is 0x%08x (len %zd)\n",
- current_offset, it->second.compressed_content.length());
- std::copy(it->second.compressed_content.begin(),
- it->second.compressed_content.end(),
- current_filled);
- }
-
- /* Fill in locale_names. */
- if (config_.header.locale_string_offset) {
- current_offset = config_.header.locale_string_offset;
- current_filled = bmpblock_.begin() + current_offset;
- if (debug_)
- printf("locale_names: offset 0x%08x (len %zd)\n",
- current_offset, config_.locale_names.size());
- std::copy(config_.locale_names.begin(),
- config_.locale_names.end(),
- current_filled);
- }
- }
-
- void BmpBlockUtil::write_to_bmpblock(const char *filename) {
- assert(!bmpblock_.empty());
-
- FILE *fp = fopen(filename, "wb");
- if (!fp) {
- perror(filename);
- exit(errno);
- }
-
- int r = fwrite(bmpblock_.c_str(), bmpblock_.size(), 1, fp);
- fclose(fp);
- if (r != 1) {
- perror(filename);
- exit(errno);
- }
- }
-
-} // namespace vboot_reference
-
-#ifndef FOR_LIBRARY
-
- //////////////////////////////////////////////////////////////////////////////
- // Command line utilities.
-
- extern "C" {
-#include "bmpblk_util.h"
- }
-
- using vboot_reference::BmpBlockUtil;
-
- // utility function: provide usage of this utility and exit.
- static void usagehelp_exit(const char *prog_name) {
- printf(
- "\n"
- "To create a new BMPBLOCK file using config from YAML file:\n"
- "\n"
- " %s [-z NUM] -c YAML BMPBLOCK\n"
- "\n"
- " -z NUM = compression algorithm to use\n"
- " 0 = none\n"
- " 1 = EFIv1\n"
- " 2 = LZMA1\n"
- "\n", prog_name);
- printf(
- "To display the contents of a BMPBLOCK:\n"
- "\n"
- " %s [-y] BMPBLOCK\n"
- "\n"
- " -y = display as yaml\n"
- "\n", prog_name);
- printf(
- "To unpack a BMPBLOCK file:\n"
- "\n"
- " %s -x [-d DIR] [-f] BMPBLOCK\n"
- "\n"
- " -d DIR = directory to use (default '.')\n"
- " -f = force overwriting existing files\n"
- "\n", prog_name);
- exit(1);
- }
-
- ///////////////////////////////////////////////////////////////////////
- // main
-
- int main(int argc, char *argv[]) {
-
- const char *prog_name = strrchr(argv[0], '/');
- if (prog_name)
- prog_name++;
- else
- prog_name = argv[0];
-
- int overwrite = 0, extract_mode = 0;
- int compression = 0;
- int set_compression = 0;
- const char *config_fn = 0, *bmpblock_fn = 0, *extract_dir = ".";
- int show_as_yaml = 0;
- bool debug = false;
-
- int opt;
- opterr = 0; // quiet
- int errorcnt = 0;
- char *e = 0;
- while ((opt = getopt(argc, argv, ":c:xz:fd:yD")) != -1) {
- switch (opt) {
- case 'c':
- config_fn = optarg;
- break;
- case 'x':
- extract_mode = 1;
- break;
- case 'y':
- show_as_yaml = 1;
- break;
- case 'z':
- compression = (int)strtoul(optarg, &e, 0);
- if (!*optarg || (e && *e)) {
- fprintf(stderr, "%s: invalid argument to -%c: \"%s\"\n",
- prog_name, opt, optarg);
- errorcnt++;
- }
- if (compression >= MAX_COMPRESS) {
- fprintf(stderr, "%s: compression type must be less than %d\n",
- prog_name, MAX_COMPRESS);
- errorcnt++;
- }
- set_compression = 1;
- break;
- case 'f':
- overwrite = 1;
- break;
- case 'd':
- extract_dir= optarg;
- break;
- case 'D':
- debug = true;
- break;
- case ':':
- fprintf(stderr, "%s: missing argument to -%c\n",
- prog_name, optopt);
- errorcnt++;
- break;
- default:
- fprintf(stderr, "%s: unrecognized switch: -%c\n",
- prog_name, optopt);
- errorcnt++;
- break;
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc >= 1) {
- bmpblock_fn = argv[0];
- } else {
- fprintf(stderr, "%s: missing BMPBLOCK name\n", prog_name);
- errorcnt++;
- }
-
- if (errorcnt)
- usagehelp_exit(prog_name);
-
- BmpBlockUtil util(debug);
-
- if (config_fn) {
- if (set_compression)
- util.force_compression(compression);
- util.load_from_config(config_fn);
- util.pack_bmpblock();
- util.write_to_bmpblock(bmpblock_fn);
- }
-
- else if (extract_mode) {
- return dump_bmpblock(bmpblock_fn, 1, extract_dir, overwrite);
- } else {
- return dump_bmpblock(bmpblock_fn, show_as_yaml, 0, 0);
- }
-
- return 0;
- }
-
-#endif // FOR_LIBRARY
diff --git a/utility/image_types.c b/utility/image_types.c
deleted file mode 100644
index 8fcd94ed..00000000
--- a/utility/image_types.c
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include <stdint.h>
-#include <string.h>
-
-#include "bmpblk_header.h"
-#include "bmpblk_font.h"
-#include "image_types.h"
-
-/* BMP header, used to validate image requirements
- * See http://en.wikipedia.org/wiki/BMP_file_format
- */
-typedef struct {
- uint8_t CharB; // must be 'B'
- uint8_t CharM; // must be 'M'
- uint32_t Size;
- uint16_t Reserved[2];
- uint32_t ImageOffset;
- uint32_t HeaderSize;
- uint32_t PixelWidth;
- uint32_t PixelHeight;
- uint16_t Planes; // Must be 1 for x86
- uint16_t BitPerPixel; // 1, 4, 8, or 24 for x86
- uint32_t CompressionType; // 0 (none) for x86, 1 (RLE) for arm
- uint32_t ImageSize;
- uint32_t XPixelsPerMeter;
- uint32_t YPixelsPerMeter;
- uint32_t NumberOfColors;
- uint32_t ImportantColors;
-} __attribute__((packed)) BMP_IMAGE_HEADER;
-
-
-ImageFormat identify_image_type(const void *buf, uint32_t bufsize,
- ImageInfo *info) {
-
- if (info)
- info->format = FORMAT_INVALID;
-
- if (bufsize < sizeof(BMP_IMAGE_HEADER) &&
- bufsize < sizeof(FontArrayHeader)) {
- return FORMAT_INVALID;
- }
-
- const BMP_IMAGE_HEADER *bhdr = buf;
- if (bhdr->CharB == 'B' && bhdr->CharM == 'M' &&
- bhdr->Planes == 1 &&
- (bhdr->CompressionType == 0 || bhdr->CompressionType == 1) &&
- (bhdr->BitPerPixel == 1 || bhdr->BitPerPixel == 4 ||
- bhdr->BitPerPixel == 8 || bhdr->BitPerPixel == 24)) {
- if (info) {
- info->format = FORMAT_BMP;
- info->width = bhdr->PixelWidth;
- info->height = bhdr->PixelHeight;
- }
- return FORMAT_BMP;
- }
-
- const FontArrayHeader *fhdr = buf;
- if (0 == memcmp(&fhdr->signature, FONT_SIGNATURE, FONT_SIGNATURE_SIZE) &&
- fhdr->num_entries > 0) {
- if (info)
- info->format = FORMAT_FONT;
- return FORMAT_FONT;
- }
-
- return FORMAT_INVALID;
-}
-
-
diff --git a/utility/include/bmpblk_util.h b/utility/include/bmpblk_util.h
deleted file mode 100644
index c8caf1fc..00000000
--- a/utility/include/bmpblk_util.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef VBOOT_REFERENCE_BMPBLK_UTIL_H_
-#define VBOOT_REFERENCE_BMPBLK_UTIL_H_
-
-#include "bmpblk_header.h"
-
-int dump_bmpblock(const char *infile, int show_as_yaml,
- const char *todir, int overwrite);
-
-#endif // VBOOT_REFERENCE_BMPBLK_UTIL_H_
diff --git a/utility/include/bmpblk_utility.h b/utility/include/bmpblk_utility.h
deleted file mode 100644
index 1d2fb94e..00000000
--- a/utility/include/bmpblk_utility.h
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (c) 2010 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.
-
-
-#ifndef VBOOT_REFERENCE_BMPBLK_UTILITY_H_
-#define VBOOT_REFERENCE_BMPBLK_UTILITY_H_
-
-#include "bmpblk_header.h"
-#include "bmpblk_font.h"
-#include "image_types.h"
-
-#include <yaml.h>
-
-#include <map>
-#include <string>
-#include <vector>
-
-using std::map;
-using std::string;
-using std::vector;
-
-namespace vboot_reference {
-
-/* Internal struct for contructing ImageInfo. */
-typedef struct ImageConfig {
- ImageInfo data;
- string filename;
- string raw_content;
- string compressed_content;
- uint32_t offset;
-} ImageConfig;
-
-/* Internal struct for contructing ScreenLayout. */
-typedef struct ScreenConfig {
- ScreenLayout data;
- string image_names[MAX_IMAGE_IN_LAYOUT];
-} ScreenConfig;
-
-typedef map<string, ImageConfig> StrImageConfigMap;
-typedef map<string, ScreenConfig> StrScreenConfigMap;
-
-/* Internal struct for contructing the whole BmpBlock. */
-typedef struct BmpBlockConfig {
- string config_filename;
- BmpBlockHeader header;
- vector<string> image_names;
- StrImageConfigMap images_map;
- StrScreenConfigMap screens_map;
- vector<vector<string> > localizations;
- string locale_names;
-} BmpBlockConfig;
-
-class BmpBlockUtil {
- public:
- BmpBlockUtil(bool debug);
- ~BmpBlockUtil();
-
- /* Load all the images and related information according to a config file. */
- void load_from_config(const char *filename);
-
- /* Contruct the bmpblock. */
- void pack_bmpblock();
-
- /* Write the bmpblock to a file */
- void write_to_bmpblock(const char *filename);
-
- /* What compression to use for the images */
- void force_compression(uint32_t compression);
-
- private:
- /* Elemental function called from load_from_config.
- * Load the config file (yaml format) and parse it. */
- void load_yaml_config(const char *filename);
-
- /* Elemental function called from load_from_config.
- * Load all image files into the internal variables. */
- void load_all_image_files();
-
- /* Elemental function called from load_from_config.
- * Contruct the BmpBlockHeader struct. */
- void fill_bmpblock_header();
-
- /* Helper functions for parsing a YAML config file. */
- void expect_event(yaml_parser_t *parser, const yaml_event_type_e type);
- void parse_config(yaml_parser_t *parser);
- void parse_first_layer(yaml_parser_t *parser);
- void parse_bmpblock(yaml_parser_t *parser);
- void parse_compression(yaml_parser_t *parser);
- void parse_images(yaml_parser_t *parser);
- void parse_layout(yaml_parser_t *parser, ScreenConfig &screen);
- void parse_screens(yaml_parser_t *parser);
- void parse_localizations(yaml_parser_t *parser);
- void parse_locale_index(yaml_parser_t *parser);
-
- /* Useful functions */
- const string read_image_file(const char *filename);
-
- /* Verbosity flags */
- bool debug_;
-
- /* Internal variable for string the BmpBlock version. */
- uint16_t major_version_;
- uint16_t minor_version_;
-
- /* Flags for version-specific features */
- bool render_hwid_;
- bool support_font_;
- bool got_font_;
- bool got_rtol_font_;
-
- /* Internal variable for storing the config of BmpBlock. */
- BmpBlockConfig config_;
-
- /* Internal variable for storing the content of BmpBlock. */
- string bmpblock_;
-
- /* Internal variables to determine whether or not to specify compression */
- bool set_compression_; // true if we force it
- uint32_t compression_; // what we force it to
-};
-
-} // namespace vboot_reference
-
-#endif // VBOOT_REFERENCE_BMPBLK_UTILITY_H_
diff --git a/utility/include/image_types.h b/utility/include/image_types.h
deleted file mode 100644
index f85a9a98..00000000
--- a/utility/include/image_types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 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.
- */
-
-#ifndef VBOOT_REFERENCE_IMAGE_TYPES_H_
-#define VBOOT_REFERENCE_IMAGE_TYPES_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#include <stdint.h>
-#include "bmpblk_header.h"
-
-/* Identify the data. Fill in known values if info is not NULL */
-ImageFormat identify_image_type(const void *buf, uint32_t bufsize,
- ImageInfo *info);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* VBOOT_REFERENCE_IMAGE_TYPES_H_ */
-