Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 8 commits
  • 8 files changed
  • 0 comments
  • 3 contributors
1  .gitignore
@@ -3,3 +3,4 @@ src/obj
3 3
 doc/handbook.aux
4 4
 doc/handbook.log
5 5
 doc/handbook.pdf
  6
+TAGS
15  flash/flash.sh
... ...
@@ -1,21 +1,22 @@
1  
-#!/bin/sh
  1
+#!/bin/bash
2 2
 
3 3
 set -e
4 4
 
5 5
 ADDRESS=0x920000
6  
-if [ "$1" == "rescue" ]; then
  6
+if [ "$1" == "rescue" ] || [ "$2" == "rescue" ]; then
7 7
     ADDRESS=0x2E0000
8 8
 fi
9 9
 
10  
-TARGET=flickernoise.fbiz
11  
-if [ "$2" == "nocompress" ]; then
12  
-    TARGET=flickernoise.fbi
  10
+TARGET=flickernoise.fbi
  11
+if [ "$2" == "compress" ] || [ "$1" == "compress" ] ; then
  12
+    TARGET=flickernoise.fbiz
13 13
 fi
14 14
 
15 15
 make -C ../src bin/${TARGET}
16 16
 
17 17
 BATCH_FILE=`mktemp`
18 18
 cat > ${BATCH_FILE}<<EOF
  19
+
19 20
 cable milkymist
20 21
 detect
21 22
 instruction CFG_OUT 000100 BYPASS
@@ -27,7 +28,11 @@ detectflash 0
27 28
 endian big
28 29
 flashmem ${ADDRESS} ../src/bin/${TARGET} noverify
29 30
 pld reconfigure
  31
+
30 32
 EOF
31 33
 
32 34
 jtag -n ${BATCH_FILE}
  35
+more    ${BATCH_FILE}
33 36
 rm -f   ${BATCH_FILE}
  37
+
  38
+echo "Done"
8  src/Makefile
@@ -13,7 +13,7 @@ OBJDIR=obj
13 13
 BINDIR=bin
14 14
 
15 15
 # base
16  
-OBJS=version.o shellext.o sysconfig.o config.o fb.o input.o keymap.o fbgrab.o shortcuts.o osc.o png.o flashvalid.o main.o
  16
+OBJS=yaffs.o version.o shellext.o sysconfig.o config.o fb.o input.o keymap.o fbgrab.o shortcuts.o osc.o png.o flashvalid.o main.o
17 17
 
18 18
 # GUI
19 19
 OBJS+=messagebox.o filedialog.o resmgr.o guirender.o performance.o cp.o keyboard.o ir.o audio.o midi.o oscsettings.o dmxspy.o dmxdesk.o dmx.o videoin.o rsswall.o patcheditor.o monitor.o firstpatch.o filemanager.o sysettings.o about.o patchpool.o flash.o shutdown.o
@@ -68,9 +68,13 @@ $(BINDIR)/flickernoise.fbiz: $(BINDIR)/flickernoise.lzma
68 68
 load: $(BINDIR)/flickernoise.bin
69 69
 	cp $< /var/lib/tftpboot/boot.bin
70 70
 
  71
+flash:
  72
+	(cd ../flash && ./flash.sh rescue)
  73
+	(cd ../flash && ./flash.sh)
  74
+
71 75
 clean:
72 76
 	rm -f $(BINDIR)/flickernoise $(BINDIR)/flickernoise.bin 
73 77
 	rm -f $(BINDIR)/flickernoise.lzma $(BINDIR)/flickernoise.fbi $(BINDIR)/flickernoise.fbiz 
74 78
 	rm -f $(POBJS)
75 79
 
76  
-.PHONY: clean load
  80
+.PHONY: clean load flash
1  src/flash.c
@@ -28,7 +28,6 @@
28 28
 #include <bsp/milkymist_flash.h>
29 29
 
30 30
 #include <curl/curl.h>
31  
-#include <curl/types.h>
32 31
 #include <curl/easy.h>
33 32
 #include <mtklib.h>
34 33
 
4  src/flashvalid.c
@@ -99,7 +99,7 @@ int flashvalid_application(const char *filename)
99 99
 	}
100 100
 
101 101
 	length = 0;
102  
-	crc = crc32(0L, Z_NULL, 0);
  102
+	crc = z_crc32(0L, Z_NULL, 0);
103 103
 
