summaryrefslogtreecommitdiff
path: root/board/scalys/grapeboard/board_configuration_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/scalys/grapeboard/board_configuration_data.c')
-rw-r--r--board/scalys/grapeboard/board_configuration_data.c92
1 files changed, 32 insertions, 60 deletions
diff --git a/board/scalys/grapeboard/board_configuration_data.c b/board/scalys/grapeboard/board_configuration_data.c
index bd6a04e..4daff4f 100644
--- a/board/scalys/grapeboard/board_configuration_data.c
+++ b/board/scalys/grapeboard/board_configuration_data.c
@@ -58,8 +58,6 @@ int add_mac_addressess_to_env(const void* blob)
memcpy(mac_address, value, 6);
- /* ret = fdtdec_get_byte_array( blob, prop_offset, propname, mac_address, 6 ); */
-
if (count) {
snprintf(eth_string, sizeof(eth_string), "eth%iaddr", count);
}
@@ -88,63 +86,34 @@ int add_mac_addressess_to_env(const void* blob)
const void* get_boardinfo_rescue_flash(void)
{
struct ccsr_gpio *pgpio = (void *)(CONFIG_SYS_GPIO2);
- struct spi_flash *flash;
- uint32_t bcd_data_lenght;
+ uint32_t bcd_data_length;
uint8_t *bcd_data = NULL;
uint32_t calculated_crc, received_crc;
int dtb_length;
int ret = 0;
+ struct udevice *rescue_flash_dev,*bus_dev;
unsigned int bus = 0;
unsigned int cs = 0;
- unsigned int speed = 10000000;
- unsigned int mode = SPI_MODE_0;
-
-#ifdef CONFIG_DM_SPI_FLASH
- struct udevice *new, *bus_dev;
- /* In DM mode defaults will be taken from DT */
- speed = 0, mode = 0;
-#else
- struct spi_flash *new;
-#endif
+ unsigned int speed = 0;
+ unsigned int mode = 0;
/* Change chip select to rescue QSPI NOR flash */
setbits_be32(&pgpio->gpdir, QSPI_MUX_N_MASK);
setbits_be32(&pgpio->gpdat, QSPI_MUX_N_MASK);
-#ifdef CONFIG_DM_SPI_FLASH
- /* Remove the old device, otherwise probe will just be a nop */
- ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
+ ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &rescue_flash_dev);
if (!ret) {
- device_remove(new, DM_REMOVE_NORMAL);
+ device_remove(rescue_flash_dev, DM_REMOVE_NORMAL);
}
- flash = NULL;
- ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
- if (ret) {
- printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
- bus, cs, ret);
- return NULL;
- }
-
- flash = dev_get_uclass_priv(new);
-#else
- if (flash)
- spi_flash_free(flash);
-
- new = spi_flash_probe(bus, cs, speed, mode);
- flash = new;
-
- if (!new) {
- printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
- return NULL;
+ ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &rescue_flash_dev);
+ if (ret != 0) {
+ printf("probe failed\n");
}
- flash = new;
-#endif
-
/* Read the last 4 bytes to determine the length of the DTB data */
- ret = spi_flash_read(flash, (BCD_FLASH_SIZE-4), 4, (uint8_t*) &bcd_data_lenght);
+ ret = spi_flash_read_dm(rescue_flash_dev, (BCD_FLASH_SIZE-4), 4, (uint8_t*) &bcd_data_length);
if (ret != 0) {
printf("Error reading bcd length\n");
errno = -ENODEV;
@@ -152,54 +121,57 @@ const void* get_boardinfo_rescue_flash(void)
}
/* Convert length from big endianess to architecture endianess */
- bcd_data_lenght = ntohl(bcd_data_lenght);
- printf("bcd_data_lenght = %i\n", bcd_data_lenght );
+ bcd_data_length = ntohl(bcd_data_length);
+ printf("bcd_data_lenght = %i\n", bcd_data_length );
- if (bcd_data_lenght > BCD_FLASH_SIZE ) {
+ if (bcd_data_length > BCD_FLASH_SIZE ) {
printf("BCD data length error %02x %02x %02x %02x\n",
- ( (uint8_t*) &bcd_data_lenght)[0],
- ( (uint8_t*) &bcd_data_lenght)[1],
- ( (uint8_t*) &bcd_data_lenght)[2],
- ( (uint8_t*) &bcd_data_lenght)[3] );
+ ( (uint8_t*) &bcd_data_length)[0],
+ ( (uint8_t*) &bcd_data_length)[1],
+ ( (uint8_t*) &bcd_data_length)[2],
+ ( (uint8_t*) &bcd_data_length)[3] );
errno = -EMSGSIZE;
goto err_no_free;
}
-
+
/* Allocate, and verify memory for the BCD data */
- bcd_data = (uint8_t*) malloc(bcd_data_lenght);
+ bcd_data = (uint8_t*) malloc(bcd_data_length);
if (bcd_data == NULL) {
printf("Error locating memory for BCD data\n");
goto err_no_free;
}
printf("Allocated memory for BCD data\n");
-
+
/* Read the DTB BCD data to memory */
- ret = spi_flash_read(flash, (BCD_FLASH_SIZE-bcd_data_lenght), bcd_data_lenght, (uint8_t*) &bcd_data);
- printf("Read data from I2C bus\n");
+ ret = spi_flash_read_dm(rescue_flash_dev, (BCD_FLASH_SIZE-bcd_data_length), bcd_data_length, (uint8_t*) bcd_data);
+ printf("Read data from QSPI bus\n");
if (ret != 0) {
printf("Error reading complete BCD data from EEPROM\n");
errno = -ENOMEM;
goto err_free;
}
- dtb_length = bcd_data_lenght - BCD_LENGTH_SIZE - BCD_HASH_SIZE;
-
+ dtb_length = bcd_data_length - BCD_LENGTH_SIZE - BCD_HASH_SIZE;
+
/* Calculate CRC on read DTB data */
calculated_crc = crc32( 0, bcd_data, dtb_length);
-
+
/* Received CRC is packed after the DTB data */
received_crc = *((uint32_t*) &bcd_data[dtb_length]);
-
+
/* Convert CRC from big endianess to architecture endianess */
received_crc = ntohl(received_crc);
-
+
if (calculated_crc != received_crc) {
printf("Checksum error. expected %08x, got %08x\n",
calculated_crc, received_crc);
errno = -EBADMSG;
goto err_free;
}
-
+
+ /* Revert chip select muxing to standard QSPI flash */
+ clrbits_be32(&pgpio->gpdat, QSPI_MUX_N_MASK);
+
/* Everything checked out, return the BCD data.
* The caller is expected to free this data */
return bcd_data;
@@ -209,7 +181,7 @@ err_free:
free(bcd_data);
err_no_free:
- /* Revert chip select for standard QSPI flash */
+ /* Revert chip select muxing to standard QSPI flash */
clrbits_be32(&pgpio->gpdat, QSPI_MUX_N_MASK);
return NULL;