Stefan Reinauer has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/36836 )
Change subject: Make firmware update hardware version aware ......................................................................
Make firmware update hardware version aware
Up to now, you can accidently write an EM100Pro firmware version on an EM100Pro-G2 device. This will brick your device and can not easily be recovered with a SPI flasher, so be careful. Hence, the firmware update code should make sure that HW version 4 is used to commence a firmware update.
Right now, release binaries do not contain EM100Pro-G2 firmware images, so this version of the code bails out on anything but HW version 4.
Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org Change-Id: Ia284adca4cb4d341a8d229374b6ea0b5d2a5d5c0 --- M firmware.c 1 file changed, 25 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/36/36836/1
diff --git a/firmware.c b/firmware.c index f5130f8..bbb0ca4 100644 --- a/firmware.c +++ b/firmware.c @@ -118,12 +118,22 @@ }
if (firmware_is_dpfw) { - int fpga_size = 0, mcu_size = 0; + int fpga_size = 0, mcu_size = 0, hdrversion = 0; char all_ff[256]; char mcu_version[8]; char fpga_version[8]; unsigned char header[0x100];
+ switch (em100->hwversion) { + case 4: + hdrversion=1; + break; + default: + printf("Dumping DPFW firmware on hardware version %u is " + "not yet supported.\n", em100->hwversion); + exit(1); + } + memset(all_ff, 255, sizeof(all_ff)); for (i = 0; i < 0x100000; i+=0x100) { if (memcmp(data+i, all_ff, 256) == 0) @@ -153,7 +163,8 @@ em100->fpga >> 8 & 0x7f, em100->fpga & 0xff);
memset(header, 0, 0x100); - memcpy(header, "em100pro", 8); + if (hdrversion == 1) + memcpy(header, "em100pro", 8); memcpy(header + 0x28, "WFPD", 4); memcpy(header + 0x14, mcu_version, 4); memcpy(header + 0x1e, fpga_version, 4); @@ -188,6 +199,16 @@ char fpga_version[MAX_VERSION_LENGTH + 1], mcu_version[MAX_VERSION_LENGTH + 1];
+ switch (em100->hwversion) { + case 4: + printf("Detected EM100Pro-G1.\n"); + break; + default: + printf("Updating EM100Pro firmware on hardware version %u is " + "not yet supported.\n", em100->hwversion); + exit(1); + } + printf("\nAttempting firmware update with file %s\n", filename);
f = fopen(filename, "rb"); @@ -219,8 +240,8 @@ } fclose(f);
- if (memcmp(fw, "em100pro", 8) != 0 || - memcmp(fw + 0x28, "WFPD", 4) != 0) { + if (em100->hwversion == 4 && (memcmp(fw, "em100pro", 8) != 0 || + memcmp(fw + 0x28, "WFPD", 4) != 0)) { printf("ERROR: Not an EM100Pro firmware file.\n"); free(fw); return 0;