Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: utility/bmpblk_utility.cc

Issue 6523019: Enable LZMA compression in bmpbklk_utility. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Remove unnecessary code Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utility/bmpblk_util.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Utility for manipulating firmware screen block (BMPBLOCK) in GBB. 5 // Utility for manipulating firmware screen block (BMPBLOCK) in GBB.
6 // 6 //
7 7
8 #include "bmpblk_utility.h" 8 #include "bmpblk_utility.h"
9 9
10 #include <assert.h> 10 #include <assert.h>
11 #include <errno.h> 11 #include <errno.h>
12 #include <getopt.h> 12 #include <getopt.h>
13 #include <lzma.h>
13 #include <stdarg.h> 14 #include <stdarg.h>
14 #include <stdio.h> 15 #include <stdio.h>
15 #include <stdlib.h> 16 #include <stdlib.h>
16 #include <string.h> 17 #include <string.h>
17 #include <yaml.h> 18 #include <yaml.h>
18 19
19 extern "C" { 20 extern "C" {
20 #include "eficompress.h" 21 #include "eficompress.h"
21 } 22 }
22 23
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (EFI_SUCCESS != EfiCompress((uint8_t *)content.c_str(), tmpsize, 320 if (EFI_SUCCESS != EfiCompress((uint8_t *)content.c_str(), tmpsize,
320 tmpbuf, &tmpsize)) { 321 tmpbuf, &tmpsize)) {
321 error("Unable to compress!\n"); 322 error("Unable to compress!\n");
322 } 323 }
323 it->second.data.compression = compression_; 324 it->second.data.compression = compression_;
324 it->second.compressed_content.assign((const char *)tmpbuf, tmpsize); 325 it->second.compressed_content.assign((const char *)tmpbuf, tmpsize);
325 it->second.data.compressed_size = tmpsize; 326 it->second.data.compressed_size = tmpsize;
326 free(tmpbuf); 327 free(tmpbuf);
327 } 328 }
328 break; 329 break;
330 case COMPRESS_LZMA1:
331 {
332 // Calculate the worst case of buffer size.
333 uint32_t tmpsize = lzma_stream_buffer_bound(content.size());
334 uint8_t *tmpbuf = (uint8_t *)malloc(tmpsize);
335 lzma_stream stream = LZMA_STREAM_INIT;
336 lzma_options_lzma options;
337 lzma_ret result;
338
339 lzma_lzma_preset(&options, 9);
340 result = lzma_alone_encoder(&stream, &options);
341 if (result != LZMA_OK) {
342 error("Unable to initialize easy encoder (error: %d)!\n", result);
343 }
344
345 stream.next_in = (uint8_t *)content.data();
346 stream.avail_in = content.size();
347 stream.next_out = tmpbuf;
348 stream.avail_out = tmpsize;
349 result = lzma_code(&stream, LZMA_FINISH);
350 if (result != LZMA_STREAM_END) {
351 error("Unable to encode data (error: %d)!\n", result);
352 }
353
354 it->second.data.compression = compression_;
355 it->second.compressed_content.assign((const char *)tmpbuf,
356 tmpsize - stream.avail_out);
357 it->second.data.compressed_size = tmpsize - stream.avail_out;
358 lzma_end(&stream);
359 free(tmpbuf);
360 }
361 break;
329 default: 362 default:
330 error("Unsupported compression method attempted.\n"); 363 error("Unsupported compression method attempted.\n");
331 } 364 }
332 } 365 }
333 } 366 }
334 367
335 const string BmpBlockUtil::read_image_file(const char *filename) { 368 const string BmpBlockUtil::read_image_file(const char *filename) {
336 string content; 369 string content;
337 vector<char> buffer; 370 vector<char> buffer;
338 371
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 static void usagehelp_exit(const char *prog_name) { 561 static void usagehelp_exit(const char *prog_name) {
529 printf( 562 printf(
530 "\n" 563 "\n"
531 "To create a new BMPBLOCK file using config from YAML file:\n" 564 "To create a new BMPBLOCK file using config from YAML file:\n"
532 "\n" 565 "\n"
533 " %s [-z NUM] -c YAML BMPBLOCK\n" 566 " %s [-z NUM] -c YAML BMPBLOCK\n"
534 "\n" 567 "\n"
535 " -z NUM = compression algorithm to use\n" 568 " -z NUM = compression algorithm to use\n"
536 " 0 = none\n" 569 " 0 = none\n"
537 " 1 = EFIv1\n" 570 " 1 = EFIv1\n"
538 " 2 = TBD\n" 571 " 2 = LZMA1\n"
539 "\n", prog_name); 572 "\n", prog_name);
540 printf( 573 printf(
541 "To display the contents of a BMPBLOCK:\n" 574 "To display the contents of a BMPBLOCK:\n"
542 "\n" 575 "\n"
543 " %s [-y] BMPBLOCK\n" 576 " %s [-y] BMPBLOCK\n"
544 "\n" 577 "\n"
545 " -y = display as yaml\n" 578 " -y = display as yaml\n"
546 "\n", prog_name); 579 "\n", prog_name);
547 printf( 580 printf(
548 "To unpack a BMPBLOCK file:\n" 581 "To unpack a BMPBLOCK file:\n"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 else if (extract_mode) { 678 else if (extract_mode) {
646 return dump_bmpblock(bmpblock_fn, 1, extract_dir, overwrite); 679 return dump_bmpblock(bmpblock_fn, 1, extract_dir, overwrite);
647 } else { 680 } else {
648 return dump_bmpblock(bmpblock_fn, show_as_yaml, 0, 0); 681 return dump_bmpblock(bmpblock_fn, show_as_yaml, 0, 0);
649 } 682 }
650 683
651 return 0; 684 return 0;
652 } 685 }
653 686
654 #endif // WITH_UTIL_MAIN 687 #endif // WITH_UTIL_MAIN
OLDNEW
« no previous file with comments | « utility/bmpblk_util.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698