104 104
 	while(1) {
105 105
 		r = read(fd, buf, sizeof(buf));
@@ -108,7 +108,7 @@ int flashvalid_application(const char *filename)
108 108
 			return FLASHVALID_ERROR_IO;
109 109
 		}
110 110
 		if(r == 0) break;
111  
-		crc = crc32(crc, buf, r);
  111
+		crc = z_crc32(crc, buf, r);
112 112
 		length += r;
113 113
 	}
114 114
 	
7  src/main.c
@@ -46,9 +46,10 @@
46 46
 #include <rtems/rtems_bsdnet.h>
47 47
 #include <rtems/ftpd.h>
48 48
 #include <rtems/telnetd.h>
49  
-#include <yaffs.h>
  49
+#include <yaffs/rtems_yaffs.h>
50 50
 #include <curl/curl.h>
51 51
 
  52
+#include "yaffs.h"
52 53
 #include "version.h"
53 54
 #include "videoinreconf.h"
54 55
 #include "shellext.h"
@@ -295,8 +296,8 @@ rtems_telnetd_config_table rtems_telnetd_config = {
295 296
 const rtems_filesystem_table_t rtems_filesystem_table[] = {
296 297
 	{ RTEMS_FILESYSTEM_TYPE_IMFS, IMFS_initialize },
297 298
 	{ RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize },
298  
-	{ RTEMS_FILESYSTEM_TYPE_NFS, rtems_nfsfs_initialize },
299  
-	{ "yaffs", yaffs_initialize },
  299
+	{ RTEMS_FILESYSTEM_TYPE_NFS, rtems_nfs_initialize },
  300
+	{ RTEMS_FILESYSTEM_TYPE_YAFFS, yaffs_initialize },
300 301
 	{ NULL, NULL }
301 302
 };
302 303
 
371  src/yaffs.c
... ...
@@ -0,0 +1,371 @@
  1
+/*
  2
+ * Flickernoise
  3
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <assert.h>
  19
+#include <rtems.h>
  20
+#include <rtems/libio.h>
  21
+#include <rtems/seterr.h>
  22
+#include <rtems/userenv.h>
  23
+#include <bsp/milkymist_flash.h>
  24
+#include <errno.h>
  25
+#include <limits.h>
  26
+#include <stdlib.h>
  27
+#include <yaffs/rtems_yaffs.h>
  28
+#include <yaffs/yaffs_packedtags2.h>
  29
+
  30
+#include "yaffs.h"
  31
+
  32
+#define MAXIMUM_YAFFS_MOUNTS 2
  33
+
  34
+struct yaffs_softc {
  35
+	struct yaffs_dev *dev;
  36
+	dev_t flashdev;
  37
+	unsigned int size;
  38
+	unsigned int blocksize;
  39
+	rtems_yaffs_os_handler free_os_context;
  40
+};
  41
+
  42
+/* WARNING: Those I/O helpers:
  43
+ * - do not open or close the device
  44
+ * - set iop to NULL
  45
+ * The device driver must be able to support this.
  46
+ */
  47
+
  48
+static rtems_status_code my_ioctl(dev_t dev, int request, void *p)
  49
+{
  50
+	rtems_libio_ioctl_args_t args;
  51
+
  52
+	args.iop = NULL;
  53
+	args.command = request;
  54
+	args.buffer = p;
  55
+	return rtems_io_control(rtems_filesystem_dev_major_t(dev), rtems_filesystem_dev_minor_t(dev), &args);
  56
+}
  57
+
  58
+static rtems_status_code my_read(dev_t dev, void *buffer, int len, int offset)
  59
+{
  60
+	rtems_libio_rw_args_t args;
  61
+	
  62
+	args.iop = NULL;
  63
+	args.offset = offset;
  64
+	args.buffer = buffer;
  65
+	args.count = len;
  66
+	args.flags = 0;
  67
+	return rtems_io_read(rtems_filesystem_dev_major_t(dev), rtems_filesystem_dev_minor_t(dev), &args);
  68
+}
  69
+
  70
+static rtems_status_code my_write(dev_t dev, const void *buffer, int len, int offset)
  71
+{
  72
+	rtems_libio_rw_args_t args;
  73
+
  74
+	args.iop = NULL;
  75
+	args.offset = offset;
  76
+	args.buffer = (void *)buffer;
  77
+	args.count = len;
  78
+	args.flags = 0;
  79
+	return rtems_io_write(rtems_filesystem_dev_major_t(dev), rtems_filesystem_dev_minor_t(dev), &args);
  80
+}
  81
+
  82
+/* Flash access functions */
  83
+
  84
+#define NOR_CHUNK_DATA_SIZE 512
  85
+#define NOR_CHUNK_TAGS_SIZE 16
  86
+#define NOR_CHUNK_WHOLE_SIZE (NOR_CHUNK_DATA_SIZE+NOR_CHUNK_TAGS_SIZE)
  87
+
  88
+static unsigned int chunk_address(struct yaffs_dev *dev, int c)
  89
+{
  90
+	struct yaffs_softc *sc = (struct yaffs_softc *)dev->driver_context;
  91
+	unsigned int chunks_per_block = dev->param.chunks_per_block;
  92
+	return sc->blocksize*(c/chunks_per_block)
  93
+		+ NOR_CHUNK_WHOLE_SIZE*(c%chunks_per_block);
  94
+}
  95
+
  96
+static int write_chunk_tags(struct yaffs_dev *dev, int nand_chunk, const u8 *data, const struct yaffs_ext_tags *tags)
  97
+{
  98
+	struct yaffs_softc *sc = (struct yaffs_softc *)dev->driver_context;
  99
+	unsigned int address;
  100
+	
  101
+	//printf("%s %d (data=%p tags=%p)\n", __func__, nand_chunk, data, tags);
  102
+	address = chunk_address(dev, nand_chunk);
  103
+	if(data)
  104
+		my_write(sc->flashdev, data, NOR_CHUNK_DATA_SIZE, address);
  105
+	if(tags) {
  106
+		struct yaffs_packed_tags2_tags_only x;
  107
+		yaffs_pack_tags2_tags_only(&x, tags);
  108
+		my_write(sc->flashdev, &x, NOR_CHUNK_TAGS_SIZE, address+NOR_CHUNK_DATA_SIZE);
  109
+	}
  110
+	return YAFFS_OK;
  111
+}
  112
+
  113
+static int read_chunk_tags(struct yaffs_dev *dev, int nand_chunk, u8 *data, struct yaffs_ext_tags *tags)
  114
+{
  115
+	struct yaffs_softc *sc = (struct yaffs_softc *)dev->driver_context;
  116
+	unsigned int address;
  117
+	
  118
+	//printf("%s %d (data=%p tags=%p)\n", __func__, nand_chunk, data, tags);
  119
+	address = chunk_address(dev, nand_chunk);
  120
+	if(data)
  121
+		my_read(sc->flashdev, data, NOR_CHUNK_DATA_SIZE, address);
  122
+	if(tags) {
  123
+		struct yaffs_packed_tags2_tags_only x;
  124
+		my_read(sc->flashdev, &x, NOR_CHUNK_TAGS_SIZE, address+NOR_CHUNK_DATA_SIZE);
  125
+		yaffs_unpack_tags2_tags_only(tags, &x);
  126
+	}
  127
+	return YAFFS_OK;
  128
+}
  129
+
  130
+static int bad_block(struct yaffs_dev *dev, int blockId)
  131
+{
  132
+	struct yaffs_ext_tags tags;
  133
+	int chunk_nr;
  134
+
  135
+	chunk_nr = blockId * dev->param.chunks_per_block;
  136
+
  137
+	read_chunk_tags(dev, chunk_nr, NULL, &tags);
  138
+	tags.block_bad = 1;
  139
+	write_chunk_tags(dev, chunk_nr, NULL, &tags);
  140
+	
  141
+	return YAFFS_OK;
  142
+}
  143
+
  144
+static int query_block(struct yaffs_dev *dev, int blockId, enum yaffs_block_state *state, u32 *seq_number)
  145
+{
  146
+	struct yaffs_ext_tags tags;
  147
+	int chunk_nr;
  148
+
  149
+	*seq_number = 0;
  150
+
  151
+	chunk_nr = blockId * dev->param.chunks_per_block;
  152
+
  153
+	read_chunk_tags(dev, chunk_nr, NULL, &tags);
  154
+	if(tags.block_bad)
  155
+		*state = YAFFS_BLOCK_STATE_DEAD;
  156
+	else if(!tags.chunk_used)
  157
+		*state = YAFFS_BLOCK_STATE_EMPTY;
  158
+	else if(tags.chunk_used) {
  159
+		*state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
  160
+		*seq_number = tags.seq_number;
  161
+	}
  162
+	
  163
+	return YAFFS_OK;
  164
+}
  165
+
  166
+static int erase(struct yaffs_dev *dev, int blockId)
  167
+{
  168
+	struct yaffs_softc *sc = dev->driver_context;
  169
+
  170
+	my_ioctl(sc->flashdev, FLASH_ERASE_BLOCK, (void *)(blockId*sc->blocksize));
  171
+	
  172
+	return YAFFS_OK;
  173
+}
  174
+
  175
+static int initialise(struct yaffs_dev *dev)
  176
+{
  177
+	return YAFFS_OK;
  178
+}
  179
+
  180
+static int mount_sema_created;
  181
+static rtems_id mount_sema;
  182
+static struct yaffs_softc *current_mounts[MAXIMUM_YAFFS_MOUNTS];
  183
+
  184
+static void unmount_handler(struct yaffs_dev *dev, void *os_context)
  185
+{
  186
+	struct yaffs_softc *softc = dev->driver_context;
  187
+	int i;
  188
+	
  189
+	rtems_semaphore_obtain(mount_sema, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  190
+	
  191
+	for(i=0;i<MAXIMUM_YAFFS_MOUNTS;i++) {
  192
+		if(current_mounts[i] == softc) {
  193
+			current_mounts[i] = NULL;
  194
+			break;
  195
+		}
  196
+	}
  197
+	
  198
+	softc->free_os_context(dev, os_context);
  199
+	free(softc);
  200
+	free(dev);
  201
+	
  202
+	rtems_semaphore_release(mount_sema);
  203
+}
  204
+
  205
+static int flush_task_running;
  206
+static rtems_id flush_task_id;
  207
+
  208
+static rtems_task flush_task(rtems_task_argument argument)
  209
+{
  210
+	int i;
  211
+	struct yaffs_softc *sc;
  212
+	rtems_yaffs_default_os_context *os_context;
  213
+	
  214
+	while(1) {
  215
+		rtems_task_wake_after(10*100);
  216
+		rtems_semaphore_obtain(mount_sema, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  217
+		for(i=0;i<MAXIMUM_YAFFS_MOUNTS;i++) {
  218
+			sc = current_mounts[i];
  219
+			if(sc != NULL) {
  220
+				os_context = sc->dev->os_context;
  221
+				os_context->os_context.lock(sc->dev, os_context);
  222
+				yaffs_flush_whole_cache(sc->dev);
  223
+				os_context->os_context.unlock(sc->dev, os_context);
  224
+			}
  225
+		}
  226
+		rtems_semaphore_release(mount_sema);
  227
+	}
  228
+}
  229
+
  230
+int yaffs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry, const void *data)
  231
+{
  232
+	int i;
  233
+	int index;
  234
+	struct yaffs_dev *dev;
  235
+	struct yaffs_param *param;
  236
+	struct yaffs_softc *softc;
  237
+	rtems_yaffs_default_os_context *os_context;
  238
+	struct stat st;
  239
+	rtems_yaffs_mount_data md;
  240
+	rtems_status_code sc1, sc2;
  241
+	int r;
  242
+	
  243
+	if(!mount_sema_created) {
  244
+		sc1 = rtems_semaphore_create(
  245
+			rtems_build_name('Y', 'A', 'F', 'M'),
  246
+			1,
  247
+			RTEMS_LOCAL
  248
+				| RTEMS_BINARY_SEMAPHORE
  249
+				| RTEMS_INHERIT_PRIORITY
  250
+				| RTEMS_PRIORITY,
  251
+			0,
  252
+			&mount_sema
  253
+		);
  254
+		if(sc1 != RTEMS_SUCCESSFUL) {
  255
+			errno = ENOMEM;
  256
+			return -1;
  257
+		}
  258
+		mount_sema_created = 1;
  259
+	}
  260
+	
  261
+	rtems_semaphore_obtain(mount_sema, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  262
+	index = -1;
  263
+	for(i=0;i<MAXIMUM_YAFFS_MOUNTS;i++) {
  264
+		if(current_mounts[i] == NULL) {
  265
+			index = i;
  266
+			break;
  267
+		}
  268
+	}
  269
+	rtems_semaphore_release(mount_sema);
  270
+	if(index == -1) {
  271
+		errno = ENOMEM;
  272
+		return -1;
  273
+	}
  274
+	
  275
+	dev = malloc(sizeof(struct yaffs_dev));
  276
+	if(dev == NULL) {
  277
+		errno = ENOMEM;
  278
+		return -1;
  279
+	}
  280
+	memset(dev, 0, sizeof(struct yaffs_dev));
  281
+	
  282
+	softc = malloc(sizeof(struct yaffs_softc));
  283
+	if(softc == NULL) {
  284
+		errno = ENOMEM;
  285
+		free(dev);
  286
+		return -1;
  287
+	}
  288
+	softc->dev = dev;
  289
+	
  290
+	if(stat(mt_entry->dev, &st) < 0) {
  291
+		errno = EIO;
  292
+		free(softc);
  293
+		free(dev);
  294
+		return -1;
  295
+	}
  296
+	softc->flashdev = st.st_rdev;
  297
+	sc1 = my_ioctl(softc->flashdev, FLASH_GET_SIZE, &softc->size);
  298
+	sc2 = my_ioctl(softc->flashdev, FLASH_GET_BLOCKSIZE, &softc->blocksize);
  299
+	if((sc1 != RTEMS_SUCCESSFUL)||(sc2 != RTEMS_SUCCESSFUL)) {
  300
+		errno = EIO;
  301
+		free(softc);
  302
+		free(dev);
  303
+		return -1;
  304
+	}
  305
+	
  306
+	os_context = malloc(sizeof(rtems_yaffs_default_os_context));
  307
+	if(os_context == NULL) {
  308
+		errno = ENOMEM;
  309
+		free(softc);
  310
+		free(dev);
  311
+		return -1;
  312
+	}
  313
+	r = rtems_yaffs_initialize_default_os_context(os_context);
  314
+	if(r == -1) {
  315
+		free(os_context);
  316
+		free(softc);
  317
+		free(dev);
  318
+		return -1;
  319
+	}
  320
+	softc->free_os_context = os_context->os_context.unmount;
  321
+	os_context->os_context.unmount = unmount_handler;
  322
+	
  323
+	/* set parameters */
  324
+	dev->driver_context = softc;
  325
+	dev->os_context = os_context;
  326
+	dev->read_only = 0;
  327
+
  328
+	param = &(dev->param);
  329
+	param->name = mt_entry->dev;
  330
+	
  331
+	param->start_block = 0;
  332
+	param->end_block = softc->size/softc->blocksize - 1;
  333
+	param->chunks_per_block = softc->blocksize/NOR_CHUNK_WHOLE_SIZE;
  334
+	param->total_bytes_per_chunk = NOR_CHUNK_WHOLE_SIZE;
  335
+	param->n_reserved_blocks = 5;
  336
+	param->n_caches = 15;
  337
+	param->inband_tags = 1;
  338
+	param->is_yaffs2 = 1;
  339
+	param->no_tags_ecc = 1;
  340
+	
  341
+	/* set callbacks */
  342
+	param->write_chunk_tags_fn = write_chunk_tags;
  343
+	param->read_chunk_tags_fn = read_chunk_tags;
  344
+	param->bad_block_fn = bad_block;
  345
+	param->query_block_fn = query_block;
  346
+	param->erase_fn = erase;
  347
+	param->initialise_flash_fn = initialise;
  348
+	
  349
+	md.dev = dev;
  350
+	r = rtems_yaffs_mount_handler(mt_entry, &md);
  351
+	if(r == -1) {
  352
+		errno = ENOMEM;
  353
+		softc->free_os_context(dev, os_context);
  354
+		free(softc);
  355
+		free(dev);
  356
+		return -1;
  357
+	}
  358
+	
  359
+	current_mounts[index] = softc;
  360
+	if(!flush_task_running) {
  361
+		sc1 = rtems_task_create(rtems_build_name('F', 'L', 'S', 'H'), 220, 256*1024,
  362
+			RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
  363
+			0, &flush_task_id);
  364
+		assert(sc1 == RTEMS_SUCCESSFUL);
  365
+		sc1 = rtems_task_start(flush_task_id, flush_task, 0);
  366
+		assert(sc1 == RTEMS_SUCCESSFUL);
  367
+		flush_task_running = 1;
  368
+	}
  369
+	
  370
+	return 0;
  371
+}
23  src/yaffs.h
... ...
@@ -0,0 +1,23 @@
  1
+/*
  2
+ * Flickernoise
  3
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __YAFFS_H
  19
+#define __YAFFS_H
  20
+
  21
+int yaffs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry, const void *data);
  22
+
  23
+#endif /* __YAFFS_H */

No commit comments for this range

Something went wrong with that request. Please try again.