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

Added flash SDBFS read to LM32 code

Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent 6ef8ac88
......@@ -40,13 +40,14 @@
#include "types.h"
#include "syscon.h"
static void delay()
{
int i;
for (i = 0; i < 1; i++)
asm volatile ("nop");
}
#define SDBFS_BIG_ENDIAN
#include "libsdbfs.h"
#include <wrc.h>
/*****************************************************************************/
/* Flash interface */
/*****************************************************************************/
/*
* Bit-bang SPI transfer function
*/
......@@ -145,6 +146,19 @@ void flash_serase(uint32_t addr)
bbspi_transfer(1,0);
}
/*
* Bulk erase
*/
void
flash_berase()
{
bbspi_transfer(1,0);
bbspi_transfer(0,0x06);
bbspi_transfer(1,0);
bbspi_transfer(0,0xc7);
bbspi_transfer(1,0);
}
/*
* Read status register
*/
......@@ -157,3 +171,73 @@ uint8_t flash_rsr()
bbspi_transfer(1,0);
return retval;
}
/*****************************************************************************/
/* SDB */
/*****************************************************************************/
/* The sdb filesystem itself */
static struct sdbfs wrc_sdb = {
.name = "wrpc-storage",
.blocksize = 1, /* Not currently used */
/* .read and .write according to device type */
};
/*
* SDB read and write functions
*/
static int sdb_flash_read(struct sdbfs *fs, int offset, void *buf, int count)
{
return flash_read(offset, buf, count);
}
static int sdb_flash_write(struct sdbfs *fs, int offset, void *buf, int count)
{
return flash_write(offset, buf, count);
}
/*
* A trivial dumper, just to show what's up in there
*/
static void flash_sdb_list(struct sdbfs *fs)
{
struct sdb_device *d;
int new = 1;
while ( (d = sdbfs_scan(fs, new)) != NULL) {
d->sdb_component.product.record_type = '\0';
mprintf("file 0x%08x @ %4i, name %s\n",
(int)(d->sdb_component.product.device_id),
(int)(d->sdb_component.addr_first),
(char *)(d->sdb_component.product.name));
new = 0;
}
}
/*
* Check for SDB presence on flash
*/
int flash_sdb_check()
{
uint32_t magic = 0;
int i;
uint32_t entry_point[3] = {0x000000, 0x170000, 0x2e0000};
for (i = 0; i < ARRAY_SIZE(entry_point); i++)
{
flash_read(entry_point[i], (uint8_t *)&magic, 4);
if (magic == SDB_MAGIC)
break;
}
if (magic == SDB_MAGIC)
{
mprintf("Found SDB magic at address 0x%06X!\n", entry_point[i]);
wrc_sdb.drvdata = NULL;
wrc_sdb.read = sdb_flash_read;
wrc_sdb.write = sdb_flash_write;
flash_sdb_list(&wrc_sdb);
}
return 0;
}
......@@ -46,9 +46,10 @@ void flash_init();
int flash_write(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_berase();
uint8_t flash_rsr();
/* SDB flash interface functions */
int flash_sdb_check();
#endif // __FLASH_H_
......@@ -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 = 0
position = 0x170000
# 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
......
......@@ -253,30 +253,16 @@ int main(void)
uint8_t d[4] = { 0xaa, 0xbb, 0xcc, 0xdd};
flash_init();
flash_read(0x00, rdat, 256);
flash_read(0x170000,rdat,256);
for (i = 0; i < 256; i++)
{
mprintf("0x%02x ", rdat[i]);
}
mprintf("\n");
// mprintf("erase\n");
// flash_serase(0x00);
// while (flash_rsr() & 0x01)
// ;
//
// mprintf("write\n");
// flash_write(0x00, d, 4);
// while (flash_rsr() & 0x01)
// ;
flash_read(0x100, rdat, 256);
printf("0x%02X ", rdat[i]);
printf("\n");
flash_read(0x170100,rdat,256);
for (i = 0; i < 256; i++)
{
mprintf("0x%02x ", rdat[i]);
}
mprintf("\n");
printf("0x%02X ", rdat[i]);
printf("\n");
// flash_sdb_check();
return 0;
......
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