Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/35947 )
Change subject: em100: Detect emulated flash chip ......................................................................
em100: Detect emulated flash chip
It's not clear why uploads (EM100 to host) generate a 64MiB ROM file. It turns out that the flash chip needs to be specified at the command line, which isn't intentional.
Detect the currently emulated SPI and use the size as defined in flashchips.
Tested on EM100Pro, will now upload ROM files matching the currently emulated target even without specifying the flash chip on the command line.
Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com Change-Id: Ia3fb3034a195313b8d3bb4ce24dc1779058fd08f --- M em100.c 1 file changed, 56 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/47/35947/1
diff --git a/em100.c b/em100.c index 1548450..a20dc7d 100644 --- a/em100.c +++ b/em100.c @@ -567,6 +567,51 @@ return !result; }
+static int get_chip_init_val(const chipdesc *desc, + const uint8_t reg1, + const uint8_t reg2, + uint16_t *out) +{ + int i; + for (i = 0; i < desc->init_len; i++) { + if (desc->init[i][0] == reg1 && desc->init[i][1] == reg2) { + *out = (desc->init[i][2] << 8) | desc->init[i][3]; + return 1; + } + } + return 0; +} + +static int get_chip_type(struct em100 *em100, const chipdesc **out) +{ + uint16_t manu; + uint16_t vend; + + /* Read manufacturer and vendor id from FPGA */ + if (!read_fpga_register(em100, 0x42, &manu)) + return 1; + if (!read_fpga_register(em100, 0x40, &vend)) + return 1; + + const chipdesc *chip = chips; + do { + uint16_t comp; + if (!get_chip_init_val(chip, 0x23, 0x40, &comp) || vend != comp) + continue; + if (!get_chip_init_val(chip, 0x23, 0x42, &comp) || manu != comp) + continue; + + break; + } while ((++chip)->name); + if (!chip->name) + return 1; + + printf("Configured to emulate %s\n", chip->name); + *out = chip; + + return 0; +} + static const struct option longopts[] = { {"set", 1, 0, 'c'}, {"download", 1, 0, 'd'}, @@ -822,8 +867,17 @@ }
if (read_filename) { - /* largest size - 64MB */ - int maxlen = desiredchip ? chip->size : 0x4000000; + int maxlen = 0x4000000; /* largest size - 64MB */ + + if (!desiredchip) { + /* Read configured SPI emulation from EM100 */ + const chipdesc *current; + if (!get_chip_type(&em100, ¤t)) + maxlen = current->size; + } else { + maxlen = chip->size; + } + void *data = malloc(maxlen); if (data == NULL) { printf("FATAL: couldn't allocate memory\n");