Commit 78e6962d authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana Committed by Grzegorz Daniluk

Some changes in file formatting and flash-write malloc

Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent cb72b87c
...@@ -51,19 +51,16 @@ ...@@ -51,19 +51,16 @@
/* /*
* Bit-bang SPI transfer function * Bit-bang SPI transfer function
*/ */
static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) static uint8_t bbspi_transfer(int cspin, uint8_t val)
{ {
uint8_t i, retval = 0; int i, retval = 0;
gpio_out(GPIO_SPI_NCS, cspin); gpio_out(GPIO_SPI_NCS, cspin);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++) {
{
gpio_out(GPIO_SPI_SCLK, 0); gpio_out(GPIO_SPI_SCLK, 0);
if (val & 0x80) if (val & 0x80) {
{
gpio_out(GPIO_SPI_MOSI, 1); gpio_out(GPIO_SPI_MOSI, 1);
} }
else else {
{
gpio_out(GPIO_SPI_MOSI, 0); gpio_out(GPIO_SPI_MOSI, 0);
} }
gpio_out(GPIO_SPI_SCLK, 1); gpio_out(GPIO_SPI_SCLK, 1);
...@@ -101,8 +98,7 @@ int flash_write(uint32_t addr, uint8_t *buf, int count) ...@@ -101,8 +98,7 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
bbspi_transfer(0,(addr & 0xFF0000) >> 16); bbspi_transfer(0,(addr & 0xFF0000) >> 16);
bbspi_transfer(0,(addr & 0xFF00) >> 8); bbspi_transfer(0,(addr & 0xFF00) >> 8);
bbspi_transfer(0,(addr & 0xFF)); bbspi_transfer(0,(addr & 0xFF));
for ( i = 0; i < count; i++ ) for ( i = 0; i < count; i++ ) {
{
bbspi_transfer(0,buf[i]); bbspi_transfer(0,buf[i]);
} }
bbspi_transfer(1,0); bbspi_transfer(1,0);
...@@ -122,8 +118,7 @@ int flash_read(uint32_t addr, uint8_t *buf, int count) ...@@ -122,8 +118,7 @@ int flash_read(uint32_t addr, uint8_t *buf, int count)
bbspi_transfer(0,(addr & 0xFF00) >> 8); bbspi_transfer(0,(addr & 0xFF00) >> 8);
bbspi_transfer(0,(addr & 0xFF)); bbspi_transfer(0,(addr & 0xFF));
bbspi_transfer(0,0); bbspi_transfer(0,0);
for ( i = 0; i < count; i++ ) for ( i = 0; i < count; i++ ) {
{
buf[i] = bbspi_transfer(0, 0); buf[i] = bbspi_transfer(0, 0);
} }
bbspi_transfer(1,0); bbspi_transfer(1,0);
...@@ -225,14 +220,12 @@ int flash_sdb_check() ...@@ -225,14 +220,12 @@ int flash_sdb_check()
uint32_t entry_point[6] = {0x000000, 0x100, 0x200, 0x300, 0x170000, 0x2e0000}; uint32_t entry_point[6] = {0x000000, 0x100, 0x200, 0x300, 0x170000, 0x2e0000};
for (i = 0; i < ARRAY_SIZE(entry_point); i++) for (i = 0; i < ARRAY_SIZE(entry_point); i++) {
{
flash_read(entry_point[i], (uint8_t *)&magic, 4); flash_read(entry_point[i], (uint8_t *)&magic, 4);
if (magic == SDB_MAGIC) if (magic == SDB_MAGIC)
break; break;
} }
if (magic == SDB_MAGIC) if (magic == SDB_MAGIC) {
{
mprintf("Found SDB magic at address 0x%06X!\n", entry_point[i]); mprintf("Found SDB magic at address 0x%06X!\n", entry_point[i]);
wrc_sdb.drvdata = NULL; wrc_sdb.drvdata = NULL;
wrc_sdb.entrypoint = entry_point[i]; wrc_sdb.entrypoint = entry_point[i];
......
...@@ -83,15 +83,12 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) ...@@ -83,15 +83,12 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val)
{ {
uint8_t i, retval = 0; uint8_t i, retval = 0;
gpio_out(GPIO_SPI_NCS, cspin); gpio_out(GPIO_SPI_NCS, cspin);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++) {
{
gpio_out(GPIO_SPI_SCLK, 0); gpio_out(GPIO_SPI_SCLK, 0);
if (val & 0x80) if (val & 0x80) {
{
gpio_out(GPIO_SPI_MOSI, 1); gpio_out(GPIO_SPI_MOSI, 1);
} }
else else {
{
gpio_out(GPIO_SPI_MOSI, 0); gpio_out(GPIO_SPI_MOSI, 0);
} }
gpio_out(GPIO_SPI_SCLK, 1); gpio_out(GPIO_SPI_SCLK, 1);
...@@ -130,8 +127,7 @@ int flash_write(uint32_t addr, uint8_t *buf, int count) ...@@ -130,8 +127,7 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
bbspi_transfer(0,(addr & 0xFF0000) >> 16); bbspi_transfer(0,(addr & 0xFF0000) >> 16);
bbspi_transfer(0,(addr & 0xFF00) >> 8); bbspi_transfer(0,(addr & 0xFF00) >> 8);
bbspi_transfer(0,(addr & 0xFF)); bbspi_transfer(0,(addr & 0xFF));
for ( i = 0; i < count; i++ ) for ( i = 0; i < count; i++ ) {
{
bbspi_transfer(0,buf[i]); bbspi_transfer(0,buf[i]);
} }
bbspi_transfer(1,0); bbspi_transfer(1,0);
...@@ -151,8 +147,7 @@ int flash_read(uint32_t addr, uint8_t *buf, int count) ...@@ -151,8 +147,7 @@ int flash_read(uint32_t addr, uint8_t *buf, int count)
bbspi_transfer(0,(addr & 0xFF00) >> 8); bbspi_transfer(0,(addr & 0xFF00) >> 8);
bbspi_transfer(0,(addr & 0xFF)); bbspi_transfer(0,(addr & 0xFF));
bbspi_transfer(0,0); bbspi_transfer(0,0);
for ( i = 0; i < count; i++ ) for ( i = 0; i < count; i++ ) {
{
buf[i] = bbspi_transfer(0, 0); buf[i] = bbspi_transfer(0, 0);
} }
bbspi_transfer(1,0); bbspi_transfer(1,0);
......
...@@ -82,9 +82,15 @@ extern void *BASE_SYSCON; ...@@ -82,9 +82,15 @@ extern void *BASE_SYSCON;
static int spec_write_flash(struct spec_device *spec, int addr, int len) static int spec_write_flash(struct spec_device *spec, int addr, int len)
{ {
uint8_t *buf = malloc(len);
int i, r, plen = len; int i, r, plen = len;
uint8_t *buf = malloc(len);
if (buf == NULL) {
fprintf(stderr, "Memory not available for write buffer!");
return -1;
}
BASE_SYSCON = spec->mapaddr + SPEC_SYSCON_OFFSET; BASE_SYSCON = spec->mapaddr + SPEC_SYSCON_OFFSET;
flash_init(); flash_init();
...@@ -104,9 +110,8 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len) ...@@ -104,9 +110,8 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
return 1; return 1;
} }
/* Let's some data to the flash */ /* Let's send some data to the flash */
while (len) while (len) {
{
/* Set write length */ /* Set write length */
i = len; i = len;
if (len > 256) if (len > 256)
...@@ -132,15 +137,14 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len) ...@@ -132,15 +137,14 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
} }
/* Write to flash */ /* Write to flash */
if (verbose) if (verbose) {
{
fprintf(stderr, "Writing %3i bytes at address 0x%06X\n", fprintf(stderr, "Writing %3i bytes at address 0x%06X\n",
i, addr); i, addr);
} }
flash_write(addr, buf, i); flash_write(addr, buf, i);
sleep(1); sleep(1);
/* FIXME: As above, RSR is a mistery... */ /* FIXME: As above, RSR is a mystery... */
// while (flash_rsr() & 0x01) // while (flash_rsr() & 0x01)
// ; // ;
...@@ -156,6 +160,8 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len) ...@@ -156,6 +160,8 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
// } // }
} }
free(buf);
return 0; return 0;
} }
...@@ -205,6 +211,7 @@ static int spec_scan_pci(struct spec_pci_id *id, struct spec_device *arr, ...@@ -205,6 +211,7 @@ static int spec_scan_pci(struct spec_pci_id *id, struct spec_device *arr,
unsigned v, d; unsigned v, d;
n = scandir("/sys/bus/pci/devices", &namelist, 0, 0); n = scandir("/sys/bus/pci/devices", &namelist, 0, 0);
if (n < 0) { if (n < 0) {
fprintf(stderr, "%s: /sys/bus/pci/devices: %s\n", prgname, fprintf(stderr, "%s: /sys/bus/pci/devices: %s\n", prgname,
strerror(errno)); strerror(errno));
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "shell.h" #include "shell.h"
#include "lib/ipv4.h" #include "lib/ipv4.h"
#include "rxts_calibrator.h" #include "rxts_calibrator.h"
#include "flash.h"
#include "wrc_ptp.h" #include "wrc_ptp.h"
...@@ -225,52 +224,13 @@ static void check_reset(void) {} ...@@ -225,52 +224,13 @@ static void check_reset(void) {}
#endif #endif
void w()
{
uint64_t i;
for (i=0;i<1024*1024*100;i++)
asm volatile ("nop");
}
int main(void) int main(void)
{ {
uint8_t rdat[256];
int i;
uint32_t addr;
check_reset(); check_reset();
wrc_ui_mode = UI_SHELL_MODE; wrc_ui_mode = UI_SHELL_MODE;
_endram = ENDRAM_MAGIC; _endram = ENDRAM_MAGIC;
sdb_find_devices();
uart_init_sw();
uart_init_hw();
timer_init(0);
mprintf("preinit\n");
w();
mprintf("flash init\n");
flash_init();
//#define ADDRSTART 0x100
//#define ADDRMAX 0x600
// addr = 0x100;
// mprintf("reading from 0x%06X to 0x%06X\n", addr, ADDRMAX);
// for (addr = ADDRSTART; addr < ADDRMAX; addr += 256)
// {
// flash_read(addr,rdat,256);
// for (i = 0; i < 256; i++)
// printf("0x%02X ", rdat[i]);
// printf("\n");
// }
// mprintf("done; current address 0x%06X\n", addr);
flash_sdb_check();
return 0;
wrc_initialize(); wrc_initialize();
usleep_init(); usleep_init();
shell_init(); shell_init();
......
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