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
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
* version: 1.0 * version: 1.0
* *
* description: * description:
* *
* dependencies: * dependencies:
* *
* references: * references:
* *
*============================================================================== *==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE * GNU LESSER GENERAL PUBLIC LICENSE
*============================================================================== *==============================================================================
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
* last changes: * last changes:
* 2013-09-25 Theodor Stana t.stana@cern.ch File created * 2013-09-25 Theodor Stana t.stana@cern.ch File created
*============================================================================== *==============================================================================
* TODO: - * TODO: -
*============================================================================== *==============================================================================
*/ */
#include "flash.h" #include "flash.h"
#include "types.h" #include "types.h"
#include "syscon.h" #include "syscon.h"
...@@ -51,30 +51,27 @@ ...@@ -51,30 +51,27 @@
/* /*
* 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 {
} gpio_out(GPIO_SPI_MOSI, 0);
else }
{ gpio_out(GPIO_SPI_SCLK, 1);
gpio_out(GPIO_SPI_MOSI, 0); retval <<= 1;
} retval |= gpio_in(GPIO_SPI_MISO);
gpio_out(GPIO_SPI_SCLK, 1); val <<= 1;
retval <<= 1; }
retval |= gpio_in(GPIO_SPI_MISO);
val <<= 1; gpio_out(GPIO_SPI_SCLK, 0);
}
return retval;
gpio_out(GPIO_SPI_SCLK, 0);
return retval;
} }
/* /*
...@@ -82,9 +79,9 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) ...@@ -82,9 +79,9 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val)
*/ */
void flash_init() void flash_init()
{ {
gpio_out(GPIO_SPI_NCS, 1); gpio_out(GPIO_SPI_NCS, 1);
gpio_out(GPIO_SPI_SCLK, 0); gpio_out(GPIO_SPI_SCLK, 0);
gpio_out(GPIO_SPI_MOSI, 0); gpio_out(GPIO_SPI_MOSI, 0);
} }
/* /*
...@@ -92,22 +89,21 @@ void flash_init() ...@@ -92,22 +89,21 @@ void flash_init()
*/ */
int flash_write(uint32_t addr, uint8_t *buf, int count) int flash_write(uint32_t addr, uint8_t *buf, int count)
{ {
int i; int i;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x06); bbspi_transfer(0,0x06);
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x02); bbspi_transfer(0,0x02);
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);
return count;
return count;
} }
/* /*
...@@ -115,20 +111,19 @@ int flash_write(uint32_t addr, uint8_t *buf, int count) ...@@ -115,20 +111,19 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
*/ */
int flash_read(uint32_t addr, uint8_t *buf, int count) int flash_read(uint32_t addr, uint8_t *buf, int count)
{ {
int i; int i;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x0b); bbspi_transfer(0,0x0b);
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));
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);
return count;
return count;
} }
/* /*
...@@ -136,14 +131,14 @@ int flash_read(uint32_t addr, uint8_t *buf, int count) ...@@ -136,14 +131,14 @@ int flash_read(uint32_t addr, uint8_t *buf, int count)
*/ */
void flash_serase(uint32_t addr) void flash_serase(uint32_t addr)
{ {
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x06); bbspi_transfer(0,0x06);
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0xD8); bbspi_transfer(0,0xD8);
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));
bbspi_transfer(1,0); bbspi_transfer(1,0);
} }
/* /*
...@@ -164,12 +159,12 @@ flash_berase() ...@@ -164,12 +159,12 @@ flash_berase()
*/ */
uint8_t flash_rsr() uint8_t flash_rsr()
{ {
uint8_t retval; uint8_t retval;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x05); bbspi_transfer(0,0x05);
retval = bbspi_transfer(0,0); retval = bbspi_transfer(0,0);
bbspi_transfer(1,0); bbspi_transfer(1,0);
return retval; return retval;
} }
...@@ -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];
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
* version: 1.0 * version: 1.0
* *
* description: * description:
* *
* dependencies: * dependencies:
* *
* references: * references:
* *
*============================================================================== *==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE * GNU LESSER GENERAL PUBLIC LICENSE
*============================================================================== *==============================================================================
...@@ -32,21 +32,21 @@ ...@@ -32,21 +32,21 @@
* last changes: * last changes:
* 2013-09-25 Theodor Stana t.stana@cern.ch File created * 2013-09-25 Theodor Stana t.stana@cern.ch File created
*============================================================================== *==============================================================================
* TODO: - * TODO: -
*============================================================================== *==============================================================================
*/ */
#ifndef __FLASH_H_ #ifndef __FLASH_H_
#define __FLASH_H_ #define __FLASH_H_
#include "types.h" #include "types.h"
/* Flash interface functions */ /* Flash interface functions */
void flash_init(); void flash_init();
int flash_write(uint32_t addr, uint8_t *buf, int count); int flash_write(uint32_t addr, uint8_t *buf, int count);
int flash_read(uint32_t addr, uint8_t *buf, int count); int flash_read(uint32_t addr, uint8_t *buf, int count);
void flash_serase(uint32_t addr); void flash_serase(uint32_t addr);
void flash_berase(); void flash_berase();
uint8_t flash_rsr(); uint8_t flash_rsr();
/* SDB flash interface functions */ /* SDB flash interface functions */
......
...@@ -44,7 +44,7 @@ flash-write: flash-write.c flash-host/libflash.a ...@@ -44,7 +44,7 @@ flash-write: flash-write.c flash-host/libflash.a
$(CC) $(CFLAGS) -Iflash-host $^ -o $@ $(CC) $(CFLAGS) -Iflash-host $^ -o $@
flash-host/libflash.a: flash-host/libflash.a:
$(MAKE) -C flash-host $(MAKE) -C flash-host
clean: clean:
......
...@@ -5,4 +5,4 @@ libflash.a: flash.o ...@@ -5,4 +5,4 @@ libflash.a: flash.o
clean: clean:
rm -f *.o *.a *~ rm -f *.o *.a *~
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
* version: 1.0 * version: 1.0
* *
* description: * description:
* *
* dependencies: * dependencies:
* *
* references: * references:
* *
*============================================================================== *==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE * GNU LESSER GENERAL PUBLIC LICENSE
*============================================================================== *==============================================================================
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* last changes: * last changes:
* 2013-09-25 Theodor Stana t.stana@cern.ch File created * 2013-09-25 Theodor Stana t.stana@cern.ch File created
*============================================================================== *==============================================================================
* TODO: - * TODO: -
*============================================================================== *==============================================================================
*/ */
...@@ -81,28 +81,25 @@ static inline int gpio_in(int pin) ...@@ -81,28 +81,25 @@ static inline int gpio_in(int pin)
*/ */
static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) 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 {
} gpio_out(GPIO_SPI_MOSI, 0);
else }
{ gpio_out(GPIO_SPI_SCLK, 1);
gpio_out(GPIO_SPI_MOSI, 0); retval <<= 1;
} retval |= gpio_in(GPIO_SPI_MISO);
gpio_out(GPIO_SPI_SCLK, 1); val <<= 1;
retval <<= 1; }
retval |= gpio_in(GPIO_SPI_MISO);
val <<= 1; gpio_out(GPIO_SPI_SCLK, 0);
}
return retval;
gpio_out(GPIO_SPI_SCLK, 0);
return retval;
} }
/* /*
...@@ -110,10 +107,10 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) ...@@ -110,10 +107,10 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val)
*/ */
void flash_init() void flash_init()
{ {
syscon = (volatile struct SYSCON_WB *)BASE_SYSCON; syscon = (volatile struct SYSCON_WB *)BASE_SYSCON;
gpio_out(GPIO_SPI_NCS, 1); gpio_out(GPIO_SPI_NCS, 1);
gpio_out(GPIO_SPI_SCLK, 0); gpio_out(GPIO_SPI_SCLK, 0);
gpio_out(GPIO_SPI_MOSI, 0); gpio_out(GPIO_SPI_MOSI, 0);
} }
/* /*
...@@ -121,22 +118,21 @@ void flash_init() ...@@ -121,22 +118,21 @@ void flash_init()
*/ */
int flash_write(uint32_t addr, uint8_t *buf, int count) int flash_write(uint32_t addr, uint8_t *buf, int count)
{ {
int i; int i;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x06); bbspi_transfer(0,0x06);
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x02); bbspi_transfer(0,0x02);
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);
return count;
return count;
} }
/* /*
...@@ -144,20 +140,19 @@ int flash_write(uint32_t addr, uint8_t *buf, int count) ...@@ -144,20 +140,19 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
*/ */
int flash_read(uint32_t addr, uint8_t *buf, int count) int flash_read(uint32_t addr, uint8_t *buf, int count)
{ {
int i; int i;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x0b); bbspi_transfer(0,0x0b);
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));
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);
return count;
return count;
} }
/* /*
...@@ -165,14 +160,14 @@ int flash_read(uint32_t addr, uint8_t *buf, int count) ...@@ -165,14 +160,14 @@ int flash_read(uint32_t addr, uint8_t *buf, int count)
*/ */
void flash_serase(uint32_t addr) void flash_serase(uint32_t addr)
{ {
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x06); bbspi_transfer(0,0x06);
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0xD8); bbspi_transfer(0,0xD8);
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));
bbspi_transfer(1,0); bbspi_transfer(1,0);
} }
...@@ -181,10 +176,10 @@ void flash_serase(uint32_t addr) ...@@ -181,10 +176,10 @@ void flash_serase(uint32_t addr)
*/ */
uint8_t flash_rsr() uint8_t flash_rsr()
{ {
uint8_t retval; uint8_t retval;
bbspi_transfer(1,0); bbspi_transfer(1,0);
bbspi_transfer(0,0x05); bbspi_transfer(0,0x05);
retval = bbspi_transfer(0,0); retval = bbspi_transfer(0,0);
bbspi_transfer(1,0); bbspi_transfer(1,0);
return retval; return retval;
} }
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
* version: 1.0 * version: 1.0
* *
* description: * description:
* *
* dependencies: * dependencies:
* *
* references: * references:
* *
*============================================================================== *==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE * GNU LESSER GENERAL PUBLIC LICENSE
*============================================================================== *==============================================================================
...@@ -32,20 +32,20 @@ ...@@ -32,20 +32,20 @@
* last changes: * last changes:
* 2013-09-25 Theodor Stana t.stana@cern.ch File created * 2013-09-25 Theodor Stana t.stana@cern.ch File created
*============================================================================== *==============================================================================
* TODO: - * TODO: -
*============================================================================== *==============================================================================
*/ */
#ifndef __FLASH_H_ #ifndef __FLASH_H_
#define __FLASH_H_ #define __FLASH_H_
#include <stdint.h> #include <stdint.h>
/* Flash interface functions */ /* Flash interface functions */
void flash_init(); void flash_init();
int flash_write(uint32_t addr, uint8_t *buf, int count); int flash_write(uint32_t addr, uint8_t *buf, int count);
int flash_read(uint32_t addr, uint8_t *buf, int count); int flash_read(uint32_t addr, uint8_t *buf, int count);
void flash_serase(uint32_t addr); void flash_serase(uint32_t addr);
uint8_t flash_rsr(); uint8_t flash_rsr();
/* SDB flash interface functions */ /* SDB flash interface functions */
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
* version: 1.0 * version: 1.0
* *
* description: * description:
* *
* dependencies: * dependencies:
* *
* references: * references:
* *
*============================================================================== *==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE * GNU LESSER GENERAL PUBLIC LICENSE
*============================================================================== *==============================================================================
...@@ -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