Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: m-labs/misp
base: 9c84387
...
head fork: m-labs/misp
compare: 1f55938
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
2  Makefile
@@ -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
View
2  libglue/Makefile
@@ -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
View
21 libglue/file.c
@@ -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;
}
View
6 libglue/include/glue.h
@@ -0,0 +1,6 @@
+#ifndef __GLUE_H
+#define __GLUE_H
+
+void fs_init(void);
+
+#endif /* __GLUE_H */
View
141 libglue/yaffs.c
@@ -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("/");
+}
View
3  main.c
@@ -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();

No commit comments for this range

Something went wrong with that request. Please try again.