mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 02:35:22 +00:00
Change GBB bmpblock to version 1.1, supporting direct HWID rendering.
With version 1.0, the BIOS displays its screens using composited images, but
we still have to create a new bmp image for every HWID. Version 1.1 lets us
render the ASCII HWID string directly, so the BIOS screens don't need
modification just because the HWID changes.
In the yaml file, we just replace the hwid image with a magic string, like
so:
bmpblock: 1.1
[...]
screens:
en_remove:
- [ 0, 0, remove_bg]
- [256, 534, en_model_text]
- [314, 534, $HWID]
- [192, 479, url]
- [195, 453, en_remove_text]
This change modifies the bmpblk_utility to accept and generate both 1.0 and
1.1 versions. It also updates the supporting scripts (most of which aren't
needed anymore) and adds a new DEFAULT.yaml file which can be used as the
basis for all locales.
BUG=chrome-os-partner:3264
TEST=none (manual)
Change-Id: I012349393848393928282
Reviewed-on: http://gerrit.chromium.org/gerrit/378
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
@@ -52,7 +52,7 @@ __pragma(pack(push, 1)) /* Support packing for MSVC. */
|
|||||||
#define BMPBLOCK_SIGNATURE_SIZE (4)
|
#define BMPBLOCK_SIGNATURE_SIZE (4)
|
||||||
|
|
||||||
#define BMPBLOCK_MAJOR_VERSION (0x0001)
|
#define BMPBLOCK_MAJOR_VERSION (0x0001)
|
||||||
#define BMPBLOCK_MINOR_VERSION (0x0000)
|
#define BMPBLOCK_MINOR_VERSION (0x0001)
|
||||||
|
|
||||||
#define MAX_IMAGE_IN_LAYOUT (8)
|
#define MAX_IMAGE_IN_LAYOUT (8)
|
||||||
|
|
||||||
@@ -106,6 +106,7 @@ typedef struct ImageInfo {
|
|||||||
typedef enum ImageTag {
|
typedef enum ImageTag {
|
||||||
TAG_NONE = 0,
|
TAG_NONE = 0,
|
||||||
TAG_HWID,
|
TAG_HWID,
|
||||||
|
TAG_HWID_RTOL, /* "right-to-left", ie, right-justified HWID */
|
||||||
} ImageTag;
|
} ImageTag;
|
||||||
|
|
||||||
/* Constants for ImageInfo.format */
|
/* Constants for ImageInfo.format */
|
||||||
@@ -122,6 +123,13 @@ typedef enum Compression {
|
|||||||
MAX_COMPRESS,
|
MAX_COMPRESS,
|
||||||
} Compression;
|
} Compression;
|
||||||
|
|
||||||
|
/* 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"
|
||||||
|
|
||||||
__pragma(pack(pop)) /* Support packing for MSVC. */
|
__pragma(pack(pop)) /* Support packing for MSVC. */
|
||||||
|
|
||||||
#endif /* VBOOT_REFERENCE_BMPBLK_HEADER_H_ */
|
#endif /* VBOOT_REFERENCE_BMPBLK_HEADER_H_ */
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ This directory contains examples of the new-style BIOS bitmaps, and a simple
|
|||||||
(and ugly) tool to view the configuration file that describes how each
|
(and ugly) tool to view the configuration file that describes how each
|
||||||
screen is displayed.
|
screen is displayed.
|
||||||
|
|
||||||
Old-style bitmaps:
|
Note:
|
||||||
|
|
||||||
|
Because the bitmap images and display code is part of the Read-Only BIOS,
|
||||||
|
back-porting any new bitmaps to older devices is not possible.
|
||||||
|
|
||||||
|
|
||||||
|
Old-style, unversioned bitmaps (used in Cr-48):
|
||||||
|
|
||||||
In the Cr-48 BIOS there are four BIOS screens that may be presented to the
|
In the Cr-48 BIOS there are four BIOS screens that may be presented to the
|
||||||
user. Each contains a graphic, a URL, and some informative text. The screens
|
user. Each contains a graphic, a URL, and some informative text. The screens
|
||||||
@@ -14,21 +20,26 @@ BIOS is compiled. The result is an opaque blob that cannot be viewed or
|
|||||||
edited with linux-based tools.
|
edited with linux-based tools.
|
||||||
|
|
||||||
|
|
||||||
New-style bitmaps (version 1.0):
|
Version 1.0, new-style bitmaps (used in Alex):
|
||||||
|
|
||||||
Future BIOSes will continue to display the same basic screens, but using a
|
The BIOSes will continue to display the same basic screens, but it uses a
|
||||||
different format. Each screen has separate bitmaps for the basic graphic,
|
different format. Each screen has separate bitmaps for the basic graphic,
|
||||||
the URL, and the informative text, and will be displayed by rendering each
|
the URL, and the informative text, and is displayed by rendering each
|
||||||
component in order. This will allow us to modify and replace any bitmap
|
component in order. This allows us to modify and replace any bitmap (most
|
||||||
(most frequently the HWID), using standard command-line tools such as
|
frequently the HWID), using standard command-line tools such as imagemagick.
|
||||||
imagemagick. Compositing each screen in this way also means that we can
|
Compositing each screen in this way also means that we can easily provide
|
||||||
easily provide localized BIOS screens or custom messages.
|
localized BIOS screens or custom messages.
|
||||||
|
|
||||||
|
|
||||||
Note:
|
Version 1.1 (used in ZGB):
|
||||||
|
|
||||||
|
This is essentially the same as version 1.0, except that the ASCII HWID
|
||||||
|
string can be rendered directly. In the screen description, the magic image
|
||||||
|
name "$HWID" (or "$HWID.rtol") indicates that the ASCII HWID value should be
|
||||||
|
displayed instead of an actual image. This means that we only need to
|
||||||
|
generate one bmpblock for all locales, since the HWID string can be changed
|
||||||
|
at the factory using "gbb_utility".
|
||||||
|
|
||||||
Because the bitmap images and display code is part of the Read-Only BIOS,
|
|
||||||
back-porting the new-style bitmaps to older devices is not possible.
|
|
||||||
|
|
||||||
|
|
||||||
Manual instructions:
|
Manual instructions:
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ from lib import bmpblock
|
|||||||
from lib import pixcontrol
|
from lib import pixcontrol
|
||||||
from lib import pixdisplay
|
from lib import pixdisplay
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wx.App):
|
class MyApp(wx.App):
|
||||||
|
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
self._bmpblock = bmpblock.BmpBlock(sys.argv[1])
|
|
||||||
progname = os.path.basename(sys.argv[0])
|
progname = os.path.basename(sys.argv[0])
|
||||||
|
progdir = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||||
|
self._bmpblock = bmpblock.BmpBlock(os.path.join(progdir, 'lib'),
|
||||||
|
sys.argv[1])
|
||||||
self._mainframe = pixcontrol.Frame(self._bmpblock, progname)
|
self._mainframe = pixcontrol.Frame(self._bmpblock, progname)
|
||||||
self._mainframe.Show()
|
self._mainframe.Show()
|
||||||
self.SetTopWindow(self._mainframe)
|
self.SetTopWindow(self._mainframe)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
1398
scripts/newbitmaps/images/1366x768/DEFAULT.yaml
Normal file
1398
scripts/newbitmaps/images/1366x768/DEFAULT.yaml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 5.4 KiB |
@@ -6,6 +6,15 @@
|
|||||||
# Generate a new yaml file for each specified hwid_*.bmp file.
|
# Generate a new yaml file for each specified hwid_*.bmp file.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--force" ]; then
|
||||||
|
shift;
|
||||||
|
else
|
||||||
|
echo "This script is deprecated."
|
||||||
|
echo "The latest BIOSes can render HWIDs directly from ASCII."
|
||||||
|
echo "Use --force to proceed anyway."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# I'm sorting the locales in more-or-less geographical order. Right should move
|
# I'm sorting the locales in more-or-less geographical order. Right should move
|
||||||
# east, left should move west. Of course we'll start in the US. :-)
|
# east, left should move west. Of course we'll start in the US. :-)
|
||||||
locales="en es_419 pt_BR en_GB fr es pt_PT ca it de el nl da no sv fi et lv lt ru pl cs sk hu sl sr hr bg ro uk tr iw ar fa hi th vi id fil zh_CN zh_TW ko ja"
|
locales="en es_419 pt_BR en_GB fr es pt_PT ca it de el nl da no sv fi et lv lt ru pl cs sk hu sl sr hr bg ro uk tr iw ar fa hi th vi id fil zh_CN zh_TW ko ja"
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ class BmpBlock(object):
|
|||||||
It has a few special attributes to specify which part we're focusing on.
|
It has a few special attributes to specify which part we're focusing on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, filename=None):
|
def __init__(self, libdir, filename=None):
|
||||||
self.yaml = None
|
self.yaml = None
|
||||||
self.filename = None
|
self.filename = None
|
||||||
self.current_screen = None
|
self.current_screen = None
|
||||||
|
self.libdir = libdir
|
||||||
self.filename = filename # always set, so we can reload
|
self.filename = filename # always set, so we can reload
|
||||||
if filename:
|
if filename:
|
||||||
self.LoadFile(filename)
|
self.LoadFile(filename)
|
||||||
@@ -45,9 +46,9 @@ class BmpBlock(object):
|
|||||||
"""Raise an error if the specified dict is not a valid BmpBlock structure"""
|
"""Raise an error if the specified dict is not a valid BmpBlock structure"""
|
||||||
|
|
||||||
assert isinstance(thing, dict)
|
assert isinstance(thing, dict)
|
||||||
assert thing["bmpblock"] == 1.0
|
assert thing["bmpblock"] == 1.0 or thing["bmpblock"] == 1.1
|
||||||
|
|
||||||
seen_images = {}
|
seen_images = {"$HWID":1, "$HWID.rtol":2}
|
||||||
seen_screens = {}
|
seen_screens = {}
|
||||||
|
|
||||||
images = thing["images"]
|
images = thing["images"]
|
||||||
@@ -56,6 +57,10 @@ class BmpBlock(object):
|
|||||||
# image values should all be filenames (ie, strings)
|
# image values should all be filenames (ie, strings)
|
||||||
for val in images.values():
|
for val in images.values():
|
||||||
assert val and isinstance(val, types.StringTypes)
|
assert val and isinstance(val, types.StringTypes)
|
||||||
|
if not "$HWID" in images:
|
||||||
|
images["$HWID"] = os.path.join(self.libdir,'current_hwid.bmp')
|
||||||
|
if not "$HWID.rtol" in images:
|
||||||
|
images["$HWID.rtol"] = os.path.join(self.libdir, 'current_hwid.bmp')
|
||||||
|
|
||||||
screens = thing["screens"]
|
screens = thing["screens"]
|
||||||
assert isinstance(screens, dict)
|
assert isinstance(screens, dict)
|
||||||
|
|||||||
BIN
scripts/newbitmaps/lib/current_hwid.bmp
Normal file
BIN
scripts/newbitmaps/lib/current_hwid.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
@@ -13,10 +13,17 @@ import re
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if '--force' in sys.argv:
|
||||||
print "usage: %s autotest/../hardware_Components/" % sys.argv[0]
|
sys.argv.remove('--force')
|
||||||
|
else:
|
||||||
|
print "This script is deprecated."
|
||||||
|
print "The latest BIOSes can render HWIDs directly from ASCII."
|
||||||
|
print "Use --force to proceed anyway."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print "usage: %s --force autotest/../hardware_Components/" % sys.argv[0]
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def MakeBmp(hwid, geom, bmp, directory):
|
def MakeBmp(hwid, geom, bmp, directory):
|
||||||
""" Create the bitmap for this file. """
|
""" Create the bitmap for this file. """
|
||||||
|
|||||||
@@ -282,10 +282,24 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
|
|||||||
fprintf(yfp, "images:\n");
|
fprintf(yfp, "images:\n");
|
||||||
for(i=0; i<hdr->number_of_imageinfos; i++) {
|
for(i=0; i<hdr->number_of_imageinfos; i++) {
|
||||||
img = (ImageInfo *)(ptr + offset);
|
img = (ImageInfo *)(ptr + offset);
|
||||||
|
if (img->compressed_size) {
|
||||||
sprintf(image_name, "img_%08x.bmp", offset);
|
sprintf(image_name, "img_%08x.bmp", offset);
|
||||||
fprintf(yfp, " img_%08x: %s # %dx%d %d/%d\n", offset, image_name,
|
if (img->tag == TAG_HWID) {
|
||||||
|
fprintf(yfp, " %s: %s # %dx%d %d/%d tag=%d\n",
|
||||||
|
RENDER_HWID, image_name,
|
||||||
img->width, img->height,
|
img->width, img->height,
|
||||||
img->compressed_size, img->original_size);
|
img->compressed_size, img->original_size, img->tag);
|
||||||
|
} else if (img->tag == TAG_HWID_RTOL) {
|
||||||
|
fprintf(yfp, " %s: %s # %dx%d %d/%d tag=%d\n",
|
||||||
|
RENDER_HWID_RTOL, image_name,
|
||||||
|
img->width, img->height,
|
||||||
|
img->compressed_size, img->original_size, img->tag);
|
||||||
|
} else {
|
||||||
|
fprintf(yfp, " img_%08x: %s # %dx%d %d/%d tag=%d\n",
|
||||||
|
offset, image_name,
|
||||||
|
img->width, img->height,
|
||||||
|
img->compressed_size, img->original_size, img->tag);
|
||||||
|
}
|
||||||
if (todir) {
|
if (todir) {
|
||||||
sprintf(full_path_name, "%s/%s", todir, image_name);
|
sprintf(full_path_name, "%s/%s", todir, image_name);
|
||||||
bfd = open(full_path_name,
|
bfd = open(full_path_name,
|
||||||
@@ -351,6 +365,7 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
|
|||||||
if (free_data)
|
if (free_data)
|
||||||
free(data_ptr);
|
free(data_ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
offset += sizeof(ImageInfo);
|
offset += sizeof(ImageInfo);
|
||||||
offset += img->compressed_size;
|
offset += img->compressed_size;
|
||||||
// 4-byte aligned
|
// 4-byte aligned
|
||||||
@@ -370,6 +385,17 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
|
|||||||
scr = (ScreenLayout *)(ptr + offset);
|
scr = (ScreenLayout *)(ptr + offset);
|
||||||
for(i=0; i<MAX_IMAGE_IN_LAYOUT; i++) {
|
for(i=0; i<MAX_IMAGE_IN_LAYOUT; i++) {
|
||||||
if (scr->images[i].image_info_offset) {
|
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]\n",
|
||||||
|
scr->images[i].x, scr->images[i].y,
|
||||||
|
RENDER_HWID);
|
||||||
|
} else if (iptr->tag == TAG_HWID_RTOL) {
|
||||||
|
fprintf(yfp, " - [%d, %d, %s]\n",
|
||||||
|
scr->images[i].x, scr->images[i].y,
|
||||||
|
RENDER_HWID_RTOL);
|
||||||
|
} else {
|
||||||
fprintf(yfp, " - [%d, %d, img_%08x]\n",
|
fprintf(yfp, " - [%d, %d, img_%08x]\n",
|
||||||
scr->images[i].x, scr->images[i].y,
|
scr->images[i].x, scr->images[i].y,
|
||||||
scr->images[i].image_info_offset);
|
scr->images[i].image_info_offset);
|
||||||
@@ -377,6 +403,7 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fprintf(yfp, "localizations:\n");
|
fprintf(yfp, "localizations:\n");
|
||||||
for(loc_num = 0;
|
for(loc_num = 0;
|
||||||
loc_num < hdr->number_of_localizations;
|
loc_num < hdr->number_of_localizations;
|
||||||
|
|||||||
@@ -59,14 +59,9 @@ static void error(const char *format, ...) {
|
|||||||
|
|
||||||
namespace vboot_reference {
|
namespace vboot_reference {
|
||||||
|
|
||||||
BmpBlockUtil::BmpBlockUtil() {
|
BmpBlockUtil::BmpBlockUtil(bool debug) {
|
||||||
initialize();
|
major_version_ = BMPBLOCK_MAJOR_VERSION;
|
||||||
}
|
minor_version_ = BMPBLOCK_MINOR_VERSION;
|
||||||
|
|
||||||
BmpBlockUtil::~BmpBlockUtil() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void BmpBlockUtil::initialize() {
|
|
||||||
config_.config_filename.clear();
|
config_.config_filename.clear();
|
||||||
memset(&config_.header, '\0', BMPBLOCK_SIGNATURE_SIZE);
|
memset(&config_.header, '\0', BMPBLOCK_SIGNATURE_SIZE);
|
||||||
config_.images_map.clear();
|
config_.images_map.clear();
|
||||||
@@ -75,21 +70,24 @@ void BmpBlockUtil::initialize() {
|
|||||||
bmpblock_.clear();
|
bmpblock_.clear();
|
||||||
set_compression_ = false;
|
set_compression_ = false;
|
||||||
compression_ = COMPRESS_NONE;
|
compression_ = COMPRESS_NONE;
|
||||||
}
|
debug_ = debug;
|
||||||
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::force_compression(uint32_t compression) {
|
BmpBlockUtil::~BmpBlockUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void BmpBlockUtil::force_compression(uint32_t compression) {
|
||||||
compression_ = compression;
|
compression_ = compression;
|
||||||
set_compression_ = true;
|
set_compression_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::load_from_config(const char *filename) {
|
void BmpBlockUtil::load_from_config(const char *filename) {
|
||||||
load_yaml_config(filename);
|
load_yaml_config(filename);
|
||||||
fill_bmpblock_header();
|
fill_bmpblock_header();
|
||||||
load_all_image_files();
|
load_all_image_files();
|
||||||
fill_all_image_infos();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void BmpBlockUtil::load_yaml_config(const char *filename) {
|
void BmpBlockUtil::load_yaml_config(const char *filename) {
|
||||||
yaml_parser_t parser;
|
yaml_parser_t parser;
|
||||||
|
|
||||||
config_.config_filename = filename;
|
config_.config_filename = filename;
|
||||||
@@ -108,9 +106,47 @@ void BmpBlockUtil::load_yaml_config(const char *filename) {
|
|||||||
parse_config(&parser);
|
parse_config(&parser);
|
||||||
yaml_parser_delete(&parser);
|
yaml_parser_delete(&parser);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
|
||||||
|
|
||||||
void BmpBlockUtil::expect_event(yaml_parser_t *parser,
|
|
||||||
|
// HEY: Check the yaml file for self-consistency now. 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.
|
||||||
|
|
||||||
|
if (debug_) {
|
||||||
|
printf("%ld 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("%ld 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\n",
|
||||||
|
it->first.c_str(),
|
||||||
|
it->second.filename.c_str(),
|
||||||
|
it->second.offset,
|
||||||
|
it->second.data.tag);
|
||||||
|
}
|
||||||
|
printf("%ld 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) {
|
const yaml_event_type_e type) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
yaml_parser_parse(parser, &event);
|
yaml_parser_parse(parser, &event);
|
||||||
@@ -118,17 +154,17 @@ void BmpBlockUtil::expect_event(yaml_parser_t *parser,
|
|||||||
error("Syntax error.\n");
|
error("Syntax error.\n");
|
||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_config(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_config(yaml_parser_t *parser) {
|
||||||
expect_event(parser, YAML_STREAM_START_EVENT);
|
expect_event(parser, YAML_STREAM_START_EVENT);
|
||||||
expect_event(parser, YAML_DOCUMENT_START_EVENT);
|
expect_event(parser, YAML_DOCUMENT_START_EVENT);
|
||||||
parse_first_layer(parser);
|
parse_first_layer(parser);
|
||||||
expect_event(parser, YAML_DOCUMENT_END_EVENT);
|
expect_event(parser, YAML_DOCUMENT_END_EVENT);
|
||||||
expect_event(parser, YAML_STREAM_END_EVENT);
|
expect_event(parser, YAML_STREAM_END_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_first_layer(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_first_layer(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
string keyword;
|
string keyword;
|
||||||
expect_event(parser, YAML_MAPPING_START_EVENT);
|
expect_event(parser, YAML_MAPPING_START_EVENT);
|
||||||
@@ -157,26 +193,28 @@ void BmpBlockUtil::parse_first_layer(yaml_parser_t *parser) {
|
|||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_bmpblock(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_bmpblock(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
yaml_parser_parse(parser, &event);
|
yaml_parser_parse(parser, &event);
|
||||||
if (event.type != YAML_SCALAR_EVENT) {
|
if (event.type != YAML_SCALAR_EVENT) {
|
||||||
error("Syntax error in parsing bmpblock.\n");
|
error("Syntax error in parsing bmpblock.\n");
|
||||||
}
|
}
|
||||||
char wantversion[20];
|
|
||||||
sprintf(wantversion, "%d.%d",
|
|
||||||
BMPBLOCK_MAJOR_VERSION,
|
|
||||||
BMPBLOCK_MINOR_VERSION);
|
|
||||||
string gotversion = (char*)event.data.scalar.value;
|
string gotversion = (char*)event.data.scalar.value;
|
||||||
if (gotversion != wantversion) {
|
if (gotversion == "1.1") {
|
||||||
error("Invalid version specified in config file\n");
|
render_hwid_ = true;
|
||||||
|
} else if (gotversion == "1.0") {
|
||||||
|
minor_version_ = 0;
|
||||||
|
render_hwid_ = false;
|
||||||
|
} else {
|
||||||
|
error("Unsupported version specified in config file (%s)\n",
|
||||||
|
gotversion.c_str());
|
||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_compression(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_compression(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
yaml_parser_parse(parser, &event);
|
yaml_parser_parse(parser, &event);
|
||||||
if (event.type != YAML_SCALAR_EVENT) {
|
if (event.type != YAML_SCALAR_EVENT) {
|
||||||
@@ -186,15 +224,15 @@ void BmpBlockUtil::parse_compression(yaml_parser_t *parser) {
|
|||||||
char *e = 0;
|
char *e = 0;
|
||||||
uint32_t comp = (uint32_t)strtoul(comp_str, &e, 0);
|
uint32_t comp = (uint32_t)strtoul(comp_str, &e, 0);
|
||||||
if (!*comp_str || (e && *e) || comp >= MAX_COMPRESS) {
|
if (!*comp_str || (e && *e) || comp >= MAX_COMPRESS) {
|
||||||
error("Invalid compression specified in config file\n");
|
error("Invalid compression specified in config file (%d)\n", comp);
|
||||||
}
|
}
|
||||||
if (!set_compression_) {
|
if (!set_compression_) {
|
||||||
compression_ = comp;
|
compression_ = comp;
|
||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_images(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_images(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
string image_name, image_filename;
|
string image_name, image_filename;
|
||||||
expect_event(parser, YAML_MAPPING_START_EVENT);
|
expect_event(parser, YAML_MAPPING_START_EVENT);
|
||||||
@@ -221,11 +259,10 @@ void BmpBlockUtil::parse_images(yaml_parser_t *parser) {
|
|||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
|
void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
string screen_name;
|
|
||||||
int depth = 0, index1 = 0, index2 = 0;
|
int depth = 0, index1 = 0, index2 = 0;
|
||||||
expect_event(parser, YAML_SEQUENCE_START_EVENT);
|
expect_event(parser, YAML_SEQUENCE_START_EVENT);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -244,9 +281,23 @@ void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
screen.image_names[index1] = (char*)event.data.scalar.value;
|
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 shouldn't
|
||||||
|
// exist in the list of images, but we will still need an
|
||||||
|
// ImageInfo struct to remember where to draw the text.
|
||||||
|
// Note that if the image name DOES exist, we still will won't
|
||||||
|
// display it (yet). Future versions may use that image to hold the
|
||||||
|
// font glpyhs, which is why we pass it around now.
|
||||||
|
if (render_hwid_) {
|
||||||
|
if (screen.image_names[index1] == RENDER_HWID) {
|
||||||
|
config_.images_map[RENDER_HWID].data.tag = TAG_HWID;
|
||||||
|
} else if (screen.image_names[index1] == RENDER_HWID_RTOL) {
|
||||||
|
config_.images_map[RENDER_HWID_RTOL].data.tag = TAG_HWID_RTOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Syntax error in parsing layout.\n");
|
error("Syntax error in parsing layout\n");
|
||||||
}
|
}
|
||||||
index2++;
|
index2++;
|
||||||
break;
|
break;
|
||||||
@@ -265,9 +316,9 @@ void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
|
|||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_screens(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_screens(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
string screen_name;
|
string screen_name;
|
||||||
expect_event(parser, YAML_MAPPING_START_EVENT);
|
expect_event(parser, YAML_MAPPING_START_EVENT);
|
||||||
@@ -287,9 +338,9 @@ void BmpBlockUtil::parse_screens(yaml_parser_t *parser) {
|
|||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::parse_localizations(yaml_parser_t *parser) {
|
void BmpBlockUtil::parse_localizations(yaml_parser_t *parser) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
int depth = 0, index = 0;
|
int depth = 0, index = 0;
|
||||||
expect_event(parser, YAML_SEQUENCE_START_EVENT);
|
expect_event(parser, YAML_SEQUENCE_START_EVENT);
|
||||||
@@ -317,15 +368,29 @@ void BmpBlockUtil::parse_localizations(yaml_parser_t *parser) {
|
|||||||
}
|
}
|
||||||
yaml_event_delete(&event);
|
yaml_event_delete(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::load_all_image_files() {
|
void BmpBlockUtil::load_all_image_files() {
|
||||||
for (StrImageConfigMap::iterator it = config_.images_map.begin();
|
for (unsigned int i = 0; i < config_.image_names.size(); i++) {
|
||||||
it != config_.images_map.end();
|
StrImageConfigMap::iterator it =
|
||||||
++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());
|
const string &content = read_image_file(it->second.filename.c_str());
|
||||||
it->second.raw_content = content;
|
it->second.raw_content = content;
|
||||||
it->second.data.original_size = content.size();
|
it->second.data.original_size = content.size();
|
||||||
|
it->second.data.format = get_image_format(content);
|
||||||
|
switch (it->second.data.format) {
|
||||||
|
case FORMAT_BMP:
|
||||||
|
it->second.data.width = get_bmp_image_width(it->second.raw_content);
|
||||||
|
it->second.data.height = get_bmp_image_height(it->second.raw_content);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("Unsupported image format in %s\n", it->second.filename.c_str());
|
||||||
|
}
|
||||||
switch(compression_) {
|
switch(compression_) {
|
||||||
case COMPRESS_NONE:
|
case COMPRESS_NONE:
|
||||||
it->second.data.compression = compression_;
|
it->second.data.compression = compression_;
|
||||||
@@ -384,9 +449,9 @@ void BmpBlockUtil::load_all_image_files() {
|
|||||||
error("Unsupported compression method attempted.\n");
|
error("Unsupported compression method attempted.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const string BmpBlockUtil::read_image_file(const char *filename) {
|
const string BmpBlockUtil::read_image_file(const char *filename) {
|
||||||
string content;
|
string content;
|
||||||
vector<char> buffer;
|
vector<char> buffer;
|
||||||
|
|
||||||
@@ -412,9 +477,9 @@ const string BmpBlockUtil::read_image_file(const char *filename) {
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageFormat BmpBlockUtil::get_image_format(const string content) {
|
ImageFormat BmpBlockUtil::get_image_format(const string content) {
|
||||||
if (content.size() < sizeof(BMP_IMAGE_HEADER))
|
if (content.size() < sizeof(BMP_IMAGE_HEADER))
|
||||||
return FORMAT_INVALID;
|
return FORMAT_INVALID;
|
||||||
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
||||||
@@ -427,83 +492,53 @@ ImageFormat BmpBlockUtil::get_image_format(const string content) {
|
|||||||
return FORMAT_INVALID;
|
return FORMAT_INVALID;
|
||||||
|
|
||||||
return FORMAT_BMP;
|
return FORMAT_BMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BmpBlockUtil::get_bmp_image_width(const string content) {
|
uint32_t BmpBlockUtil::get_bmp_image_width(const string content) {
|
||||||
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
||||||
return hdr->PixelWidth;
|
return hdr->PixelWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BmpBlockUtil::get_bmp_image_height(const string content) {
|
uint32_t BmpBlockUtil::get_bmp_image_height(const string content) {
|
||||||
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
|
||||||
return hdr->PixelHeight;
|
return hdr->PixelHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::fill_all_image_infos() {
|
void BmpBlockUtil::fill_bmpblock_header() {
|
||||||
int errcnt = 0;
|
|
||||||
for (StrImageConfigMap::iterator it = config_.images_map.begin();
|
|
||||||
it != config_.images_map.end();
|
|
||||||
++it) {
|
|
||||||
it->second.data.format = (uint32_t)get_image_format(it->second.raw_content);
|
|
||||||
switch (it->second.data.format) {
|
|
||||||
case FORMAT_BMP:
|
|
||||||
it->second.data.width = get_bmp_image_width(it->second.raw_content);
|
|
||||||
it->second.data.height = get_bmp_image_height(it->second.raw_content);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "Unsupported image format in %s\n",
|
|
||||||
it->second.filename.c_str());
|
|
||||||
errcnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (errcnt)
|
|
||||||
error("Unable to continue due to errors.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BmpBlockUtil::compress_all_images(const Compression compress) {
|
|
||||||
switch (compress) {
|
|
||||||
case COMPRESS_NONE:
|
|
||||||
for (StrImageConfigMap::iterator it = config_.images_map.begin();
|
|
||||||
it != config_.images_map.end();
|
|
||||||
++it) {
|
|
||||||
it->second.data.compression = compress;
|
|
||||||
it->second.compressed_content = it->second.raw_content;
|
|
||||||
it->second.data.compressed_size = it->second.compressed_content.size();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error("Unsupported data compression.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BmpBlockUtil::fill_bmpblock_header() {
|
|
||||||
memset(&config_.header, '\0', sizeof(config_.header));
|
memset(&config_.header, '\0', sizeof(config_.header));
|
||||||
memcpy(&config_.header.signature, BMPBLOCK_SIGNATURE,
|
memcpy(&config_.header.signature, BMPBLOCK_SIGNATURE,
|
||||||
BMPBLOCK_SIGNATURE_SIZE);
|
BMPBLOCK_SIGNATURE_SIZE);
|
||||||
config_.header.major_version = BMPBLOCK_MAJOR_VERSION;
|
config_.header.major_version = major_version_;
|
||||||
config_.header.minor_version = BMPBLOCK_MINOR_VERSION;
|
config_.header.minor_version = minor_version_;
|
||||||
config_.header.number_of_localizations = config_.localizations.size();
|
config_.header.number_of_localizations = config_.localizations.size();
|
||||||
config_.header.number_of_screenlayouts = config_.localizations[0].size();
|
config_.header.number_of_screenlayouts = config_.localizations[0].size();
|
||||||
|
// HEY: this is part of the yaml consistency check
|
||||||
for (unsigned int i = 1; i < config_.localizations.size(); ++i) {
|
for (unsigned int i = 1; i < config_.localizations.size(); ++i) {
|
||||||
assert(config_.header.number_of_screenlayouts ==
|
assert(config_.header.number_of_screenlayouts ==
|
||||||
config_.localizations[i].size());
|
config_.localizations[i].size());
|
||||||
}
|
}
|
||||||
config_.header.number_of_imageinfos = config_.images_map.size();
|
config_.header.number_of_imageinfos = config_.images_map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::pack_bmpblock() {
|
void BmpBlockUtil::pack_bmpblock() {
|
||||||
bmpblock_.clear();
|
bmpblock_.clear();
|
||||||
|
|
||||||
/* Compute the ImageInfo offsets from start of BMPBLOCK. */
|
/* Compute the ImageInfo offsets from start of BMPBLOCK. */
|
||||||
uint32_t current_offset = sizeof(BmpBlockHeader) +
|
uint32_t current_offset = sizeof(BmpBlockHeader) +
|
||||||
sizeof(ScreenLayout) * (config_.header.number_of_localizations *
|
sizeof(ScreenLayout) * (config_.header.number_of_localizations *
|
||||||
config_.header.number_of_screenlayouts);
|
config_.header.number_of_screenlayouts);
|
||||||
for (unsigned int i = 0; i < config_.image_names.size(); ++i) {
|
for (StrImageConfigMap::iterator it = config_.images_map.begin();
|
||||||
string image_name = config_.image_names[i];
|
it != config_.images_map.end();
|
||||||
ImageConfig &img = config_.images_map[image_name];
|
++it) {
|
||||||
img.offset = current_offset;
|
it->second.offset = current_offset;
|
||||||
|
if (debug_)
|
||||||
|
printf(" \"%s\": filename=\"%s\" offset=0x%x tag=%d\n",
|
||||||
|
it->first.c_str(),
|
||||||
|
it->second.filename.c_str(),
|
||||||
|
it->second.offset,
|
||||||
|
it->second.data.tag);
|
||||||
current_offset += sizeof(ImageInfo) +
|
current_offset += sizeof(ImageInfo) +
|
||||||
config_.images_map[image_name].data.compressed_size;
|
it->second.data.compressed_size;
|
||||||
/* Make it 4-byte aligned. */
|
/* Make it 4-byte aligned. */
|
||||||
if ((current_offset & 3) > 0) {
|
if ((current_offset & 3) > 0) {
|
||||||
current_offset = (current_offset & ~3) + 4;
|
current_offset = (current_offset & ~3) + 4;
|
||||||
@@ -517,6 +552,7 @@ void BmpBlockUtil::pack_bmpblock() {
|
|||||||
reinterpret_cast<char*>(&config_.header + 1),
|
reinterpret_cast<char*>(&config_.header + 1),
|
||||||
current_filled);
|
current_filled);
|
||||||
current_filled += sizeof(config_.header);
|
current_filled += sizeof(config_.header);
|
||||||
|
current_offset = sizeof(config_.header);
|
||||||
|
|
||||||
/* Fill all ScreenLayout structs. */
|
/* Fill all ScreenLayout structs. */
|
||||||
for (unsigned int i = 0; i < config_.localizations.size(); ++i) {
|
for (unsigned int i = 0; i < config_.localizations.size(); ++i) {
|
||||||
@@ -525,6 +561,16 @@ void BmpBlockUtil::pack_bmpblock() {
|
|||||||
for (unsigned int k = 0;
|
for (unsigned int k = 0;
|
||||||
k < MAX_IMAGE_IN_LAYOUT && !screen.image_names[k].empty();
|
k < MAX_IMAGE_IN_LAYOUT && !screen.image_names[k].empty();
|
||||||
++k) {
|
++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 =
|
screen.data.images[k].image_info_offset =
|
||||||
config_.images_map[screen.image_names[k]].offset;
|
config_.images_map[screen.image_names[k]].offset;
|
||||||
}
|
}
|
||||||
@@ -532,6 +578,9 @@ void BmpBlockUtil::pack_bmpblock() {
|
|||||||
reinterpret_cast<char*>(&screen.data + 1),
|
reinterpret_cast<char*>(&screen.data + 1),
|
||||||
current_filled);
|
current_filled);
|
||||||
current_filled += sizeof(screen.data);
|
current_filled += sizeof(screen.data);
|
||||||
|
if (debug_)
|
||||||
|
printf("S: current offset is 0x%08x\n", current_offset);
|
||||||
|
current_offset += sizeof(screen.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,17 +589,24 @@ void BmpBlockUtil::pack_bmpblock() {
|
|||||||
it != config_.images_map.end();
|
it != config_.images_map.end();
|
||||||
++it) {
|
++it) {
|
||||||
current_filled = bmpblock_.begin() + it->second.offset;
|
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),
|
std::copy(reinterpret_cast<char*>(&it->second.data),
|
||||||
reinterpret_cast<char*>(&it->second.data + 1),
|
reinterpret_cast<char*>(&it->second.data + 1),
|
||||||
current_filled);
|
current_filled);
|
||||||
current_filled += sizeof(it->second.data);
|
current_filled += sizeof(it->second.data);
|
||||||
|
current_offset += sizeof(it->second.data);
|
||||||
|
if (debug_)
|
||||||
|
printf("I1: current offset is 0x%08x (len %ld)\n",
|
||||||
|
current_offset, it->second.compressed_content.length());
|
||||||
std::copy(it->second.compressed_content.begin(),
|
std::copy(it->second.compressed_content.begin(),
|
||||||
it->second.compressed_content.end(),
|
it->second.compressed_content.end(),
|
||||||
current_filled);
|
current_filled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BmpBlockUtil::write_to_bmpblock(const char *filename) {
|
void BmpBlockUtil::write_to_bmpblock(const char *filename) {
|
||||||
assert(!bmpblock_.empty());
|
assert(!bmpblock_.empty());
|
||||||
|
|
||||||
FILE *fp = fopen(filename, "wb");
|
FILE *fp = fopen(filename, "wb");
|
||||||
@@ -565,23 +621,23 @@ void BmpBlockUtil::write_to_bmpblock(const char *filename) {
|
|||||||
perror(filename);
|
perror(filename);
|
||||||
exit(errno);
|
exit(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace vboot_reference
|
} // namespace vboot_reference
|
||||||
|
|
||||||
#ifdef WITH_UTIL_MAIN
|
#ifdef WITH_UTIL_MAIN
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// Command line utilities.
|
// Command line utilities.
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "bmpblk_util.h"
|
#include "bmpblk_util.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
using vboot_reference::BmpBlockUtil;
|
using vboot_reference::BmpBlockUtil;
|
||||||
|
|
||||||
// utility function: provide usage of this utility and exit.
|
// utility function: provide usage of this utility and exit.
|
||||||
static void usagehelp_exit(const char *prog_name) {
|
static void usagehelp_exit(const char *prog_name) {
|
||||||
printf(
|
printf(
|
||||||
"\n"
|
"\n"
|
||||||
"To create a new BMPBLOCK file using config from YAML file:\n"
|
"To create a new BMPBLOCK file using config from YAML file:\n"
|
||||||
@@ -609,12 +665,12 @@ static void usagehelp_exit(const char *prog_name) {
|
|||||||
" -f = force overwriting existing files\n"
|
" -f = force overwriting existing files\n"
|
||||||
"\n", prog_name);
|
"\n", prog_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// main
|
// main
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
const char *prog_name = strrchr(argv[0], '/');
|
const char *prog_name = strrchr(argv[0], '/');
|
||||||
if (prog_name)
|
if (prog_name)
|
||||||
@@ -627,12 +683,13 @@ int main(int argc, char *argv[]) {
|
|||||||
int set_compression = 0;
|
int set_compression = 0;
|
||||||
const char *config_fn = 0, *bmpblock_fn = 0, *extract_dir = ".";
|
const char *config_fn = 0, *bmpblock_fn = 0, *extract_dir = ".";
|
||||||
int show_as_yaml = 0;
|
int show_as_yaml = 0;
|
||||||
|
bool debug = false;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
opterr = 0; // quiet
|
opterr = 0; // quiet
|
||||||
int errorcnt = 0;
|
int errorcnt = 0;
|
||||||
char *e = 0;
|
char *e = 0;
|
||||||
while ((opt = getopt(argc, argv, ":c:xz:fd:y")) != -1) {
|
while ((opt = getopt(argc, argv, ":c:xz:fd:yD")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
config_fn = optarg;
|
config_fn = optarg;
|
||||||
@@ -663,6 +720,9 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'd':
|
case 'd':
|
||||||
extract_dir= optarg;
|
extract_dir= optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
debug = true;
|
||||||
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
fprintf(stderr, "%s: missing argument to -%c\n",
|
fprintf(stderr, "%s: missing argument to -%c\n",
|
||||||
prog_name, optopt);
|
prog_name, optopt);
|
||||||
@@ -688,7 +748,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if (errorcnt)
|
if (errorcnt)
|
||||||
usagehelp_exit(prog_name);
|
usagehelp_exit(prog_name);
|
||||||
|
|
||||||
BmpBlockUtil util;
|
BmpBlockUtil util(debug);
|
||||||
|
|
||||||
if (config_fn) {
|
if (config_fn) {
|
||||||
if (set_compression)
|
if (set_compression)
|
||||||
@@ -705,6 +765,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // WITH_UTIL_MAIN
|
#endif // WITH_UTIL_MAIN
|
||||||
|
|||||||
@@ -50,15 +50,12 @@ typedef struct BmpBlockConfig {
|
|||||||
|
|
||||||
class BmpBlockUtil {
|
class BmpBlockUtil {
|
||||||
public:
|
public:
|
||||||
BmpBlockUtil();
|
BmpBlockUtil(bool debug);
|
||||||
~BmpBlockUtil();
|
~BmpBlockUtil();
|
||||||
|
|
||||||
/* Load all the images and related infomations according to a config file. */
|
/* Load all the images and related infomations according to a config file. */
|
||||||
void load_from_config(const char *filename);
|
void load_from_config(const char *filename);
|
||||||
|
|
||||||
/* Compress all the images using a given comression method. */
|
|
||||||
void compress_all_images(const Compression compress);
|
|
||||||
|
|
||||||
/* Contruct the bmpblock. */
|
/* Contruct the bmpblock. */
|
||||||
void pack_bmpblock();
|
void pack_bmpblock();
|
||||||
|
|
||||||
@@ -69,9 +66,6 @@ class BmpBlockUtil {
|
|||||||
void force_compression(uint32_t compression);
|
void force_compression(uint32_t compression);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Clear all internal data. */
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
/* Elemental function called from load_from_config.
|
/* Elemental function called from load_from_config.
|
||||||
* Load the config file (yaml format) and parse it. */
|
* Load the config file (yaml format) and parse it. */
|
||||||
void load_yaml_config(const char *filename);
|
void load_yaml_config(const char *filename);
|
||||||
@@ -80,10 +74,6 @@ class BmpBlockUtil {
|
|||||||
* Load all image files into the internal variables. */
|
* Load all image files into the internal variables. */
|
||||||
void load_all_image_files();
|
void load_all_image_files();
|
||||||
|
|
||||||
/* Elemental function called from load_from_config.
|
|
||||||
* Contruct all ImageInfo structs. */
|
|
||||||
void fill_all_image_infos();
|
|
||||||
|
|
||||||
/* Elemental function called from load_from_config.
|
/* Elemental function called from load_from_config.
|
||||||
* Contruct the BmpBlockHeader struct. */
|
* Contruct the BmpBlockHeader struct. */
|
||||||
void fill_bmpblock_header();
|
void fill_bmpblock_header();
|
||||||
@@ -105,6 +95,16 @@ class BmpBlockUtil {
|
|||||||
uint32_t get_bmp_image_width(const string content);
|
uint32_t get_bmp_image_width(const string content);
|
||||||
uint32_t get_bmp_image_height(const string content);
|
uint32_t get_bmp_image_height(const string content);
|
||||||
|
|
||||||
|
/* 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_;
|
||||||
|
|
||||||
/* Internal variable for storing the config of BmpBlock. */
|
/* Internal variable for storing the config of BmpBlock. */
|
||||||
BmpBlockConfig config_;
|
BmpBlockConfig config_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user