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

Fixed flash-write RSR issues and reset SDB-CONFIG file

The issue was due to a bug in gpio_in, which was doing an AND with
the value of GPIO_SPI_MISO, which was set to the pin offset, instead
of what it was set in the include/syscon.h file.

When I copied the gpio functions from include/syscon.h, I overlooked
the fact that the pins for the gpio functions there are set using
wbgen macros that actually perform the shifting, and I simply copied
the functions and redefined the GPIO_SPI_MISO macros as offsets.

The issue has been fixed by redefining the gpio_in function as an
AND with the value (1 << PIN_NR). This fixes everything.
Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent 78e6962d
......@@ -72,10 +72,20 @@ static inline void gpio_out(int pin, int val)
static inline int gpio_in(int pin)
{
return syscon->GPSR & pin ? 1 : 0;
return syscon->GPSR & (1 << pin) ? 1 : 0;
}
/*
* Delay function
*/
static void delay()
{
int i;
for (i = 0; i < 4; i++)
asm volatile ("nop");
}
/*
* Bit-bang SPI transfer function
*/
......@@ -83,6 +93,7 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val)
{
uint8_t i, retval = 0;
gpio_out(GPIO_SPI_NCS, cspin);
delay();
for (i = 0; i < 8; i++) {
gpio_out(GPIO_SPI_SCLK, 0);
if (val & 0x80) {
......@@ -91,10 +102,12 @@ static uint8_t bbspi_transfer(uint8_t cspin, uint8_t val)
else {
gpio_out(GPIO_SPI_MOSI, 0);
}
delay();
gpio_out(GPIO_SPI_SCLK, 1);
retval <<= 1;
retval |= gpio_in(GPIO_SPI_MISO);
val <<= 1;
delay();
}
gpio_out(GPIO_SPI_SCLK, 0);
......
......@@ -48,7 +48,4 @@ int flash_read(uint32_t addr, uint8_t *buf, int count);
void flash_serase(uint32_t addr);
uint8_t flash_rsr();
/* SDB flash interface functions */
#endif // __FLASH_H_
......@@ -79,11 +79,14 @@ int verbose;
extern void *BASE_SYSCON;
int c =0;
static int spec_write_flash(struct spec_device *spec, int addr, int len)
{
int i, r, plen = len;
int i;
int startlen = len;
/* Initializations */
uint8_t *buf = malloc(len);
if (buf == NULL) {
......@@ -110,7 +113,7 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
return 1;
}
/* Let's send some data to the flash */
/* Sending the data to the flash */
while (len) {
/* Set write length */
i = len;
......@@ -118,22 +121,14 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
i = 256;
/* Erase if sector boundary */
if ((addr % 0x10000) == 0)
{
if (verbose)
{
if ((addr % 0x10000) == 0) {
if (verbose) {
fprintf(stderr, "Erasing at address 0x%06X\n",
addr);
}
flash_serase(addr);
sleep(1);
/* FIXME: Can't understand why rsr is not working... */
// r = 0x01;
// while (r & 0x01)
// {
// r = flash_rsr();
// printf("%d\n", r);
// }
while (flash_rsr() & 0x01)
;
}
/* Write to flash */
......@@ -142,24 +137,17 @@ static int spec_write_flash(struct spec_device *spec, int addr, int len)
i, addr);
}
flash_write(addr, buf, i);
sleep(1);
/* FIXME: As above, RSR is a mystery... */
// while (flash_rsr() & 0x01)
// ;
while (flash_rsr() & 0x01)
;
/* Setup next length, address and buffer pointer */
len -= i;
addr += i;
buf += i;
// if (i != len) {
// fprintf(stderr, "Tried to write %i bytes, retval %i\n",
// len, i);
// return 1;
// }
}
/* pull back buffer so we can free */
buf -= startlen;
free(buf);
return 0;
......
......@@ -3,7 +3,7 @@
# at offset zero at all, we want to start at zero *wihin* our space.
# This is actually the default, but stating it is better.
.
position = 0x100
position = 0
# Then, we have a number of writable files. By default (i.e. no config)
# all existing files are created as read-only files with current contents
......
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