2009-03-31 13:57:36 +02:00
|
|
|
/*
|
2009-09-14 15:29:27 +02:00
|
|
|
* cbfstool, CLI utility for CBFS file manipulation
|
2009-03-31 13:57:36 +02:00
|
|
|
*
|
2009-09-14 15:29:27 +02:00
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
|
|
|
* written by Patrick Georgi <patrick.georgi@coresystems.de>
|
2012-11-16 23:48:22 +01:00
|
|
|
* Copyright (C) 2012 Google, Inc.
|
2009-03-31 13:57:36 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2009-09-14 15:29:27 +02:00
|
|
|
#include <stdio.h>
|
2011-10-21 23:24:57 +02:00
|
|
|
#include <stdlib.h>
|
2009-12-21 16:09:01 +01:00
|
|
|
#include <string.h>
|
2015-03-06 00:38:03 +01:00
|
|
|
#include <strings.h>
|
2011-10-21 23:24:57 +02:00
|
|
|
#include <ctype.h>
|
2012-10-30 00:52:36 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2009-09-14 15:29:27 +02:00
|
|
|
#include "common.h"
|
|
|
|
#include "cbfs.h"
|
2013-01-28 19:15:49 +01:00
|
|
|
#include "cbfs_image.h"
|
2012-12-15 00:16:21 +01:00
|
|
|
#include "fit.h"
|
2009-03-31 13:57:36 +02:00
|
|
|
|
2009-09-22 17:58:19 +02:00
|
|
|
struct command {
|
|
|
|
const char *name;
|
2012-10-30 00:52:36 +01:00
|
|
|
const char *optstring;
|
|
|
|
int (*function) (void);
|
2009-09-22 17:58:19 +02:00
|
|
|
};
|
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
static struct param {
|
|
|
|
char *cbfs_name;
|
|
|
|
char *name;
|
|
|
|
char *filename;
|
|
|
|
char *bootblock;
|
2014-10-30 19:44:20 +01:00
|
|
|
char *ignore_section;
|
2013-07-09 19:39:13 +02:00
|
|
|
uint64_t u64val;
|
2013-01-28 07:23:49 +01:00
|
|
|
uint32_t type;
|
|
|
|
uint32_t baseaddress;
|
2013-01-29 02:45:12 +01:00
|
|
|
uint32_t baseaddress_assigned;
|
2013-01-28 07:23:49 +01:00
|
|
|
uint32_t loadaddress;
|
cbfstool: add a command to duplicate a cbfs instance
The new command allows to create a file where the original CBFS image
is duplicated at a different offset.
The required options of the new command are -D, the offset where the
copy CBFS header is placed, and -s, the size of the new CBFS copy.
When a CBFS is copied, the bootblock area of the source CBFS is
ignored, as well as empty and deleted files in the source CBFS. The
size of the destination CBFS is calculated as the rombase size of the
source CBFS less the bootblock size.
The copy instance can be created in the image only above the original,
which rules out the use of this new command for x86 images. If
necessary, this limitation could be addressed later.
As with other cbfstool commands, unless explicitly specified the
lowest CBFS instance in the image is considered the source. If
necessary, the user can specify the source CBFS using the -H option.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run multiple cbfstool commands on a storm image:
$ cd /tmp
$ cp /build/storm/firmware/image.serial.bin storm.bin
$ cbfstool storm.bin print
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
$ cbfstool storm.bin copy -D 0x420000
E: You need to specify -s/--size.
$ cbfstool storm.bin copy -D 0x420000 -s 0x70000
$ cbfstool storm.bin print
W: Multiple (2) CBFS headers found, using the first one.
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
cbfstool storm.bin print -H 0x420000
storm.bin: 8192 kB, bootblocksize 0, romsize 4784128, offset 0x420040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x420040 raw 416
ddr.mbn 0x420240 raw 25836
rpm.mbn 0x426780 raw 78576
tz.mbn 0x439ac0 raw 85360
fallback/verstage 0x44e880 stage 41620
fallback/romstage 0x458b80 stage 19556
fallback/ramstage 0x45d840 stage 25579
config 0x463c80 raw 2878
fallback/payload 0x464800 payload 64811
u-boot.dtb 0x474580 (unknown) 2993
(empty) 0x475180 null 110168
$ cbfstool storm.bin remove -n config -H 0x420000
$ cbfstool storm.bin copy -H 0x420000 -D 0x620000 -s 0x70000
$ cbfstool storm.bin print -H 0x620000
storm.bin: 8192 kB, bootblocksize 0, romsize 6881280, offset 0x620040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x620040 raw 416
ddr.mbn 0x620240 raw 25836
rpm.mbn 0x626780 raw 78576
tz.mbn 0x639ac0 raw 85360
fallback/verstage 0x64e880 stage 41620
fallback/romstage 0x658b80 stage 19556
fallback/ramstage 0x65d840 stage 25579
fallback/payload 0x663c80 payload 64811
u-boot.dtb 0x673a00 (unknown) 2993
(empty) 0x674600 null 113112
$ cbfstool /build/storm/firmware/image.serial.bin extract -n fallback/payload -f payload1
[..]
$ cbfstool storm.bin extract -H 0x620000 -n fallback/payload -f payload2
[..]
$ diff payload1 payload2
Change-Id: Ieb9205848aec361bb870de0d284dff06c597564f
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: b8d3c1b09a47ca24d2d2effc6de0e89d1b0a8903
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Change-Id: I227e607ccf7a9a8e2a1f3c6bbc506b8d29a35b1b
Original-Reviewed-on: https://chromium-review.googlesource.com/237561
Reviewed-on: http://review.coreboot.org/9742
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 04:26:54 +01:00
|
|
|
uint32_t copyoffset;
|
|
|
|
uint32_t copyoffset_assigned;
|
2013-01-29 02:45:12 +01:00
|
|
|
uint32_t headeroffset;
|
|
|
|
uint32_t headeroffset_assigned;
|
2013-01-28 07:23:49 +01:00
|
|
|
uint32_t entrypoint;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t alignment;
|
2013-03-19 05:17:12 +01:00
|
|
|
uint32_t pagesize;
|
2014-11-10 22:14:24 +01:00
|
|
|
uint32_t cbfsoffset;
|
|
|
|
uint32_t cbfsoffset_assigned;
|
2013-01-28 20:46:02 +01:00
|
|
|
uint32_t top_aligned;
|
2014-02-03 05:37:28 +01:00
|
|
|
uint32_t arch;
|
2012-12-15 00:16:21 +01:00
|
|
|
int fit_empty_entries;
|
2013-01-28 07:23:49 +01:00
|
|
|
comp_algo algo;
|
2013-08-27 20:22:21 +02:00
|
|
|
/* for linux payloads */
|
|
|
|
char *initrd;
|
|
|
|
char *cmdline;
|
2013-01-28 07:23:49 +01:00
|
|
|
} param = {
|
|
|
|
/* All variables not listed are initialized as zero. */
|
2014-02-03 05:37:28 +01:00
|
|
|
.arch = CBFS_ARCHITECTURE_UNKNOWN,
|
2013-01-28 07:23:49 +01:00
|
|
|
.algo = CBFS_COMPRESS_NONE,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
.headeroffset = ~0,
|
2013-01-28 07:23:49 +01:00
|
|
|
};
|
2012-10-30 00:52:36 +01:00
|
|
|
|
2013-01-29 08:22:11 +01:00
|
|
|
typedef int (*convert_buffer_t)(struct buffer *buffer, uint32_t *offset);
|
2009-03-31 13:57:36 +02:00
|
|
|
|
2013-07-09 19:39:13 +02:00
|
|
|
static int cbfs_add_integer_component(const char *cbfs_name,
|
|
|
|
const char *name,
|
|
|
|
uint64_t u64val,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
uint32_t offset,
|
|
|
|
uint32_t headeroffset) {
|
2013-07-09 19:39:13 +02:00
|
|
|
struct cbfs_image image;
|
|
|
|
struct buffer buffer;
|
|
|
|
int i, ret = 1;
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
ERROR("You need to specify -n/--name.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer_create(&buffer, 8, name) != 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
buffer.data[i] = (u64val >> i*8) & 0xff;
|
|
|
|
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
if (cbfs_image_from_file(&image, cbfs_name, headeroffset) != 0) {
|
2013-07-09 19:39:13 +02:00
|
|
|
ERROR("Could not load ROM image '%s'.\n", cbfs_name);
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbfs_get_entry(&image, name)) {
|
|
|
|
ERROR("'%s' already in ROM image.\n", name);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:38:03 +01:00
|
|
|
if (cbfs_add_entry(&image, &buffer, name, CBFS_COMPONENT_RAW, offset) !=
|
|
|
|
0) {
|
|
|
|
ERROR("Failed to add %llu into ROM image as '%s'.\n",
|
|
|
|
(long long unsigned)u64val, name);
|
2013-07-09 19:39:13 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbfs_image_write_file(&image, cbfs_name) == 0)
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
static int cbfs_add_component(const char *cbfs_name,
|
|
|
|
const char *filename,
|
|
|
|
const char *name,
|
|
|
|
uint32_t type,
|
|
|
|
uint32_t offset,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
uint32_t headeroffset,
|
2015-03-04 00:55:03 +01:00
|
|
|
convert_buffer_t convert)
|
|
|
|
{
|
2013-01-29 03:24:00 +01:00
|
|
|
struct cbfs_image image;
|
|
|
|
struct buffer buffer;
|
|
|
|
|
|
|
|
if (!filename) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -f/--filename.\n");
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
if (!name) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -n/--name.\n");
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
2009-03-31 13:57:36 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
if (type == 0) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify a valid -t/--type.\n");
|
2012-10-30 00:52:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2009-09-22 17:58:19 +02:00
|
|
|
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, cbfs_name, headeroffset))
|
2013-11-13 23:34:57 +01:00
|
|
|
return 1;
|
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
if (buffer_from_file(&buffer, filename) != 0) {
|
|
|
|
ERROR("Could not load file '%s'.\n", filename);
|
2013-11-13 23:34:57 +01:00
|
|
|
cbfs_image_delete(&image);
|
2012-10-30 00:52:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-29 08:22:11 +01:00
|
|
|
if (convert && convert(&buffer, &offset) != 0) {
|
2013-01-29 03:24:00 +01:00
|
|
|
ERROR("Failed to parse file '%s'.\n", filename);
|
|
|
|
buffer_delete(&buffer);
|
2013-11-13 23:34:57 +01:00
|
|
|
cbfs_image_delete(&image);
|
2013-01-29 03:24:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2009-09-22 17:58:19 +02:00
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
if (cbfs_get_entry(&image, name)) {
|
|
|
|
ERROR("'%s' already in ROM image.\n", name);
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
cbfs_image_delete(&image);
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2013-01-29 03:24:00 +01:00
|
|
|
|
|
|
|
if (cbfs_add_entry(&image, &buffer, name, type, offset) != 0) {
|
|
|
|
ERROR("Failed to add '%s' into ROM image.\n", filename);
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
cbfs_image_delete(&image);
|
2009-09-30 13:21:18 +02:00
|
|
|
return 1;
|
2011-10-14 21:44:14 +02:00
|
|
|
}
|
2012-10-30 00:52:36 +01:00
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
if (cbfs_image_write_file(&image, cbfs_name) != 0) {
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer_delete(&buffer);
|
|
|
|
cbfs_image_delete(&image);
|
2009-09-22 17:58:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:37:28 +01:00
|
|
|
static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset)
|
|
|
|
{
|
2013-01-29 08:22:11 +01:00
|
|
|
struct buffer output;
|
2014-02-03 05:37:28 +01:00
|
|
|
int ret;
|
2015-03-06 00:38:03 +01:00
|
|
|
ret = parse_elf_to_stage(buffer, &output, param.algo, offset,
|
|
|
|
param.ignore_section);
|
2014-02-03 05:37:28 +01:00
|
|
|
if (ret != 0)
|
2013-01-29 08:22:11 +01:00
|
|
|
return -1;
|
|
|
|
buffer_delete(buffer);
|
|
|
|
// direct assign, no dupe.
|
|
|
|
memcpy(buffer, &output, sizeof(*buffer));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-04 00:55:03 +01:00
|
|
|
static int cbfstool_convert_mkpayload(struct buffer *buffer,
|
|
|
|
unused uint32_t *offset)
|
|
|
|
{
|
2013-01-29 08:22:11 +01:00
|
|
|
struct buffer output;
|
2013-02-05 00:39:13 +01:00
|
|
|
int ret;
|
|
|
|
/* per default, try and see if payload is an ELF binary */
|
2015-03-06 00:38:03 +01:00
|
|
|
ret = parse_elf_to_payload(buffer, &output, param.algo);
|
2013-02-05 00:39:13 +01:00
|
|
|
|
|
|
|
/* If it's not an ELF, see if it's a UEFI FV */
|
|
|
|
if (ret != 0)
|
|
|
|
ret = parse_fv_to_payload(buffer, &output, param.algo);
|
|
|
|
|
2013-08-27 20:22:21 +02:00
|
|
|
/* If it's neither ELF nor UEFI Fv, try bzImage */
|
|
|
|
if (ret != 0)
|
|
|
|
ret = parse_bzImage_to_payload(buffer, &output,
|
|
|
|
param.initrd, param.cmdline, param.algo);
|
|
|
|
|
2013-02-05 00:39:13 +01:00
|
|
|
/* Not a supported payload type */
|
|
|
|
if (ret != 0) {
|
|
|
|
ERROR("Not a supported payload type (ELF / FV).\n");
|
2013-01-29 08:22:11 +01:00
|
|
|
return -1;
|
2013-02-05 00:39:13 +01:00
|
|
|
}
|
|
|
|
|
2013-01-29 08:22:11 +01:00
|
|
|
buffer_delete(buffer);
|
|
|
|
// direct assign, no dupe.
|
|
|
|
memcpy(buffer, &output, sizeof(*buffer));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cbfstool_convert_mkflatpayload(struct buffer *buffer,
|
2015-03-04 00:55:03 +01:00
|
|
|
unused uint32_t *offset)
|
|
|
|
{
|
2013-01-29 08:22:11 +01:00
|
|
|
struct buffer output;
|
|
|
|
if (parse_flat_binary_to_payload(buffer, &output,
|
|
|
|
param.loadaddress,
|
|
|
|
param.entrypoint,
|
|
|
|
param.algo) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
buffer_delete(buffer);
|
|
|
|
// direct assign, no dupe.
|
|
|
|
memcpy(buffer, &output, sizeof(*buffer));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-29 03:24:00 +01:00
|
|
|
static int cbfs_add(void)
|
|
|
|
{
|
|
|
|
return cbfs_add_component(param.cbfs_name,
|
|
|
|
param.filename,
|
|
|
|
param.name,
|
|
|
|
param.type,
|
|
|
|
param.baseaddress,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
param.headeroffset,
|
2013-01-29 03:24:00 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2013-01-29 08:22:11 +01:00
|
|
|
static int cbfs_add_stage(void)
|
2009-09-22 17:58:19 +02:00
|
|
|
{
|
2013-01-29 08:22:11 +01:00
|
|
|
return cbfs_add_component(param.cbfs_name,
|
|
|
|
param.filename,
|
|
|
|
param.name,
|
|
|
|
CBFS_COMPONENT_STAGE,
|
|
|
|
param.baseaddress,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
param.headeroffset,
|
2013-01-29 08:22:11 +01:00
|
|
|
cbfstool_convert_mkstage);
|
2009-09-22 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 08:22:11 +01:00
|
|
|
static int cbfs_add_payload(void)
|
2009-09-22 17:58:19 +02:00
|
|
|
{
|
2013-01-29 08:22:11 +01:00
|
|
|
return cbfs_add_component(param.cbfs_name,
|
|
|
|
param.filename,
|
|
|
|
param.name,
|
|
|
|
CBFS_COMPONENT_PAYLOAD,
|
|
|
|
param.baseaddress,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
param.headeroffset,
|
2013-01-29 08:22:11 +01:00
|
|
|
cbfstool_convert_mkpayload);
|
2009-03-31 13:57:36 +02:00
|
|
|
}
|
2009-09-22 17:58:19 +02:00
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_add_flat_binary(void)
|
2012-10-23 01:04:13 +02:00
|
|
|
{
|
2013-01-28 07:23:49 +01:00
|
|
|
if (param.loadaddress == 0) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify a valid "
|
2012-10-30 00:52:36 +01:00
|
|
|
"-l/--load-address.\n");
|
|
|
|
return 1;
|
2012-10-23 01:04:13 +02:00
|
|
|
}
|
2013-01-28 07:23:49 +01:00
|
|
|
if (param.entrypoint == 0) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify a valid "
|
2012-10-30 00:52:36 +01:00
|
|
|
"-e/--entry-point.\n");
|
|
|
|
return 1;
|
2012-10-23 01:04:13 +02:00
|
|
|
}
|
2013-01-29 08:22:11 +01:00
|
|
|
return cbfs_add_component(param.cbfs_name,
|
|
|
|
param.filename,
|
|
|
|
param.name,
|
|
|
|
CBFS_COMPONENT_PAYLOAD,
|
|
|
|
param.baseaddress,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
param.headeroffset,
|
2013-01-29 08:22:11 +01:00
|
|
|
cbfstool_convert_mkflatpayload);
|
2012-10-23 01:04:13 +02:00
|
|
|
}
|
|
|
|
|
2013-07-09 19:39:13 +02:00
|
|
|
static int cbfs_add_integer(void)
|
|
|
|
{
|
|
|
|
return cbfs_add_integer_component(param.cbfs_name,
|
|
|
|
param.name,
|
|
|
|
param.u64val,
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
param.baseaddress,
|
|
|
|
param.headeroffset);
|
2013-07-09 19:39:13 +02:00
|
|
|
}
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_remove(void)
|
2012-01-27 09:33:47 +01:00
|
|
|
{
|
2013-01-28 19:38:40 +01:00
|
|
|
struct cbfs_image image;
|
2012-01-27 09:33:47 +01:00
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (!param.name) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -n/--name.\n");
|
2012-01-27 09:33:47 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name, param.headeroffset))
|
2012-01-27 09:33:47 +01:00
|
|
|
return 1;
|
|
|
|
|
2013-01-28 19:38:40 +01:00
|
|
|
if (cbfs_remove_entry(&image, param.name) != 0) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("Removing file '%s' failed.\n",
|
2013-01-28 19:38:40 +01:00
|
|
|
param.name);
|
|
|
|
cbfs_image_delete(&image);
|
2012-01-27 09:33:47 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2013-01-28 19:38:40 +01:00
|
|
|
if (cbfs_image_write_file(&image, param.cbfs_name) != 0) {
|
|
|
|
cbfs_image_delete(&image);
|
2012-01-27 09:33:47 +01:00
|
|
|
return 1;
|
2012-10-30 00:52:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 19:38:40 +01:00
|
|
|
cbfs_image_delete(&image);
|
2012-01-27 09:33:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_create(void)
|
2009-09-22 17:58:19 +02:00
|
|
|
{
|
2013-01-29 02:45:12 +01:00
|
|
|
struct cbfs_image image;
|
|
|
|
struct buffer bootblock;
|
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (param.size == 0) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify a valid -s/--size.\n");
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:37:28 +01:00
|
|
|
if (param.arch == CBFS_ARCHITECTURE_UNKNOWN) {
|
2013-03-29 00:46:07 +01:00
|
|
|
ERROR("You need to specify -m/--machine arch.\n");
|
2012-11-16 23:48:22 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:14:24 +01:00
|
|
|
if (!param.bootblock) {
|
|
|
|
DEBUG("-B not given, creating image without bootblock.\n");
|
|
|
|
buffer_create(&bootblock, 0, "(dummy)");
|
|
|
|
} else if (buffer_from_file(&bootblock, param.bootblock)) {
|
2013-01-29 02:45:12 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:14:24 +01:00
|
|
|
if (!param.alignment)
|
|
|
|
param.alignment = 64; // default CBFS entry alignment
|
|
|
|
|
|
|
|
// Set default offsets. x86, as usual, needs to be a special snowflake.
|
2013-01-29 02:45:12 +01:00
|
|
|
if (!param.baseaddress_assigned) {
|
2014-11-10 22:14:24 +01:00
|
|
|
if (param.arch == CBFS_ARCHITECTURE_X86) {
|
|
|
|
// Make sure there's at least enough room for rel_offset
|
|
|
|
param.baseaddress = param.size - (
|
|
|
|
bootblock.size > sizeof(int32_t) ?
|
|
|
|
bootblock.size : sizeof(int32_t));
|
|
|
|
DEBUG("x86 -> bootblock lies at end of ROM (%#x).\n",
|
|
|
|
param.baseaddress);
|
|
|
|
} else {
|
|
|
|
param.baseaddress = 0;
|
|
|
|
DEBUG("bootblock starts at address 0x0.\n");
|
|
|
|
}
|
2013-01-29 02:45:12 +01:00
|
|
|
}
|
|
|
|
if (!param.headeroffset_assigned) {
|
2014-11-10 22:14:24 +01:00
|
|
|
if (param.arch == CBFS_ARCHITECTURE_X86) {
|
|
|
|
param.headeroffset = param.baseaddress -
|
|
|
|
sizeof(struct cbfs_header);
|
|
|
|
DEBUG("x86 -> CBFS header before bootblock (%#x).\n",
|
|
|
|
param.headeroffset);
|
|
|
|
} else {
|
|
|
|
param.headeroffset = align_up(param.baseaddress +
|
|
|
|
bootblock.size, sizeof(uint32_t));
|
|
|
|
DEBUG("CBFS header placed behind bootblock (%#x).\n",
|
|
|
|
param.headeroffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!param.cbfsoffset_assigned) {
|
|
|
|
if (param.arch == CBFS_ARCHITECTURE_X86) {
|
|
|
|
param.cbfsoffset = 0;
|
|
|
|
DEBUG("x86 -> CBFS entries start at address 0x0.\n");
|
|
|
|
} else {
|
|
|
|
param.cbfsoffset = align_up(param.headeroffset +
|
|
|
|
sizeof(struct cbfs_header),
|
|
|
|
param.alignment);
|
|
|
|
DEBUG("CBFS entries start beind master header (%#x).\n",
|
|
|
|
param.cbfsoffset);
|
2013-01-29 02:45:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbfs_image_create(&image,
|
2014-02-03 05:37:28 +01:00
|
|
|
param.arch,
|
2013-01-29 02:45:12 +01:00
|
|
|
param.size,
|
|
|
|
param.alignment,
|
|
|
|
&bootblock,
|
|
|
|
param.baseaddress,
|
|
|
|
param.headeroffset,
|
2014-11-10 22:14:24 +01:00
|
|
|
param.cbfsoffset) != 0) {
|
2013-01-29 02:45:12 +01:00
|
|
|
ERROR("Failed to create %s.\n", param.cbfs_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
buffer_delete(&bootblock);
|
|
|
|
|
|
|
|
if (cbfs_image_write_file(&image, param.cbfs_name) != 0) {
|
|
|
|
ERROR("Failed to write %s.\n", param.cbfs_name);
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return 0;
|
2009-09-22 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_locate(void)
|
2009-11-09 18:18:02 +01:00
|
|
|
{
|
2013-01-28 20:46:02 +01:00
|
|
|
struct cbfs_image image;
|
|
|
|
struct buffer buffer;
|
|
|
|
int32_t address;
|
2012-10-30 00:52:36 +01:00
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (!param.filename) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -f/--filename.\n");
|
2012-10-30 00:52:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (!param.name) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -n/--name.\n");
|
2009-11-09 18:18:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name, param.headeroffset))
|
2013-01-28 20:46:02 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (cbfs_get_entry(&image, param.name))
|
|
|
|
WARN("'%s' already in CBFS.\n", param.name);
|
|
|
|
|
|
|
|
if (buffer_from_file(&buffer, param.filename) != 0) {
|
|
|
|
ERROR("Cannot load %s.\n", param.filename);
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-10-30 00:52:36 +01:00
|
|
|
|
2013-01-28 20:46:02 +01:00
|
|
|
address = cbfs_locate_entry(&image, param.name, buffer.size,
|
2013-03-19 05:24:43 +01:00
|
|
|
param.pagesize, param.alignment);
|
2013-01-28 20:46:02 +01:00
|
|
|
buffer_delete(&buffer);
|
2009-11-09 18:18:02 +01:00
|
|
|
|
2013-01-28 20:46:02 +01:00
|
|
|
if (address == -1) {
|
2013-03-19 05:24:43 +01:00
|
|
|
ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n",
|
|
|
|
param.name, param.pagesize, param.alignment);
|
2013-01-28 20:46:02 +01:00
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param.top_aligned)
|
2014-02-05 08:10:08 +01:00
|
|
|
address = address - image.header->romsize;
|
2013-01-28 20:46:02 +01:00
|
|
|
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
printf("0x%x\n", address);
|
|
|
|
return 0;
|
2009-11-09 18:18:02 +01:00
|
|
|
}
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_print(void)
|
2009-09-22 17:58:19 +02:00
|
|
|
{
|
2013-01-28 19:15:49 +01:00
|
|
|
struct cbfs_image image;
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name, param.headeroffset))
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
2014-12-24 00:59:57 +01:00
|
|
|
|
2013-01-28 19:15:49 +01:00
|
|
|
cbfs_print_directory(&image);
|
|
|
|
cbfs_image_delete(&image);
|
2009-09-22 17:58:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static int cbfs_extract(void)
|
2011-01-13 10:09:21 +01:00
|
|
|
{
|
2013-01-28 19:29:49 +01:00
|
|
|
int result = 0;
|
|
|
|
struct cbfs_image image;
|
2011-01-13 10:09:21 +01:00
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (!param.filename) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -f/--filename.\n");
|
2012-10-30 00:52:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
if (!param.name) {
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("You need to specify -n/--name.\n");
|
2011-01-13 10:09:21 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name, param.headeroffset))
|
2013-01-28 19:29:49 +01:00
|
|
|
result = 1;
|
2014-12-24 00:59:57 +01:00
|
|
|
else if (cbfs_export_entry(&image, param.name,
|
|
|
|
param.filename))
|
2013-01-28 19:29:49 +01:00
|
|
|
result = 1;
|
2011-01-13 10:09:21 +01:00
|
|
|
|
2013-01-28 19:29:49 +01:00
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return result;
|
2011-01-13 10:09:21 +01:00
|
|
|
}
|
|
|
|
|
2012-12-15 00:16:21 +01:00
|
|
|
static int cbfs_update_fit(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct cbfs_image image;
|
|
|
|
|
|
|
|
if (!param.name) {
|
|
|
|
ERROR("You need to specify -n/--name.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param.fit_empty_entries <= 0) {
|
|
|
|
ERROR("Invalid number of fit entries "
|
|
|
|
"(-x/--empty-fits): %d\n", param.fit_empty_entries);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-24 00:59:57 +01:00
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name, param.headeroffset))
|
2012-12-15 00:16:21 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
ret = fit_update_table(&image, param.fit_empty_entries, param.name);
|
|
|
|
if (!ret)
|
|
|
|
ret = cbfs_image_write_file(&image, param.cbfs_name);
|
|
|
|
|
|
|
|
cbfs_image_delete(&image);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
cbfstool: add a command to duplicate a cbfs instance
The new command allows to create a file where the original CBFS image
is duplicated at a different offset.
The required options of the new command are -D, the offset where the
copy CBFS header is placed, and -s, the size of the new CBFS copy.
When a CBFS is copied, the bootblock area of the source CBFS is
ignored, as well as empty and deleted files in the source CBFS. The
size of the destination CBFS is calculated as the rombase size of the
source CBFS less the bootblock size.
The copy instance can be created in the image only above the original,
which rules out the use of this new command for x86 images. If
necessary, this limitation could be addressed later.
As with other cbfstool commands, unless explicitly specified the
lowest CBFS instance in the image is considered the source. If
necessary, the user can specify the source CBFS using the -H option.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run multiple cbfstool commands on a storm image:
$ cd /tmp
$ cp /build/storm/firmware/image.serial.bin storm.bin
$ cbfstool storm.bin print
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
$ cbfstool storm.bin copy -D 0x420000
E: You need to specify -s/--size.
$ cbfstool storm.bin copy -D 0x420000 -s 0x70000
$ cbfstool storm.bin print
W: Multiple (2) CBFS headers found, using the first one.
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
cbfstool storm.bin print -H 0x420000
storm.bin: 8192 kB, bootblocksize 0, romsize 4784128, offset 0x420040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x420040 raw 416
ddr.mbn 0x420240 raw 25836
rpm.mbn 0x426780 raw 78576
tz.mbn 0x439ac0 raw 85360
fallback/verstage 0x44e880 stage 41620
fallback/romstage 0x458b80 stage 19556
fallback/ramstage 0x45d840 stage 25579
config 0x463c80 raw 2878
fallback/payload 0x464800 payload 64811
u-boot.dtb 0x474580 (unknown) 2993
(empty) 0x475180 null 110168
$ cbfstool storm.bin remove -n config -H 0x420000
$ cbfstool storm.bin copy -H 0x420000 -D 0x620000 -s 0x70000
$ cbfstool storm.bin print -H 0x620000
storm.bin: 8192 kB, bootblocksize 0, romsize 6881280, offset 0x620040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x620040 raw 416
ddr.mbn 0x620240 raw 25836
rpm.mbn 0x626780 raw 78576
tz.mbn 0x639ac0 raw 85360
fallback/verstage 0x64e880 stage 41620
fallback/romstage 0x658b80 stage 19556
fallback/ramstage 0x65d840 stage 25579
fallback/payload 0x663c80 payload 64811
u-boot.dtb 0x673a00 (unknown) 2993
(empty) 0x674600 null 113112
$ cbfstool /build/storm/firmware/image.serial.bin extract -n fallback/payload -f payload1
[..]
$ cbfstool storm.bin extract -H 0x620000 -n fallback/payload -f payload2
[..]
$ diff payload1 payload2
Change-Id: Ieb9205848aec361bb870de0d284dff06c597564f
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: b8d3c1b09a47ca24d2d2effc6de0e89d1b0a8903
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Change-Id: I227e607ccf7a9a8e2a1f3c6bbc506b8d29a35b1b
Original-Reviewed-on: https://chromium-review.googlesource.com/237561
Reviewed-on: http://review.coreboot.org/9742
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 04:26:54 +01:00
|
|
|
static int cbfs_copy(void)
|
|
|
|
{
|
|
|
|
struct cbfs_image image;
|
|
|
|
|
|
|
|
if (!param.copyoffset_assigned) {
|
|
|
|
ERROR("You need to specify -D/--copy_offset.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!param.size) {
|
|
|
|
ERROR("You need to specify -s/--size.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbfs_image_from_file(&image, param.cbfs_name,
|
|
|
|
param.headeroffset) != 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (cbfs_copy_instance(&image, param.copyoffset, param.size))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Save the new image. */
|
|
|
|
return buffer_write_file(&image.buffer, param.cbfs_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-21 23:24:57 +02:00
|
|
|
static const struct command commands[] = {
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
{"add", "H;f:n:t:b:vh?", cbfs_add},
|
2014-12-24 00:59:57 +01:00
|
|
|
{"add-flat-binary", "H:f:n:l:e:c:b:vh?", cbfs_add_flat_binary},
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
{"add-payload", "H:f:n:t:c:b:vh?C:I:", cbfs_add_payload},
|
|
|
|
{"add-stage", "H:f:n:t:c:b:S:vh?", cbfs_add_stage},
|
|
|
|
{"add-int", "H:i:n:b:vh?", cbfs_add_integer},
|
2013-01-29 02:45:12 +01:00
|
|
|
{"create", "s:B:b:H:a:o:m:vh?", cbfs_create},
|
2014-12-24 00:59:57 +01:00
|
|
|
{"copy", "H:D:s:", cbfs_copy},
|
|
|
|
{"extract", "H:n:f:vh?", cbfs_extract},
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
{"locate", "H:f:n:P:a:Tvh?", cbfs_locate},
|
|
|
|
{"print", "H:vh?", cbfs_print},
|
2014-12-24 00:59:57 +01:00
|
|
|
{"remove", "H:n:vh?", cbfs_remove},
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
{"update-fit", "H:n:x:vh?", cbfs_update_fit},
|
2012-10-30 00:52:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
2014-12-24 00:59:57 +01:00
|
|
|
{"alignment", required_argument, 0, 'a' },
|
2014-11-10 22:14:24 +01:00
|
|
|
{"base-address", required_argument, 0, 'b' },
|
2014-12-24 00:59:57 +01:00
|
|
|
{"bootblock", required_argument, 0, 'B' },
|
|
|
|
{"cmdline", required_argument, 0, 'C' },
|
|
|
|
{"compression", required_argument, 0, 'c' },
|
cbfstool: add a command to duplicate a cbfs instance
The new command allows to create a file where the original CBFS image
is duplicated at a different offset.
The required options of the new command are -D, the offset where the
copy CBFS header is placed, and -s, the size of the new CBFS copy.
When a CBFS is copied, the bootblock area of the source CBFS is
ignored, as well as empty and deleted files in the source CBFS. The
size of the destination CBFS is calculated as the rombase size of the
source CBFS less the bootblock size.
The copy instance can be created in the image only above the original,
which rules out the use of this new command for x86 images. If
necessary, this limitation could be addressed later.
As with other cbfstool commands, unless explicitly specified the
lowest CBFS instance in the image is considered the source. If
necessary, the user can specify the source CBFS using the -H option.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run multiple cbfstool commands on a storm image:
$ cd /tmp
$ cp /build/storm/firmware/image.serial.bin storm.bin
$ cbfstool storm.bin print
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
$ cbfstool storm.bin copy -D 0x420000
E: You need to specify -s/--size.
$ cbfstool storm.bin copy -D 0x420000 -s 0x70000
$ cbfstool storm.bin print
W: Multiple (2) CBFS headers found, using the first one.
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
cbfstool storm.bin print -H 0x420000
storm.bin: 8192 kB, bootblocksize 0, romsize 4784128, offset 0x420040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x420040 raw 416
ddr.mbn 0x420240 raw 25836
rpm.mbn 0x426780 raw 78576
tz.mbn 0x439ac0 raw 85360
fallback/verstage 0x44e880 stage 41620
fallback/romstage 0x458b80 stage 19556
fallback/ramstage 0x45d840 stage 25579
config 0x463c80 raw 2878
fallback/payload 0x464800 payload 64811
u-boot.dtb 0x474580 (unknown) 2993
(empty) 0x475180 null 110168
$ cbfstool storm.bin remove -n config -H 0x420000
$ cbfstool storm.bin copy -H 0x420000 -D 0x620000 -s 0x70000
$ cbfstool storm.bin print -H 0x620000
storm.bin: 8192 kB, bootblocksize 0, romsize 6881280, offset 0x620040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x620040 raw 416
ddr.mbn 0x620240 raw 25836
rpm.mbn 0x626780 raw 78576
tz.mbn 0x639ac0 raw 85360
fallback/verstage 0x64e880 stage 41620
fallback/romstage 0x658b80 stage 19556
fallback/ramstage 0x65d840 stage 25579
fallback/payload 0x663c80 payload 64811
u-boot.dtb 0x673a00 (unknown) 2993
(empty) 0x674600 null 113112
$ cbfstool /build/storm/firmware/image.serial.bin extract -n fallback/payload -f payload1
[..]
$ cbfstool storm.bin extract -H 0x620000 -n fallback/payload -f payload2
[..]
$ diff payload1 payload2
Change-Id: Ieb9205848aec361bb870de0d284dff06c597564f
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: b8d3c1b09a47ca24d2d2effc6de0e89d1b0a8903
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Change-Id: I227e607ccf7a9a8e2a1f3c6bbc506b8d29a35b1b
Original-Reviewed-on: https://chromium-review.googlesource.com/237561
Reviewed-on: http://review.coreboot.org/9742
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 04:26:54 +01:00
|
|
|
{"copy-offset", required_argument, 0, 'D' },
|
2014-12-24 00:59:57 +01:00
|
|
|
{"empty-fits", required_argument, 0, 'x' },
|
2014-11-10 22:14:24 +01:00
|
|
|
{"entry-point", required_argument, 0, 'e' },
|
|
|
|
{"file", required_argument, 0, 'f' },
|
2014-12-24 00:59:57 +01:00
|
|
|
{"header-offset", required_argument, 0, 'H' },
|
|
|
|
{"help", no_argument, 0, 'h' },
|
|
|
|
{"ignore-sec", required_argument, 0, 'S' },
|
|
|
|
{"initrd", required_argument, 0, 'I' },
|
2014-11-10 22:14:24 +01:00
|
|
|
{"int", required_argument, 0, 'i' },
|
2014-12-24 00:59:57 +01:00
|
|
|
{"load-address", required_argument, 0, 'l' },
|
2014-11-10 22:14:24 +01:00
|
|
|
{"machine", required_argument, 0, 'm' },
|
2014-12-24 00:59:57 +01:00
|
|
|
{"name", required_argument, 0, 'n' },
|
|
|
|
{"offset", required_argument, 0, 'o' },
|
|
|
|
{"page-size", required_argument, 0, 'P' },
|
|
|
|
{"size", required_argument, 0, 's' },
|
|
|
|
{"top-aligned", required_argument, 0, 'T' },
|
|
|
|
{"type", required_argument, 0, 't' },
|
2014-11-10 22:14:24 +01:00
|
|
|
{"verbose", no_argument, 0, 'v' },
|
|
|
|
{NULL, 0, 0, 0 }
|
2009-09-22 17:58:19 +02:00
|
|
|
};
|
|
|
|
|
2012-10-30 00:52:36 +01:00
|
|
|
static void usage(char *name)
|
2009-09-22 17:58:19 +02:00
|
|
|
{
|
|
|
|
printf
|
2010-04-24 23:24:06 +02:00
|
|
|
("cbfstool: Management utility for CBFS formatted ROM images\n\n"
|
2012-10-30 00:52:36 +01:00
|
|
|
"USAGE:\n" " %s [-h]\n"
|
2013-01-28 07:39:43 +01:00
|
|
|
" %s FILE COMMAND [-v] [PARAMETERS]...\n\n" "OPTIONs:\n"
|
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the
firmware image. cbfstool should be able to operate on any of them, not
just the first one present.
To accomplish that, allow all CBFS commands to accept the -H parameter
(which specifies the exact CBFS header location in the image).
If this parameter is specified, the image is not searched for the CBFS
header, only the specified location is checked for validity, If the
location is valid, it is considered to be the CBFS header, if not -
the tool exits with an error status.
Note, that default behavior of the tool does not change.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run the following experiments:
- examined an image with three CBFS instances, was able to print all
of them.
- built a rambi coreboot image and tried the following (cbfstool output abbreviated):
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2
7ffff0 fff67de9 000000ff fff6dfe9 fffff650
800000
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650
coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000
alignment: 64 bytes, architecture: x86
Name Offset Type Size
cmos_layout.bin 0x700000 cmos_layout 1164
...
(empty) 0x7ec600 null 77848
$ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654
E: /build/rambi/firmware/coreboot.rom does not have CBFS master header.
E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'.
$
Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a
Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/237485
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/9741
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 00:10:12 +01:00
|
|
|
" -H header_offset Do not search for header, use this offset\n"
|
|
|
|
" -T Output top-aligned memory address\n"
|
|
|
|
" -v Provide verbose output\n"
|
|
|
|
" -h Display this help message\n\n"
|
2009-09-22 17:58:19 +02:00
|
|
|
"COMMANDs:\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" add -f FILE -n NAME -t TYPE [-b base-address] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Add a component\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" add-payload -f FILE -n NAME [-c compression] [-b base] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Add a payload to the ROM\n"
|
2013-08-27 20:22:21 +02:00
|
|
|
" (linux specific: [-C cmdline] [-I initrd])\n"
|
2014-10-30 19:44:20 +01:00
|
|
|
" add-stage -f FILE -n NAME [-c compression] [-b base] \\\n"
|
|
|
|
" [-S section-to-ignore] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Add a stage to the ROM\n"
|
|
|
|
" add-flat-binary -f FILE -n NAME -l load-address \\\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" -e entry-point [-c compression] [-b base] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Add a 32bit flat mode binary\n"
|
2013-07-09 19:39:13 +02:00
|
|
|
" add-int -i INTEGER -n NAME [-b base] "
|
|
|
|
"Add a raw 64-bit integer value\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" remove -n NAME "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Remove a component\n"
|
cbfstool: add a command to duplicate a cbfs instance
The new command allows to create a file where the original CBFS image
is duplicated at a different offset.
The required options of the new command are -D, the offset where the
copy CBFS header is placed, and -s, the size of the new CBFS copy.
When a CBFS is copied, the bootblock area of the source CBFS is
ignored, as well as empty and deleted files in the source CBFS. The
size of the destination CBFS is calculated as the rombase size of the
source CBFS less the bootblock size.
The copy instance can be created in the image only above the original,
which rules out the use of this new command for x86 images. If
necessary, this limitation could be addressed later.
As with other cbfstool commands, unless explicitly specified the
lowest CBFS instance in the image is considered the source. If
necessary, the user can specify the source CBFS using the -H option.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run multiple cbfstool commands on a storm image:
$ cd /tmp
$ cp /build/storm/firmware/image.serial.bin storm.bin
$ cbfstool storm.bin print
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
$ cbfstool storm.bin copy -D 0x420000
E: You need to specify -s/--size.
$ cbfstool storm.bin copy -D 0x420000 -s 0x70000
$ cbfstool storm.bin print
W: Multiple (2) CBFS headers found, using the first one.
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
cbfstool storm.bin print -H 0x420000
storm.bin: 8192 kB, bootblocksize 0, romsize 4784128, offset 0x420040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x420040 raw 416
ddr.mbn 0x420240 raw 25836
rpm.mbn 0x426780 raw 78576
tz.mbn 0x439ac0 raw 85360
fallback/verstage 0x44e880 stage 41620
fallback/romstage 0x458b80 stage 19556
fallback/ramstage 0x45d840 stage 25579
config 0x463c80 raw 2878
fallback/payload 0x464800 payload 64811
u-boot.dtb 0x474580 (unknown) 2993
(empty) 0x475180 null 110168
$ cbfstool storm.bin remove -n config -H 0x420000
$ cbfstool storm.bin copy -H 0x420000 -D 0x620000 -s 0x70000
$ cbfstool storm.bin print -H 0x620000
storm.bin: 8192 kB, bootblocksize 0, romsize 6881280, offset 0x620040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x620040 raw 416
ddr.mbn 0x620240 raw 25836
rpm.mbn 0x626780 raw 78576
tz.mbn 0x639ac0 raw 85360
fallback/verstage 0x64e880 stage 41620
fallback/romstage 0x658b80 stage 19556
fallback/ramstage 0x65d840 stage 25579
fallback/payload 0x663c80 payload 64811
u-boot.dtb 0x673a00 (unknown) 2993
(empty) 0x674600 null 113112
$ cbfstool /build/storm/firmware/image.serial.bin extract -n fallback/payload -f payload1
[..]
$ cbfstool storm.bin extract -H 0x620000 -n fallback/payload -f payload2
[..]
$ diff payload1 payload2
Change-Id: Ieb9205848aec361bb870de0d284dff06c597564f
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: b8d3c1b09a47ca24d2d2effc6de0e89d1b0a8903
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Change-Id: I227e607ccf7a9a8e2a1f3c6bbc506b8d29a35b1b
Original-Reviewed-on: https://chromium-review.googlesource.com/237561
Reviewed-on: http://review.coreboot.org/9742
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 04:26:54 +01:00
|
|
|
" copy -D new_header_offset -s region size \\\n"
|
|
|
|
" [-H source header offset] "
|
|
|
|
"Create a copy (duplicate) cbfs instance\n"
|
2014-11-10 22:14:24 +01:00
|
|
|
" create -s size -m ARCH [-B bootblock] [-b bootblock offset] \\\n"
|
|
|
|
" [-o CBFS offset] [-H header offset] [-a align] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Create a ROM file\n"
|
2013-03-19 05:24:43 +01:00
|
|
|
" locate -f FILE -n NAME [-P page-size] [-a align] [-T] "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Find a place for a file of that size\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" print "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Show the contents of the ROM\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
" extract -n NAME -f FILE "
|
2012-10-30 00:52:36 +01:00
|
|
|
"Extracts a raw payload from ROM\n"
|
2012-12-15 00:16:21 +01:00
|
|
|
" update-fit -n MICROCODE_BLOB_NAME -x EMTPY_FIT_ENTRIES\n "
|
|
|
|
"Updates the FIT table with microcode entries\n"
|
2011-01-17 06:02:09 +01:00
|
|
|
"\n"
|
2015-03-06 00:38:03 +01:00
|
|
|
"OFFSETs:\n"
|
|
|
|
" Numbers accompanying -b, -H, and -o switches may be provided\n"
|
|
|
|
" in two possible formats: if their value is greater than\n"
|
|
|
|
" 0x80000000, they are interpreted as a top-aligned x86 memory\n"
|
|
|
|
" address; otherwise, they are treated as an offset into flash.\n"
|
2012-11-16 23:48:22 +01:00
|
|
|
"ARCHes:\n"
|
2014-06-14 00:56:45 +02:00
|
|
|
" arm64, arm, mips, x86\n"
|
2012-10-30 00:52:36 +01:00
|
|
|
"TYPEs:\n", name, name
|
|
|
|
);
|
2010-04-24 23:24:06 +02:00
|
|
|
print_supported_filetypes();
|
2009-09-22 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-07-17 21:17:15 +02:00
|
|
|
size_t i;
|
2012-10-30 00:52:36 +01:00
|
|
|
int c;
|
2009-09-22 17:58:19 +02:00
|
|
|
|
|
|
|
if (argc < 3) {
|
2012-10-30 00:52:36 +01:00
|
|
|
usage(argv[0]);
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-28 07:23:49 +01:00
|
|
|
param.cbfs_name = argv[1];
|
2009-09-22 17:58:19 +02:00
|
|
|
char *cmd = argv[2];
|
2012-10-30 00:52:36 +01:00
|
|
|
optind += 2;
|
2009-09-22 17:58:19 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(commands); i++) {
|
|
|
|
if (strcmp(cmd, commands[i].name) != 0)
|
|
|
|
continue;
|
2012-10-30 00:52:36 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
char *suffix = NULL;
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, commands[i].optstring,
|
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* filter out illegal long options */
|
2013-01-08 03:10:16 +01:00
|
|
|
if (strchr(commands[i].optstring, c) == NULL) {
|
2012-10-30 00:52:36 +01:00
|
|
|
/* TODO maybe print actual long option instead */
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("%s: invalid option -- '%c'\n",
|
|
|
|
argv[0], c);
|
2012-10-30 00:52:36 +01:00
|
|
|
c = '?';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case 'n':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.name = optarg;
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (intfiletype(optarg) != ((uint64_t) - 1))
|
2013-01-28 07:23:49 +01:00
|
|
|
param.type = intfiletype(optarg);
|
2012-10-30 00:52:36 +01:00
|
|
|
else
|
2013-01-28 07:23:49 +01:00
|
|
|
param.type = strtoul(optarg, NULL, 0);
|
|
|
|
if (param.type == 0)
|
2013-01-28 07:39:43 +01:00
|
|
|
WARN("Unknown type '%s' ignored\n",
|
2012-10-30 00:52:36 +01:00
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (!strncasecmp(optarg, "lzma", 5))
|
2013-01-28 07:23:49 +01:00
|
|
|
param.algo = CBFS_COMPRESS_LZMA;
|
2012-10-30 00:52:36 +01:00
|
|
|
else if (!strncasecmp(optarg, "none", 5))
|
2013-01-28 07:23:49 +01:00
|
|
|
param.algo = CBFS_COMPRESS_NONE;
|
2012-10-30 00:52:36 +01:00
|
|
|
else
|
2013-01-28 07:39:43 +01:00
|
|
|
WARN("Unknown compression '%s'"
|
|
|
|
" ignored.\n", optarg);
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 'b':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.baseaddress = strtoul(optarg, NULL, 0);
|
2013-01-29 02:45:12 +01:00
|
|
|
// baseaddress may be zero on non-x86, so we
|
|
|
|
// need an explicit "baseaddress_assigned".
|
|
|
|
param.baseaddress = strtoul(optarg, NULL, 0);
|
|
|
|
param.baseaddress_assigned = 1;
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 'l':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.loadaddress = strtoul(optarg, NULL, 0);
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 'e':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.entrypoint = strtoul(optarg, NULL, 0);
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 's':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.size = strtoul(optarg, &suffix, 0);
|
2012-10-30 00:52:36 +01:00
|
|
|
if (tolower(suffix[0])=='k') {
|
2013-01-28 07:23:49 +01:00
|
|
|
param.size *= 1024;
|
2012-10-30 00:52:36 +01:00
|
|
|
}
|
|
|
|
if (tolower(suffix[0])=='m') {
|
2013-01-28 07:23:49 +01:00
|
|
|
param.size *= 1024 * 1024;
|
2012-10-30 00:52:36 +01:00
|
|
|
}
|
2014-08-09 17:44:39 +02:00
|
|
|
break;
|
2012-10-30 00:52:36 +01:00
|
|
|
case 'B':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.bootblock = optarg;
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
2013-01-29 02:45:12 +01:00
|
|
|
case 'H':
|
|
|
|
param.headeroffset = strtoul(
|
|
|
|
optarg, NULL, 0);
|
|
|
|
param.headeroffset_assigned = 1;
|
|
|
|
break;
|
cbfstool: add a command to duplicate a cbfs instance
The new command allows to create a file where the original CBFS image
is duplicated at a different offset.
The required options of the new command are -D, the offset where the
copy CBFS header is placed, and -s, the size of the new CBFS copy.
When a CBFS is copied, the bootblock area of the source CBFS is
ignored, as well as empty and deleted files in the source CBFS. The
size of the destination CBFS is calculated as the rombase size of the
source CBFS less the bootblock size.
The copy instance can be created in the image only above the original,
which rules out the use of this new command for x86 images. If
necessary, this limitation could be addressed later.
As with other cbfstool commands, unless explicitly specified the
lowest CBFS instance in the image is considered the source. If
necessary, the user can specify the source CBFS using the -H option.
BRANCH=storm
BUG=chrome-os-partner:34161, chromium:445938
TEST=run multiple cbfstool commands on a storm image:
$ cd /tmp
$ cp /build/storm/firmware/image.serial.bin storm.bin
$ cbfstool storm.bin print
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
$ cbfstool storm.bin copy -D 0x420000
E: You need to specify -s/--size.
$ cbfstool storm.bin copy -D 0x420000 -s 0x70000
$ cbfstool storm.bin print
W: Multiple (2) CBFS headers found, using the first one.
storm.bin: 8192 kB, bootblocksize 34472, romsize 458752, offset 0x8700
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x8700 raw 416
ddr.mbn 0x8900 raw 25836
rpm.mbn 0xee40 raw 78576
tz.mbn 0x22180 raw 85360
fallback/verstage 0x36f40 stage 41620
fallback/romstage 0x41240 stage 19556
fallback/ramstage 0x45f00 stage 25579
config 0x4c340 raw 2878
fallback/payload 0x4cec0 payload 64811
u-boot.dtb 0x5cc40 (unknown) 2993
(empty) 0x5d840 null 75608
cbfstool storm.bin print -H 0x420000
storm.bin: 8192 kB, bootblocksize 0, romsize 4784128, offset 0x420040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x420040 raw 416
ddr.mbn 0x420240 raw 25836
rpm.mbn 0x426780 raw 78576
tz.mbn 0x439ac0 raw 85360
fallback/verstage 0x44e880 stage 41620
fallback/romstage 0x458b80 stage 19556
fallback/ramstage 0x45d840 stage 25579
config 0x463c80 raw 2878
fallback/payload 0x464800 payload 64811
u-boot.dtb 0x474580 (unknown) 2993
(empty) 0x475180 null 110168
$ cbfstool storm.bin remove -n config -H 0x420000
$ cbfstool storm.bin copy -H 0x420000 -D 0x620000 -s 0x70000
$ cbfstool storm.bin print -H 0x620000
storm.bin: 8192 kB, bootblocksize 0, romsize 6881280, offset 0x620040
alignment: 64 bytes, architecture: arm
Name Offset Type Size
cdt.mbn 0x620040 raw 416
ddr.mbn 0x620240 raw 25836
rpm.mbn 0x626780 raw 78576
tz.mbn 0x639ac0 raw 85360
fallback/verstage 0x64e880 stage 41620
fallback/romstage 0x658b80 stage 19556
fallback/ramstage 0x65d840 stage 25579
fallback/payload 0x663c80 payload 64811
u-boot.dtb 0x673a00 (unknown) 2993
(empty) 0x674600 null 113112
$ cbfstool /build/storm/firmware/image.serial.bin extract -n fallback/payload -f payload1
[..]
$ cbfstool storm.bin extract -H 0x620000 -n fallback/payload -f payload2
[..]
$ diff payload1 payload2
Change-Id: Ieb9205848aec361bb870de0d284dff06c597564f
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: b8d3c1b09a47ca24d2d2effc6de0e89d1b0a8903
Original-Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Change-Id: I227e607ccf7a9a8e2a1f3c6bbc506b8d29a35b1b
Original-Reviewed-on: https://chromium-review.googlesource.com/237561
Reviewed-on: http://review.coreboot.org/9742
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-12-24 04:26:54 +01:00
|
|
|
case 'D':
|
|
|
|
param.copyoffset = strtoul(optarg, NULL, 0);
|
|
|
|
param.copyoffset_assigned = 1;
|
2015-01-09 01:36:35 +01:00
|
|
|
break;
|
2012-10-30 00:52:36 +01:00
|
|
|
case 'a':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.alignment = strtoul(optarg, NULL, 0);
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
2013-03-19 05:17:12 +01:00
|
|
|
case 'P':
|
|
|
|
param.pagesize = strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
2012-10-30 00:52:36 +01:00
|
|
|
case 'o':
|
2014-11-10 22:14:24 +01:00
|
|
|
param.cbfsoffset = strtoul(optarg, NULL, 0);
|
|
|
|
param.cbfsoffset_assigned = 1;
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
|
|
|
case 'f':
|
2013-01-28 07:23:49 +01:00
|
|
|
param.filename = optarg;
|
2012-10-30 00:52:36 +01:00
|
|
|
break;
|
2013-07-09 19:39:13 +02:00
|
|
|
case 'i':
|
|
|
|
param.u64val = strtoull(optarg, NULL, 0);
|
|
|
|
break;
|
2013-01-28 20:46:02 +01:00
|
|
|
case 'T':
|
|
|
|
param.top_aligned = 1;
|
|
|
|
break;
|
2012-12-15 00:16:21 +01:00
|
|
|
case 'x':
|
|
|
|
param.fit_empty_entries = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
2012-10-30 00:52:36 +01:00
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
2012-11-16 23:48:22 +01:00
|
|
|
case 'm':
|
2014-02-03 05:37:28 +01:00
|
|
|
param.arch = string_to_arch(optarg);
|
2012-11-16 23:48:22 +01:00
|
|
|
break;
|
2013-08-27 20:22:21 +02:00
|
|
|
case 'I':
|
|
|
|
param.initrd = optarg;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
param.cmdline = optarg;
|
|
|
|
break;
|
2014-10-30 19:44:20 +01:00
|
|
|
case 'S':
|
|
|
|
param.ignore_section = optarg;
|
|
|
|
break;
|
2012-10-30 00:52:36 +01:00
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return commands[i].function();
|
2009-09-22 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
2013-01-28 07:39:43 +01:00
|
|
|
ERROR("Unknown command '%s'.\n", cmd);
|
2012-10-30 00:52:36 +01:00
|
|
|
usage(argv[0]);
|
2009-09-22 17:58:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|