ifdtool: Add option to specify platform (-p) quirks

Apollo Lake uses yet another descriptor format where only two masters
are used: CPU/BIOS and CSE/TXE. CSE stores data in a region number 5
that has not been used previously and CPU must not write it. Add quirk
(-p aplk) that locks descriptor according to recommended values.

BUG=chrome-os-partner:58974
TEST=ifdtool -p aplk -l bios.bin; ifdtool -d bios.bin.new. Make sure
FLMSTR1 and FLMSTR2 are set correctly. unlock with -l and make sure
FLMSTRs are restored.

Change-Id: I3f33372bef3ff75d0e34030694c79cd07d5540de
Signed-off-by: Andrey Petrov <andrey.petrov@intel.com>
Reviewed-on: https://review.coreboot.org/17202
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Andrey Petrov 2016-10-31 19:31:54 -07:00 committed by Martin Roth
parent 8a3514d0ae
commit 96ecb77905
2 changed files with 43 additions and 13 deletions

View File

@ -30,6 +30,7 @@
static int ifd_version; static int ifd_version;
static int max_regions = 0; static int max_regions = 0;
static int selected_chip = 0; static int selected_chip = 0;
static int platform = -1;
static const struct region_name region_names[MAX_REGIONS] = { static const struct region_name region_names[MAX_REGIONS] = {
{ "Flash Descriptor", "fd" }, { "Flash Descriptor", "fd" },
@ -832,18 +833,32 @@ static void lock_descriptor(char *filename, char *image, int size)
fmba->flmstr3 = 0x118; fmba->flmstr3 = 0x118;
} }
/* CPU/BIOS can read descriptor, BIOS, and GbE. */ switch (platform) {
fmba->flmstr1 |= 0xb << rd_shift; case PLATFORM_APOLLOLAKE:
/* CPU/BIOS can write BIOS and GbE. */ /* CPU/BIOS can read descriptor and BIOS */
fmba->flmstr1 |= 0xa << wr_shift; fmba->flmstr1 |= 0x3 << rd_shift;
/* ME can read descriptor, ME, and GbE. */ /* CPU/BIOS can write BIOS */
fmba->flmstr2 |= 0xd << rd_shift; fmba->flmstr1 |= 0x2 << wr_shift;
/* ME can write ME and GbE. */ /* TXE can read descriptor, BIOS and Device Expansion */
fmba->flmstr2 |= 0xc << wr_shift; fmba->flmstr2 |= 0x23 << rd_shift;
/* GbE can write only GbE. */ /* TXE can only write Device Expansion */
fmba->flmstr3 |= 0x8 << rd_shift; fmba->flmstr2 |= 0x20 << wr_shift;
/* GbE can read only GbE. */ break;
fmba->flmstr3 |= 0x8 << wr_shift; default:
/* CPU/BIOS can read descriptor, BIOS, and GbE. */
fmba->flmstr1 |= 0xb << rd_shift;
/* CPU/BIOS can write BIOS and GbE. */
fmba->flmstr1 |= 0xa << wr_shift;
/* ME can read descriptor, ME, and GbE. */
fmba->flmstr2 |= 0xd << rd_shift;
/* ME can write ME and GbE. */
fmba->flmstr2 |= 0xc << wr_shift;
/* GbE can write only GbE. */
fmba->flmstr3 |= 0x8 << rd_shift;
/* GbE can read only GbE. */
fmba->flmstr3 |= 0x8 << wr_shift;
break;
}
write_image(filename, image, size); write_image(filename, image, size);
} }
@ -1140,6 +1155,8 @@ static void print_usage(const char *name)
" Dual Output Fast Read Support\n" " Dual Output Fast Read Support\n"
" -l | --lock Lock firmware descriptor and ME region\n" " -l | --lock Lock firmware descriptor and ME region\n"
" -u | --unlock Unlock firmware descriptor and ME region\n" " -u | --unlock Unlock firmware descriptor and ME region\n"
" -p | --platform Add platform-specific quirks\n"
" aplk - Apollo Lake\n"
" -v | --version: print the version\n" " -v | --version: print the version\n"
" -h | --help: print this help\n\n" " -h | --help: print this help\n\n"
"<region> is one of Descriptor, BIOS, ME, GbE, Platform\n" "<region> is one of Descriptor, BIOS, ME, GbE, Platform\n"
@ -1171,10 +1188,11 @@ int main(int argc, char *argv[])
{"unlock", 0, NULL, 'u'}, {"unlock", 0, NULL, 'u'},
{"version", 0, NULL, 'v'}, {"version", 0, NULL, 'v'},
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"platform", 0, NULL, 'p'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while ((opt = getopt_long(argc, argv, "df:D:C:xi:n:s:eluvh?", while ((opt = getopt_long(argc, argv, "df:D:C:xi:n:s:p:eluvh?",
long_options, &option_index)) != EOF) { long_options, &option_index)) != EOF) {
switch (opt) { switch (opt) {
case 'd': case 'd':
@ -1325,6 +1343,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;
case 'p':
if (!strcmp(optarg, "aplk")) {
platform = PLATFORM_APOLLOLAKE;
} else {
fprintf(stderr, "Unknown platform: %s\n", optarg);
exit(EXIT_FAILURE);
}
break;
case 'v': case 'v':
print_version(); print_version();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -21,6 +21,10 @@ enum ifd_version {
IFD_VERSION_2, IFD_VERSION_2,
}; };
enum platform {
PLATFORM_APOLLOLAKE
};
#define LAYOUT_LINELEN 80 #define LAYOUT_LINELEN 80
enum spi_frequency { enum spi_frequency {