Commit ca6ac8a3 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk Committed by Adam Wujek

simpler sdbfs creation by using parameters provided by Syscon HDL module

parent ae10efa1
......@@ -9,6 +9,7 @@
#include <wrc.h>
#include <flash.h>
#include <types.h>
#include <storage.h>
#define SDBFS_BIG_ENDIAN
#include <libsdbfs.h>
......@@ -114,14 +115,14 @@ int flash_erase(uint32_t addr, int count)
int sectors;
/*calc number of sectors to be removed*/
if(count % FLASH_BLOCKSIZE > 0)
if(count % storage_cfg.blocksize > 0)
sectors = 1;
else
sectors = 0;
sectors += (count / FLASH_BLOCKSIZE);
sectors += (count / storage_cfg.blocksize);
for(i=0; i<sectors; ++i) {
flash_serase(addr + i*FLASH_BLOCKSIZE);
flash_serase(addr + i*storage_cfg.blocksize);
while(flash_rsr() & 0x01);
}
......
......@@ -16,6 +16,7 @@
#include "i2c.h"
#include "onewire.h"
#include "endpoint.h"
#include "syscon.h"
#include <sdb.h>
#define SDBFS_BIG_ENDIAN
......@@ -36,6 +37,8 @@
#define EEPROM_START_ADR 0
#define EEPROM_STOP_ADR 127
struct storage_config storage_cfg;
/* Functions for Flash access */
static int sdb_flash_read(struct sdbfs *fs, int offset, void *buf, int count)
{
......@@ -221,7 +224,7 @@ void storage_init(int chosen_i2cif, int chosen_i2c_addr)
pp_printf("sdbfs: found at %i in Flash\n",
entry_points_flash[i]);
wrc_sdb.drvdata = NULL;
wrc_sdb.blocksize = FLASH_BLOCKSIZE;
wrc_sdb.blocksize = storage_cfg.blocksize;
wrc_sdb.entrypoint = entry_points_flash[i];
wrc_sdb.read = sdb_flash_read;
wrc_sdb.write = sdb_flash_write;
......@@ -742,6 +745,19 @@ out:
#ifdef CONFIG_GENSDBFS
int storage_read_hdl_cfg(void)
{
get_storage_info(&storage_cfg.memtype, &storage_cfg.baseadr, &storage_cfg.blocksize);
if (storage_cfg.memtype == MEM_FLASH && storage_cfg.blocksize == 0) {
storage_cfg.valid = 0;
/* keep default blocksize for backwards compatibility */
storage_cfg.blocksize = FLASH_BLOCKSIZE;
}
else
storage_cfg.valid = 1;
return 0;
}
extern uint32_t _binary_tools_sdbfs_default_bin_start[];
extern uint32_t _binary_tools_sdbfs_default_bin_end[];
......@@ -750,11 +766,14 @@ static inline unsigned long SDB_ALIGN(unsigned long x, int blocksize)
return (x + (blocksize - 1)) & ~(blocksize - 1);
}
int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint8_t i2c_adr)
int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint32_t blocksize, uint8_t i2c_adr)
{
if (mem_type == MEM_FLASH && blocksize == 0)
return -EINVAL;
if (mem_type == MEM_FLASH) {
pp_printf("Erasing Flash(0x%x)...\n", base_adr);
sdb_flash_erase(NULL, base_adr, SDBFS_REC * FLASH_BLOCKSIZE);
sdb_flash_erase(NULL, base_adr, SDBFS_REC * blocksize);
}
else if (mem_type == MEM_EEPROM) {
pp_printf("Erasing EEPROM %d (0x%x)...\n", i2c_adr, base_adr);
......@@ -771,7 +790,7 @@ int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint8_t i2c_adr)
return 0;
}
int storage_gensdbfs(int mem_type, uint32_t base_adr, uint8_t i2c_adr)
int storage_gensdbfs(int mem_type, uint32_t base_adr, uint32_t blocksize, uint8_t i2c_adr)
{
struct sdb_device *sdbfs = (struct sdb_device*) _binary_tools_sdbfs_default_bin_start;
struct sdb_interconnect *sdbfs_dir = (struct sdb_interconnect*) _binary_tools_sdbfs_default_bin_start;
......@@ -779,14 +798,13 @@ int storage_gensdbfs(int mem_type, uint32_t base_adr, uint8_t i2c_adr)
int i;
char buf[19] = {0};
int cur_adr, size;
int blocksize = 1;
uint32_t val;
if (mem_type == MEM_FLASH && base_adr == 0)
return -EINVAL;
if (mem_type == MEM_FLASH)
blocksize = FLASH_BLOCKSIZE;
if (mem_type == MEM_FLASH && blocksize == 0)
return -EINVAL;
/* first file starts after the SDBFS description */
cur_adr = base_adr + SDB_ALIGN(SDBFS_REC*sizeof(struct sdb_device), blocksize);
......@@ -814,7 +832,7 @@ int storage_gensdbfs(int mem_type, uint32_t base_adr, uint8_t i2c_adr)
pp_printf("Formatting SDBFS in Flash(0x%x)...\n", base_adr);
/* each file is in a separate block, therefore erase SDBFS_REC
* number of blocks */
sdb_flash_erase(NULL, base_adr, SDBFS_REC * FLASH_BLOCKSIZE);
sdb_flash_erase(NULL, base_adr, SDBFS_REC * blocksize);
for (i=0; i<SDBFS_REC; ++i) {
sdb_flash_write(NULL, base_adr + i*size, &sdbfs[i], size);
}
......
......@@ -74,12 +74,23 @@ int storage_init_readcmd(uint8_t *buf, uint8_t bufsize, uint8_t next);
#ifdef CONFIG_GENSDBFS
struct storage_config{
int memtype;
int valid;
uint32_t blocksize;
uint32_t baseadr;
};
extern struct storage_config storage_cfg;
#define MEM_FLASH 0
#define MEM_EEPROM 1
#define MEM_1W_EEPROM 2
#define SDBFS_REC 5
int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint8_t i2c_adr);
int storage_gensdbfs(int mem_type, uint32_t base_adr, uint8_t i2c_adr);
int storage_read_hdl_cfg(void);
int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint32_t blocksize, uint8_t i2c_adr);
int storage_gensdbfs(int mem_type, uint32_t base_adr, uint32_t blocksize, uint8_t i2c_adr);
#endif
......
......@@ -14,13 +14,14 @@
/*
* args[1] - where to write sdbfs image (0 - Flash, 1 - I2C EEPROM, 2 - 1Wire EEPROM)
* args[2] - base address for sdbfs image in Flash/EEPROM
* args[3] - i2c address of EEPROM
* args[3] - i2c address of EEPROM or blocksize of Flash
*/
static int cmd_sdb(const char *args[])
{
#ifdef CONFIG_GENSDBFS
uint8_t i2c_adr;
uint8_t i2c_adr = FMC_EEPROM_ADR;
int blocksize = 1;
#endif
if (!args[0]) {
......@@ -28,16 +29,37 @@ static int cmd_sdb(const char *args[])
return 0;
}
#ifdef CONFIG_GENSDBFS
if (args[3])
if (!args[1])
return -EINVAL;
/* interpret args[3] as i2c adr or blocksize depending on memory type */
if (args[3] && atoi(args[1]) == MEM_FLASH)
blocksize = atoi(args[3])*1024;
else if (args[3])
i2c_adr = atoi(args[3]);
else
i2c_adr = FMC_EEPROM_ADR;
if (args[2] && !strcasecmp(args[0], "fs")) {
storage_gensdbfs(atoi(args[1]), atoi(args[2]), i2c_adr);
/* Writing SDBFS image */
if (!strcasecmp(args[0], "fs") && args[2]) {
/* if all the parameters were specified from the cmd line, we
* use these */
storage_gensdbfs(atoi(args[1]), atoi(args[2]), blocksize, i2c_adr);
return 0;
}
if (!strcasecmp(args[0], "fs") && storage_cfg.valid &&
atoi(args[1]) == MEM_FLASH ) {
/* if available, we can also use Flash parameters specified with
* HDL generics */
storage_gensdbfs(MEM_FLASH, storage_cfg.baseadr, storage_cfg.blocksize, 0);
return 0;
}
/* Erasing SDBFS image */
if (!strcasecmp(args[0], "fse") && args[2]) {
storage_sdbfs_erase(atoi(args[1]), atoi(args[2]), blocksize, i2c_adr);
return 0;
}
if (args[2] && !strcasecmp(args[0], "fse")) {
storage_sdbfs_erase(atoi(args[1]), atoi(args[2]), i2c_adr);
if (!strcasecmp(args[0], "fse") && storage_cfg.valid &&
atoi(args[1]) == MEM_FLASH ) {
storage_sdbfs_erase(MEM_FLASH, storage_cfg.baseadr, storage_cfg.blocksize, 0);
return 0;
}
#endif
......
......@@ -56,6 +56,7 @@ static void wrc_initialize(void)
timer_init(1);
get_hw_name(wrc_hw_name);
storage_read_hdl_cfg();
wrpc_w1_init();
wrpc_w1_bus.detail = ONEWIRE_PORT;
w1_scan_bus(&wrpc_w1_bus);
......
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