diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2016-08-10 16:36:24 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-05-07 17:23:01 -0700 |
commit | ad546b47f698ef1bd4ec26cbd157334f61b50958 (patch) | |
tree | 38c8782412dbfbef29fcaa879ea061b60a7fdd4e /utility | |
parent | dde7e4c51831d542a52f166fa3fa2634b5b9b615 (diff) | |
download | vboot-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>
Diffstat (limited to 'utility')
-rw-r--r-- | utility/bmpblk_font.c | 229 | ||||
-rw-r--r-- | utility/bmpblk_util.c | 455 | ||||
-rw-r--r-- | utility/bmpblk_utility.cc | 777 | ||||
-rw-r--r-- | utility/image_types.c | 71 | ||||
-rw-r--r-- | utility/include/bmpblk_util.h | 13 | ||||
-rw-r--r-- | utility/include/bmpblk_utility.h | 125 | ||||
-rw-r--r-- | utility/include/image_types.h | 25 |
7 files changed, 0 insertions, 1695 deletions
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_ */ - |