summaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2011-05-05 15:12:10 -0700
committerBill Richardson <wfrichar@chromium.org>2011-05-05 15:31:31 -0700
commit54e95825b30d4f730cbd70c109fb6622dda6fbb8 (patch)
tree30f12b2296bf16299ceef047cf9cde6332c2bba1 /utility
parentc3574086a82d04b3584712f7e15a8eb4ea6d40a0 (diff)
downloadvboot-54e95825b30d4f730cbd70c109fb6622dda6fbb8.tar.gz
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>
Diffstat (limited to 'utility')
-rw-r--r--utility/bmpblk_util.c143
-rw-r--r--utility/bmpblk_utility.cc936
-rw-r--r--utility/include/bmpblk_utility.h22
3 files changed, 594 insertions, 507 deletions
diff --git a/utility/bmpblk_util.c b/utility/bmpblk_util.c
index 5c94d8e9..2dd63e8c 100644
--- a/utility/bmpblk_util.c
+++ b/utility/bmpblk_util.c
@@ -282,74 +282,89 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
fprintf(yfp, "images:\n");
for(i=0; i<hdr->number_of_imageinfos; i++) {
img = (ImageInfo *)(ptr + offset);
- sprintf(image_name, "img_%08x.bmp", offset);
- fprintf(yfp, " img_%08x: %s # %dx%d %d/%d\n", offset, image_name,
- img->width, img->height,
- img->compressed_size, img->original_size);
- 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;
+ 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\n",
+ RENDER_HWID, image_name,
+ img->width, img->height,
+ 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);
}
- 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) {
+ 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;
}
- free_data = 1;
- break;
- case COMPRESS_LZMA1:
- data_ptr = do_lzma_decompress(img);
- if (!data_ptr) {
+ 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;
}
- 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;
+ if (free_data)
+ free(data_ptr);
}
- fclose(bfp);
- if (free_data)
- free(data_ptr);
}
offset += sizeof(ImageInfo);
offset += img->compressed_size;
@@ -370,9 +385,21 @@ int dump_bmpblock(const char *infile, int show_as_yaml,
scr = (ScreenLayout *)(ptr + offset);
for(i=0; i<MAX_IMAGE_IN_LAYOUT; i++) {
if (scr->images[i].image_info_offset) {
- fprintf(yfp, " - [%d, %d, img_%08x]\n",
- scr->images[i].x, scr->images[i].y,
- 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",
+ scr->images[i].x, scr->images[i].y,
+ scr->images[i].image_info_offset);
+ }
}
}
}
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc
index 078a5ceb..3cc31ad2 100644
--- a/utility/bmpblk_utility.cc
+++ b/utility/bmpblk_utility.cc
@@ -59,82 +59,118 @@ static void error(const char *format, ...) {
namespace vboot_reference {
-BmpBlockUtil::BmpBlockUtil() {
- initialize();
-}
+ 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;
+ }
-BmpBlockUtil::~BmpBlockUtil() {
-}
+ BmpBlockUtil::~BmpBlockUtil() {
+ }
-void BmpBlockUtil::initialize() {
- 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;
-}
+ void BmpBlockUtil::force_compression(uint32_t compression) {
+ compression_ = compression;
+ set_compression_ = true;
+ }
-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_from_config(const char *filename) {
- load_yaml_config(filename);
- fill_bmpblock_header();
- load_all_image_files();
- fill_all_image_infos();
-}
+ void BmpBlockUtil::load_yaml_config(const char *filename) {
+ yaml_parser_t parser;
-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_.config_filename = filename;
- config_.images_map.clear();
- config_.screens_map.clear();
- config_.localizations.clear();
+ FILE *fp = fopen(filename, "rb");
+ if (!fp) {
+ perror(filename);
+ exit(errno);
+ }
- 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);
- yaml_parser_initialize(&parser);
- yaml_parser_set_input_file(&parser, fp);
- parse_config(&parser);
- yaml_parser_delete(&parser);
- fclose(fp);
-}
-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);
-}
+ // 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.
-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);
-}
+ 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::parse_first_layer(yaml_parser_t *parser) {
- yaml_event_t event;
- string keyword;
- expect_event(parser, YAML_MAPPING_START_EVENT);
- for (;;) {
+ void BmpBlockUtil::expect_event(yaml_parser_t *parser,
+ const yaml_event_type_e type) {
+ yaml_event_t event;
yaml_parser_parse(parser, &event);
- switch (event.type) {
+ 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") {
@@ -154,53 +190,55 @@ void BmpBlockUtil::parse_first_layer(yaml_parser_t *parser) {
return;
default:
error("Syntax error in parsing config file.\n");
+ }
+ yaml_event_delete(&event);
}
- 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");
- }
- char wantversion[20];
- sprintf(wantversion, "%d.%d",
- BMPBLOCK_MAJOR_VERSION,
- BMPBLOCK_MINOR_VERSION);
- string gotversion = (char*)event.data.scalar.value;
- if (gotversion != wantversion) {
- error("Invalid version specified in config file\n");
+ 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 == "1.1") {
+ 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) {
- 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\n");
- }
- if (!set_compression_) {
- compression_ = comp;
+ 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);
}
- 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) {
+ 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);
@@ -218,35 +256,48 @@ void BmpBlockUtil::parse_images(yaml_parser_t *parser) {
return;
default:
error("Syntax error in parsing images.\n");
+ }
+ yaml_event_delete(&event);
}
- yaml_event_delete(&event);
}
-}
-void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
- yaml_event_t event;
- string screen_name;
- int depth = 0, index1 = 0, index2 = 0;
- expect_event(parser, YAML_SEQUENCE_START_EVENT);
- for (;;) {
- yaml_parser_parse(parser, &event);
- switch (event.type) {
+ 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;
- break;
- default:
- error("Syntax error in parsing layout.\n");
+ 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 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;
+ default:
+ error("Syntax error in parsing layout\n");
}
index2++;
break;
@@ -262,18 +313,18 @@ void BmpBlockUtil::parse_layout(yaml_parser_t *parser, ScreenConfig &screen) {
break;
default:
error("Syntax error in paring layout.\n");
+ }
+ yaml_event_delete(&event);
}
- 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) {
+ 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();
@@ -284,18 +335,18 @@ void BmpBlockUtil::parse_screens(yaml_parser_t *parser) {
return;
default:
error("Syntax error in parsing screens.\n");
+ }
+ yaml_event_delete(&event);
}
- 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) {
+ 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++;
@@ -314,25 +365,39 @@ void BmpBlockUtil::parse_localizations(yaml_parser_t *parser) {
break;
default:
error("Syntax error in parsing localizations.\n");
+ }
+ yaml_event_delete(&event);
}
- yaml_event_delete(&event);
}
-}
-void BmpBlockUtil::load_all_image_files() {
- for (StrImageConfigMap::iterator it = config_.images_map.begin();
- it != config_.images_map.end();
- ++it) {
- const string &content = read_image_file(it->second.filename.c_str());
- it->second.raw_content = content;
- it->second.data.original_size = content.size();
- 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:
+ 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 = 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_) {
+ 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();
@@ -348,7 +413,7 @@ void BmpBlockUtil::load_all_image_files() {
free(tmpbuf);
}
break;
- case COMPRESS_LZMA1:
+ case COMPRESS_LZMA1:
{
// Calculate the worst case of buffer size.
uint32_t tmpsize = lzma_stream_buffer_bound(content.size());
@@ -380,331 +445,326 @@ void BmpBlockUtil::load_all_image_files() {
free(tmpbuf);
}
break;
- default:
- error("Unsupported compression method attempted.\n");
+ 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);
- }
+ const string BmpBlockUtil::read_image_file(const char *filename) {
+ string content;
+ vector<char> buffer;
- if (!buffer.empty()) {
- if(fread(&buffer[0], buffer.size(), 1, fp) != 1) {
+ FILE *fp = fopen(filename, "rb");
+ if (!fp) {
perror(filename);
- buffer.clear();
- } else {
- content.assign(buffer.begin(), buffer.end());
+ exit(errno);
}
- }
- fclose(fp);
- return content;
-}
-
-ImageFormat BmpBlockUtil::get_image_format(const string content) {
- if (content.size() < sizeof(BMP_IMAGE_HEADER))
- return FORMAT_INVALID;
- const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
+ if (fseek(fp, 0, SEEK_END) == 0) {
+ buffer.resize(ftell(fp));
+ rewind(fp);
+ }
- if (hdr->CharB != 'B' || hdr->CharM != 'M' ||
- hdr->Planes != 1 ||
- (hdr->CompressionType != 0 && hdr->CompressionType != 1) ||
- (hdr->BitPerPixel != 1 && hdr->BitPerPixel != 4 &&
- hdr->BitPerPixel != 8 && hdr->BitPerPixel != 24))
- return FORMAT_INVALID;
+ if (!buffer.empty()) {
+ if(fread(&buffer[0], buffer.size(), 1, fp) != 1) {
+ perror(filename);
+ buffer.clear();
+ } else {
+ content.assign(buffer.begin(), buffer.end());
+ }
+ }
- return FORMAT_BMP;
-}
+ fclose(fp);
+ return content;
+ }
-uint32_t BmpBlockUtil::get_bmp_image_width(const string content) {
- const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
- return hdr->PixelWidth;
-}
+ ImageFormat BmpBlockUtil::get_image_format(const string content) {
+ if (content.size() < sizeof(BMP_IMAGE_HEADER))
+ return FORMAT_INVALID;
+ const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
-uint32_t BmpBlockUtil::get_bmp_image_height(const string content) {
- const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
- return hdr->PixelHeight;
-}
+ if (hdr->CharB != 'B' || hdr->CharM != 'M' ||
+ hdr->Planes != 1 ||
+ (hdr->CompressionType != 0 && hdr->CompressionType != 1) ||
+ (hdr->BitPerPixel != 1 && hdr->BitPerPixel != 4 &&
+ hdr->BitPerPixel != 8 && hdr->BitPerPixel != 24))
+ return FORMAT_INVALID;
-void BmpBlockUtil::fill_all_image_infos() {
- 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++;
- }
+ return FORMAT_BMP;
}
- 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");
+ uint32_t BmpBlockUtil::get_bmp_image_width(const string content) {
+ const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
+ return hdr->PixelWidth;
}
-}
-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 = BMPBLOCK_MAJOR_VERSION;
- config_.header.minor_version = BMPBLOCK_MINOR_VERSION;
- config_.header.number_of_localizations = config_.localizations.size();
- config_.header.number_of_screenlayouts = config_.localizations[0].size();
- for (unsigned int i = 1; i < config_.localizations.size(); ++i) {
- assert(config_.header.number_of_screenlayouts ==
- config_.localizations[i].size());
+ uint32_t BmpBlockUtil::get_bmp_image_height(const string content) {
+ const BMP_IMAGE_HEADER *hdr = (const BMP_IMAGE_HEADER *)content.c_str();
+ return hdr->PixelHeight;
}
- config_.header.number_of_imageinfos = config_.images_map.size();
-}
-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 (unsigned int i = 0; i < config_.image_names.size(); ++i) {
- string image_name = config_.image_names[i];
- ImageConfig &img = config_.images_map[image_name];
- img.offset = current_offset;
- current_offset += sizeof(ImageInfo) +
- config_.images_map[image_name].data.compressed_size;
- /* Make it 4-byte aligned. */
- if ((current_offset & 3) > 0) {
- current_offset = (current_offset & ~3) + 4;
+ 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();
+ // HEY: 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();
}
- 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);
-
- /* 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) {
- screen.data.images[k].image_info_offset =
- config_.images_map[screen.image_names[k]].offset;
+
+ 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\n",
+ it->first.c_str(),
+ it->second.filename.c_str(),
+ it->second.offset,
+ it->second.data.tag);
+ 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;
}
- std::copy(reinterpret_cast<char*>(&screen.data),
- reinterpret_cast<char*>(&screen.data + 1),
- current_filled);
- current_filled += sizeof(screen.data);
}
- }
+ bmpblock_.resize(current_offset);
- /* 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;
- std::copy(reinterpret_cast<char*>(&it->second.data),
- reinterpret_cast<char*>(&it->second.data + 1),
- current_filled);
- current_filled += sizeof(it->second.data);
- std::copy(it->second.compressed_content.begin(),
- it->second.compressed_content.end(),
+ /* 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 %ld)\n",
+ current_offset, it->second.compressed_content.length());
+ std::copy(it->second.compressed_content.begin(),
+ it->second.compressed_content.end(),
+ current_filled);
+ }
}
-}
-void BmpBlockUtil::write_to_bmpblock(const char *filename) {
- assert(!bmpblock_.empty());
+ void BmpBlockUtil::write_to_bmpblock(const char *filename) {
+ assert(!bmpblock_.empty());
- FILE *fp = fopen(filename, "wb");
- if (!fp) {
- perror(filename);
- exit(errno);
- }
+ 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);
+ int r = fwrite(bmpblock_.c_str(), bmpblock_.size(), 1, fp);
+ fclose(fp);
+ if (r != 1) {
+ perror(filename);
+ exit(errno);
+ }
}
-}
} // namespace vboot_reference
#ifdef WITH_UTIL_MAIN
-//////////////////////////////////////////////////////////////////////////////
-// Command line utilities.
+ //////////////////////////////////////////////////////////////////////////////
+ // Command line utilities.
-extern "C" {
+ 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);
-}
+ 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;
-
- int opt;
- opterr = 0; // quiet
- int errorcnt = 0;
- char *e = 0;
- while ((opt = getopt(argc, argv, ":c:xz:fd:y")) != -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);
+ ///////////////////////////////////////////////////////////////////////
+ // 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++;
- }
- if (compression >= MAX_COMPRESS) {
- fprintf(stderr, "%s: compression type must be less than %d\n",
- prog_name, MAX_COMPRESS);
+ break;
+ default:
+ fprintf(stderr, "%s: unrecognized switch: -%c\n",
+ prog_name, optopt);
errorcnt++;
+ break;
}
- set_compression = 1;
- break;
- case 'f':
- overwrite = 1;
- break;
- case 'd':
- extract_dir= optarg;
- 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);
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc >= 1) {
+ bmpblock_fn = argv[0];
+ } else {
+ fprintf(stderr, "%s: missing BMPBLOCK name\n", prog_name);
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);
+ if (errorcnt)
+ usagehelp_exit(prog_name);
- BmpBlockUtil util;
+ 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);
- }
+ 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);
- }
+ 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;
-}
+ return 0;
+ }
#endif // WITH_UTIL_MAIN
diff --git a/utility/include/bmpblk_utility.h b/utility/include/bmpblk_utility.h
index 9c708ba3..95e8ce35 100644
--- a/utility/include/bmpblk_utility.h
+++ b/utility/include/bmpblk_utility.h
@@ -50,15 +50,12 @@ typedef struct BmpBlockConfig {
class BmpBlockUtil {
public:
- BmpBlockUtil();
+ BmpBlockUtil(bool debug);
~BmpBlockUtil();
/* Load all the images and related infomations according to a config file. */
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. */
void pack_bmpblock();
@@ -69,9 +66,6 @@ class BmpBlockUtil {
void force_compression(uint32_t compression);
private:
- /* Clear all internal data. */
- void initialize();
-
/* Elemental function called from load_from_config.
* Load the config file (yaml format) and parse it. */
void load_yaml_config(const char *filename);
@@ -81,10 +75,6 @@ class BmpBlockUtil {
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.
* Contruct the BmpBlockHeader struct. */
void fill_bmpblock_header();
@@ -105,6 +95,16 @@ class BmpBlockUtil {
uint32_t get_bmp_image_width(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. */
BmpBlockConfig config_;