Commit d97d7b17 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

software/vme-flasher: SPI bugfixes. Extended space for the bitstream to 6MB

parent 751778e7
......@@ -15,13 +15,14 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <libvmebus.h>
//#include <libsdbfs.h>
#include "sxldr_regs.h"
#define BOOTLOADER_BASE 0x70000
#define BOOTLOADER_VERSION 2
#define BOOTLOADER_BITSTREAM_BASE 0x100000
#define BOOTLOADER_SDB_BASE 0x500000
#define BOOTLOADER_SDB_BASE 0x600000
#define ID_M25P128 0x202018
......@@ -42,20 +43,24 @@
#define FLASH_BE 0xC7
/* SDB filesystem header. Fixed for the time being, the final version should simply use libsdbfs. */
const uint8_t sdb_header[] =
{ 0x53, 0x44, 0x42, 0x2d, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xce, 0x42, 0x00, 0x00, 0x5f, 0xec, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xff,
0xff, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x61, 0x66, 0x70, 0x67, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x61, 0x66, 0x70, 0x67, 0x61, 0x2e, 0x62, 0x69, 0x6e,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x33, 0x93, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x73, 0x66,
0x70, 0x67, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x73, 0x66, 0x70, 0x67, 0x61,
0x2e, 0x62, 0x69, 0x6e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01 };
const uint8_t sdb_header[] = {
0x53, 0x44, 0x42, 0x2d, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0x42, 0x00, 0x00, 0x5f, 0xec,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x2c, 0x13, 0xe9, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61,
0x61, 0x66, 0x70, 0x67, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x61, 0x66, 0x70, 0x67, 0x61, 0x2e, 0x62, 0x69, 0x6e, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x33, 0x93, 0x46, 0x69, 0x6c, 0x65,
0x44, 0x61, 0x74, 0x61, 0x62, 0x6f, 0x6f, 0x74, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x62, 0x6f, 0x6f, 0x74, 0x6c, 0x64, 0x72, 0x2e,
0x62, 0x69, 0x6e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01
};
struct vme_mapping map;
void *vme_va;
......@@ -107,15 +112,6 @@ void enter_bootloader()
Done\" LED next to the fuses should be on).\n");
exit(-1);
}
uint32_t cr = csr_readl(SXLDR_REG_CSR);
if (SXLDR_CSR_VERSION_R(cr) != BOOTLOADER_VERSION) {
fprintf(stderr,
"The bootloader is too old. Please update it according to the instructions at:\
http://www.ohwr.org/projects/svec/documents/XXX.\n");
exit(-1);
}
}
void spi_cs(int cs)
......@@ -207,6 +203,8 @@ void flash_program_page(uint32_t addr, const uint8_t * data, int size)
spi_write8(addr & 0x00ff); /* Address to start writing (LSB) */
for (i = 0; i < size; i++)
spi_write8(data[i]);
for (; i < FLASH_PAGE_SIZE; i++)
spi_write8(0xff);
spi_cs(0);
flash_wait_completion();
}
......@@ -224,6 +222,8 @@ void flash_program(uint32_t addr, const uint8_t * data, int size)
if (!sector_map[sector]) {
flash_write_enable();
fprintf(stderr, "Erasing sector 0x%x \r",
addr + n);
flash_erase_sector(addr + n);
sector_map[sector] = 1;
}
......@@ -231,7 +231,7 @@ void flash_program(uint32_t addr, const uint8_t * data, int size)
flash_write_enable();
flash_program_page(addr + n, data + n, plen);
fprintf(stderr, "Programming page %d/%d. \r",
fprintf(stderr, "Programming page %d/%d. \r",
n / FLASH_PAGE_SIZE,
(size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE - 1);
......@@ -251,11 +251,11 @@ void flash_program(uint32_t addr, const uint8_t * data, int size)
fprintf(stderr,
"Verification failed at offset 0x%06x (is: 0x%02x, should be: 0x%02x)\n.",
addr + n, d, *p);
spi_cs(1);
spi_cs(0);
exit(-1);
}
}
spi_cs(1);
spi_cs(0);
}
......@@ -292,12 +292,13 @@ int main(int argc, char *argv[])
enter_bootloader();
if (flash_read_id() != ID_M25P128) {
fprintf(stderr, "Flash memory ID invalid.\n");
fprintf(stderr,
"Flash memory ID invalid. You are probably be running an old version of the bootloader that doesn't support flash programming via VME.\n");
exit(-1);
}
flash_program(BOOTLOADER_BITSTREAM_BASE, buf, size);
flash_program(BOOTLOADER_SDB_BASE, sdb_header, sizeof(sdb_header));
flash_program(BOOTLOADER_BITSTREAM_BASE, buf, size);
free(buf);
printf("Programming OK.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment