Stefan Reinauer submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Patrick Georgi: Looks good to me, approved
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
Reviewed-on: https://review.coreboot.org/c/em100/+/36836
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
---
M em100.h
M firmware.c
2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/em100.h b/em100.h
index 2159fba..9ebcb13 100644
--- a/em100.h
+++ b/em100.h
@@ -29,6 +29,10 @@
uint8_t hwversion;
};

+/* Hardware versions */
+#define HWVERSION_EM100PRO 4
+#define HWVERSION_EM100PRO_G2 6
+
#define BULK_SEND_TIMEOUT 5000 /* sentinel value */

/* usb.c */
diff --git a/firmware.c b/firmware.c
index c88011c..6e2ff36 100644
--- a/firmware.c
+++ b/firmware.c
@@ -119,12 +119,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 HWVERSION_EM100PRO:
+ 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)
@@ -156,7 +166,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);
@@ -192,6 +203,16 @@
char fpga_version[MAX_VERSION_LENGTH + 1],
mcu_version[MAX_VERSION_LENGTH + 1];

+ switch (em100->hwversion) {
+ case HWVERSION_EM100PRO:
+ 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");
@@ -223,8 +244,8 @@
}
fclose(f);

- if (memcmp(fw, "em100pro", 8) != 0 ||
- memcmp(fw + 0x28, "WFPD", 4) != 0) {
+ if (em100->hwversion == HWVERSION_EM100PRO && (memcmp(fw, "em100pro", 8) != 0 ||
+ memcmp(fw + 0x28, "WFPD", 4) != 0)) {
printf("ERROR: Not an EM100Pro firmware file.\n");
free(fw);
return 0;

To view, visit change 36836. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: em100
Gerrit-Branch: master
Gerrit-Change-Id: Ia284adca4cb4d341a8d229374b6ea0b5d2a5d5c0
Gerrit-Change-Number: 36836
Gerrit-PatchSet: 3
Gerrit-Owner: Stefan Reinauer <stefan.reinauer@coreboot.org>
Gerrit-Reviewer: Furquan Shaikh <furquan@google.com>
Gerrit-Reviewer: Martin Roth <martinroth@google.com>
Gerrit-Reviewer: Patrick Georgi <pgeorgi@google.com>
Gerrit-Reviewer: Stefan Reinauer <stefan.reinauer@coreboot.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged