Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9c84387
Choose a base ref
...
head repository: m-labs/misp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1f55938
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 2, 2012

  1. libglue: freopen

    Sebastien Bourdeauducq committed Jun 2, 2012
    Copy the full SHA
    9c8a24b View commit details
  2. Mount YAFFS

    Sebastien Bourdeauducq committed Jun 2, 2012
    Copy the full SHA
    1f55938 View commit details
Showing with 170 additions and 5 deletions.
  1. +1 −1 Makefile
  2. +1 −1 libglue/Makefile
  3. +19 −2 libglue/file.c
  4. +6 −0 libglue/include/glue.h
  5. +140 −1 libglue/yaffs.c
  6. +3 −0 main.c
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ include $(MISPDIR)/common.mak
OBJECTS=crt0.o isr.o luainit.o main.o
OURLIBS=m mm yaffs2 glue lua

CFLAGS+=-I$(MISPDIR)/libm/include -I$(MISPDIR)/libmm/include -I$(LUADIR)/src
CFLAGS+=-I$(MISPDIR)/libm/include -I$(MISPDIR)/libmm/include -I$(MISPDIR)/libglue/include -I$(LUADIR)/src

all: misp.bin

2 changes: 1 addition & 1 deletion libglue/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MISPDIR=..
include $(MISPDIR)/common.mak

CFLAGS+=-I$(YAFFSDIR)/direct -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -I$(MISPDIR)/libglue/include
CFLAGS+=-I$(YAFFSDIR)/direct -I$(YAFFSDIR) -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -I$(MISPDIR)/libglue/include
OBJECTS=yaffs.o asprintf.o file.o getenv.o

all: libglue.a
21 changes: 19 additions & 2 deletions libglue/file.c
Original file line number Diff line number Diff line change
@@ -187,7 +187,11 @@ FILE *fopen(const char *path, const char *mode)

int fclose(FILE *fd)
{
return yaffs_close(*(int *)fd);
int r;

r = yaffs_close(*(int *)fd);
free(fd);
return r;
}

int fprintf(FILE *stream, const char *format, ...)
@@ -306,5 +310,18 @@ int feof(FILE *stream)

FILE *freopen(const char *path, const char *mode, FILE *stream)
{
return NULL;
FILE *newfd;

if(is_std_stream(stream))
return NULL; /* unsupported */

yaffs_close(*(int *)stream);
newfd = fopen(path, mode);
if(newfd == NULL) {
free(stream);
return NULL;
}
*(int *)stream = *(int *)newfd;
free(newfd);
return stream;
}
6 changes: 6 additions & 0 deletions libglue/include/glue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __GLUE_H
#define __GLUE_H

void fs_init(void);

#endif /* __GLUE_H */
141 changes: 140 additions & 1 deletion libglue/yaffs.c
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@
#include <hw/mem.h>

#include <yaffsfs.h>
#include <yaffs_guts.h>
#include <yaffs_packedtags2.h>

#include <glue.h>

/*
* YAFFS callbacks
@@ -56,4 +60,139 @@ void yaffs_bug_fn(const char *file_name, int line_no)

/*
* YAFFS init and flash access
*/
*/

#define NOR_SIZE (32*1024*1024)
#define NOR_BLOCKSIZE (128*1024)

#define NOR_CHUNK_DATA_SIZE 512
#define NOR_CHUNK_TAGS_SIZE 16
#define NOR_CHUNK_WHOLE_SIZE (NOR_CHUNK_DATA_SIZE+NOR_CHUNK_TAGS_SIZE)

static void read_flash(void *data, int len, int offset)
{
memcpy(data, (char *)(0x80000000 | FLASH_OFFSET_FILESYSTEM) + offset, len);
}

static void write_flash(const void *data, int len, int offset)
{
/* TODO */
}

static unsigned int chunk_address(struct yaffs_dev *dev, int c)
{
unsigned int chunks_per_block = dev->param.chunks_per_block;
return NOR_BLOCKSIZE*(c/chunks_per_block)
+ NOR_CHUNK_WHOLE_SIZE*(c%chunks_per_block);
}

static int read_chunk_tags(struct yaffs_dev *dev, int nand_chunk, u8 *data, struct yaffs_ext_tags *tags)
{
unsigned int address;

//printf("%s %d (data=%p tags=%p)\n", __func__, nand_chunk, data, tags);
address = chunk_address(dev, nand_chunk);
if(data)
read_flash(data, NOR_CHUNK_DATA_SIZE, address);
if(tags) {
struct yaffs_packed_tags2_tags_only x;
read_flash(&x, NOR_CHUNK_TAGS_SIZE, address+NOR_CHUNK_DATA_SIZE);
yaffs_unpack_tags2_tags_only(tags, &x);
}
return YAFFS_OK;
}

static int write_chunk_tags(struct yaffs_dev *dev, int nand_chunk, const u8 *data, const struct yaffs_ext_tags *tags)
{
unsigned int address;

//printf("%s %d (data=%p tags=%p)\n", __func__, nand_chunk, data, tags);
address = chunk_address(dev, nand_chunk);
if(data)
write_flash(data, NOR_CHUNK_DATA_SIZE, address);
if(tags) {
struct yaffs_packed_tags2_tags_only x;
yaffs_pack_tags2_tags_only(&x, tags);
write_flash(&x, NOR_CHUNK_TAGS_SIZE, address+NOR_CHUNK_DATA_SIZE);
}
return YAFFS_OK;
}

static int bad_block(struct yaffs_dev *dev, int blockId)
{
struct yaffs_ext_tags tags;
int chunk_nr;

chunk_nr = blockId * dev->param.chunks_per_block;

read_chunk_tags(dev, chunk_nr, NULL, &tags);
tags.block_bad = 1;
write_chunk_tags(dev, chunk_nr, NULL, &tags);

return YAFFS_OK;
}

static int query_block(struct yaffs_dev *dev, int blockId, enum yaffs_block_state *state, u32 *seq_number)
{
struct yaffs_ext_tags tags;
int chunk_nr;

*seq_number = 0;

chunk_nr = blockId * dev->param.chunks_per_block;

read_chunk_tags(dev, chunk_nr, NULL, &tags);
if(tags.block_bad)
*state = YAFFS_BLOCK_STATE_DEAD;
else if(!tags.chunk_used)
*state = YAFFS_BLOCK_STATE_EMPTY;
else if(tags.chunk_used) {
*state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
*seq_number = tags.seq_number;
}

return YAFFS_OK;
}

static int erase(struct yaffs_dev *dev, int blockId)
{
// TODO my_ioctl(sc->flashdev, FLASH_ERASE_BLOCK, (void *)(blockId*sc->blocksize));

return YAFFS_OK;
}

static int initialise(struct yaffs_dev *dev)
{
return YAFFS_OK;
}

static struct yaffs_dev flash_dev = {
.read_only = 0,
.param = {
.name = "/",

.start_block = 0,
.end_block = NOR_SIZE/NOR_BLOCKSIZE - 1,
.chunks_per_block = NOR_BLOCKSIZE/NOR_CHUNK_WHOLE_SIZE,
.total_bytes_per_chunk = NOR_CHUNK_WHOLE_SIZE,
.n_reserved_blocks = 5,
.n_caches = 15,
.inband_tags = 1,
.is_yaffs2 = 1,
.no_tags_ecc = 1,

.write_chunk_tags_fn = write_chunk_tags,
.read_chunk_tags_fn = read_chunk_tags,
.bad_block_fn = bad_block,
.query_block_fn = query_block,
.erase_fn = erase,
.initialise_flash_fn = initialise
}
};


void fs_init(void)
{
yaffs_add_device(&flash_dev);
yaffs_mount("/");
}
3 changes: 3 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
#include <irq.h>
#include <uart.h>

#include <glue.h>

#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
@@ -27,6 +29,7 @@ int main()
irq_setie(1);
uart_init();
mm_initialize(&_heapstart, 64*1024*1024);
fs_init();

printf("Hello World\n");
test_lua();