Add 'recovery_key' in Google Binary Block (GBB) utility

Review URL: http://codereview.chromium.org/2553001
This commit is contained in:
Hung-Te Lin
2010-06-03 14:35:47 -07:00
parent 96ee63bbf3
commit 08dc5f381d
3 changed files with 32 additions and 15 deletions

View File

@@ -257,7 +257,18 @@ bool GoogleBinaryBlockUtil::find_property(PROPINDEX i,
*pname = "bmp_fv";
break;
case PROP_RCVKEY:
*poffset = header_.recovery_key_offset;;
*psize = header_.recovery_key_size;
if (pname)
*pname = "recovery_key";
break;
default:
if (verbose) {
fprintf(stderr, " internal error: unknown property (%d).\n",
static_cast<int>(i));
}
assert(!"invalid property index.");
return false;
}
@@ -272,12 +283,8 @@ bool GoogleBinaryBlockUtil::set_property(PROPINDEX i, const string &value) {
assert(is_valid_gbb);
if (!find_property(i, &prop_offset, &prop_size, &prop_name)) {
if (verbose)
fprintf(stderr, " internal error: unknown property (%d).\n",
static_cast<int>(i));
if (!find_property(i, &prop_offset, &prop_size, &prop_name))
return false;
}
if (prop_size < value.size()) {
if (verbose)
@@ -308,12 +315,8 @@ string GoogleBinaryBlockUtil::get_property(PROPINDEX i) const {
assert(is_valid_gbb);
if (!find_property(i, &prop_offset, &prop_size, &prop_name)) {
if (verbose)
fprintf(stderr, " internal error: unknown property (%d).\n",
static_cast<int>(i));
if (!find_property(i, &prop_offset, &prop_size, &prop_name))
return "";
}
// check range again to allow empty value (for compatbility)
if (prop_offset == 0 && prop_size == 0) {
@@ -333,9 +336,6 @@ string GoogleBinaryBlockUtil::get_property_name(PROPINDEX i) const {
const char *prop_name;
if (!find_property(i, &unused_off, &unused_size, &prop_name)) {
if (verbose)
fprintf(stderr, " internal error: unknown property (%d).\n",
static_cast<int>(i));
assert(!"invalid property index.");
return "";
}
@@ -355,6 +355,10 @@ bool GoogleBinaryBlockUtil::set_bmpfv(const string &value) {
return set_property(PROP_BMPFV, value);
}
bool GoogleBinaryBlockUtil::set_recovery_key(const string &value) {
return set_property(PROP_RCVKEY, value);
}
} // namespace vboot_reference
#ifdef WITH_UTIL_MAIN
@@ -378,6 +382,7 @@ static void usagehelp_exit(const char *prog_name) {
" --hwid \tReport hardware id (default).\n"
" -k, --rootkey=FILE \tFile name to export Root Key.\n"
" -b, --bmpfv=FILE \tFile name to export Bitmap FV.\n"
" --recoverykey=FILE\tFile name to export Recovery Key.\n"
"\n"
"SET MODE:\n"
"-s, --set \tSet (write) to bios_file, "
@@ -386,6 +391,7 @@ static void usagehelp_exit(const char *prog_name) {
" -i, --hwid=HWID \tThe new hardware id to be changed.\n"
" -k, --rootkey=FILE \tFile name of new Root Key.\n"
" -b, --bmpfv=FILE \tFile name of new Bitmap FV.\n"
" --recoverykey=FILE\tFile name of new Recovery Key.\n"
"\n"
"SAMPLE:\n"
" %s -g bios.bin\n"
@@ -490,6 +496,7 @@ int main(int argc, char *argv[]) {
{"hwid", 2, NULL, 'i' },
{"rootkey", 1, NULL, 'k' },
{"bmpfv", 1, NULL, 'b' },
{"recoverykey", 1, NULL, 'R' },
{ NULL, 0, NULL, 0 },
};
@@ -527,6 +534,12 @@ int main(int argc, char *argv[]) {
usagehelp_exit(myname);
break;
case 'R':
if (!opt_props.set_new_value(
GoogleBinaryBlockUtil::PROP_RCVKEY, optarg))
usagehelp_exit(myname);
break;
default:
case '?':
usagehelp_exit(myname);

View File

@@ -18,6 +18,7 @@ class GoogleBinaryBlockUtil {
PROP_HWID, // hardware id
PROP_ROOTKEY, // root key
PROP_BMPFV, // bitmap FV
PROP_RCVKEY, // recovery key
PROP_RANGE, // indicator of valid property range
};
@@ -48,9 +49,11 @@ class GoogleBinaryBlockUtil {
bool set_hwid(const char *hwid); // NOTE: hwid is NUL-terminated.
bool set_rootkey(const std::string &value);
bool set_bmpfv(const std::string &value);
bool set_recovery_key(const std::string &value);
std::string get_hwid() const { return get_property(PROP_HWID); }
std::string get_rootkey() const { return get_property(PROP_ROOTKEY); }
std::string get_bmpfv() const { return get_property(PROP_BMPFV); }
std::string get_recovery_key() const { return get_property(PROP_RCVKEY); }
private:
// clear all cached data and initialize to original state

View File

@@ -35,8 +35,10 @@ typedef struct GoogleBinaryBlockHeader {
uint32_t rootkey_size; // Root Key size in bytes
uint32_t bmpfv_offset; // BMP FV offset from header
uint32_t bmpfv_size; // BMP FV size in bytes
uint32_t recovery_key_offset; // Recovery Key offset from header
uint32_t recovery_key_size; // Recovery Key size in bytes
uint8_t pad[88]; // to match GBB_HEADER_SIZE
uint8_t pad[80]; // to match GBB_HEADER_SIZE
} GoogleBinaryBlockHeader;
#ifdef __cplusplus
@@ -44,4 +46,3 @@ typedef struct GoogleBinaryBlockHeader {
#endif // __cplusplus
#endif /* VBOOT_REFERENCE_GBB_HEADER_H_ */