Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 6 files changed
  • 0 comments
  • 1 contributor
5  Makefile
@@ -40,4 +40,7 @@ clean:
40 40
 		make -C $(MISPDIR)/lib$$lib clean; \
41 41
 	done
42 42
 
43  
-.PHONY: clean libs
  43
+netboot: misp.bin
  44
+	cp misp.bin /var/lib/tftpboot/boot.bin
  45
+
  46
+.PHONY: clean libs netboot
4  libglue/Makefile
... ...
@@ -1,8 +1,8 @@
1 1
 MISPDIR=..
2 2
 include $(MISPDIR)/common.mak
3 3
 
4  
-CFLAGS+=-I$(YAFFSDIR)/direct -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
5  
-OBJECTS=file.o getenv.o
  4
+CFLAGS+=-I$(YAFFSDIR)/direct -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -I$(MISPDIR)/libglue/include
  5
+OBJECTS=yaffs.o asprintf.o file.o getenv.o
6 6
 
7 7
 all: libglue.a
8 8
 
47  libglue/asprintf.c
... ...
@@ -0,0 +1,47 @@
  1
+#include <stdlib.h>
  2
+#include <stdio.h>
  3
+#include <stdarg.h>
  4
+#include <asprintf.h>
  5
+
  6
+int vasprintf(char **strp, const char *fmt, va_list ap)
  7
+{
  8
+	va_list aq;
  9
+	int alloclen;
  10
+	int len;
  11
+	char *newbuf;
  12
+	
  13
+	alloclen = 256;
  14
+	*strp = malloc(alloclen);
  15
+	if(!*strp)
  16
+		return -1;
  17
+
  18
+	while(1) {
  19
+		va_copy(aq, ap);
  20
+		len = vscnprintf(*strp, alloclen, fmt, aq);
  21
+		va_end(aq);
  22
+		if(len < 0) {
  23
+			free(*strp);
  24
+			return len;
  25
+		}
  26
+		if(len < alloclen)
  27
+			return len;
  28
+		alloclen *= 2;
  29
+		newbuf = realloc(*strp, alloclen);
  30
+		if(!newbuf) {
  31
+			free(*strp);
  32
+			return -1;
  33
+		}
  34
+		*strp = newbuf;
  35
+	}
  36
+}
  37
+
  38
+int asprintf(char **strp, const char *fmt, ...)
  39
+{
  40
+	va_list args;
  41
+	int len;
  42
+
  43
+	va_start(args, fmt);
  44
+	len = vasprintf(strp, fmt, args);
  45
+	va_end(args);
  46
+	return len;
  47
+}
292  libglue/file.c
... ...
@@ -1,79 +1,225 @@
1 1
 #include <stdio.h>
  2
+#include <stdlib.h>
2 3
 #include <errno.h>
3 4
 #include <stdarg.h>
  5
+#include <asprintf.h>
4 6
 #include <console.h>
5 7
 
6  
-#include <yaffs_osglue.h>
  8
+#include <yaffsfs.h>
7 9
 
8  
-/* TODO */
  10
+#define VAL_STDIN	1
  11
+#define VAL_STDOUT	2
  12
+#define VAL_STDERR	3
9 13
 
10  
-unsigned int yaffs_trace_mask;
  14
+FILE *stdin = (FILE *)VAL_STDIN;
  15
+FILE *stdout = (FILE *)VAL_STDOUT;
  16
+FILE *stderr = (FILE *)VAL_STDERR;
11 17
 
12  
-void yaffsfs_Lock(void)
  18
+static int is_std_stream(FILE *fd)
13 19
 {
  20
+	int f;
  21
+	
  22
+	f = (int)fd;
  23
+	return (f == VAL_STDIN) || (f == VAL_STDOUT) || (f == VAL_STDERR);
14 24
 }
15 25
 
16  
-void yaffsfs_Unlock(void)
17  
-{
18  
-}
  26
+/* 
  27
+ * Mode conversion function based on NuttX
  28
+ * 
  29
+ *   Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
  30
+ *   Author: Gregory Nutt <gnutt@nuttx.org>
  31
+ *
  32
+ * Redistribution and use in source and binary forms, with or without
  33
+ * modification, are permitted provided that the following conditions
  34
+ * are met:
  35
+ *
  36
+ * 1. Redistributions of source code must retain the above copyright
  37
+ *    notice, this list of conditions and the following disclaimer.
  38
+ * 2. Redistributions in binary form must reproduce the above copyright
  39
+ *    notice, this list of conditions and the following disclaimer in
  40
+ *    the documentation and/or other materials provided with the
  41
+ *    distribution.
  42
+ * 3. Neither the name NuttX nor the names of its contributors may be
  43
+ *    used to endorse or promote products derived from this software
  44
+ *    without specific prior written permission.
  45
+ *
  46
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  47
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  48
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  49
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  50
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  51
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  52
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  53
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  54
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  56
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  57
+ * POSSIBILITY OF SUCH DAMAGE.
  58
+ */
19 59
 
20  
-u32 yaffsfs_CurrentTime(void)
21  
-{
22  
-	return 0;
23  
-}
  60
+enum open_mode_e {
  61
+	MODE_NONE = 0,	/* No access mode determined */
  62
+	MODE_R,		/* "r" or "rb" open for reading */
  63
+	MODE_W,		/* "w" or "wb" open for writing, truncating or creating file */
  64
+	MODE_A,		/* "a" or "ab" open for writing, appending to file */
  65
+	MODE_RPLUS,	/* "r+", "rb+", or "r+b" open for update (reading and writing) */
  66
+	MODE_WPLUS,	/* "w+", "wb+", or "w+b"  open for update, truncating or creating file */
  67
+	MODE_APLUS,	/* "a+", "ab+", or "a+b" open for update, appending to file */
  68
+};
24 69
 
25  
-void yaffsfs_SetError(int err)
  70
+static int mode2oflags(const char *mode)
26 71
 {
27  
-	errno = err;
28  
-}
  72
+	enum open_mode_e state;
  73
+	int oflags;
29 74
 
30  
-int yaffsfs_GetLastError(void)
31  
-{
32  
-	return errno;
33  
-}
  75
+	/* Verify that a mode string was provided. */
  76
+	if(!mode)
  77
+		goto errout;
34 78
 
35  
-void *yaffsfs_malloc(size_t size)
36  
-{
37  
-	return NULL;
  79
+	/* Parse the mode string to determine the corresponding open flags */
  80
+	state = MODE_NONE;
  81
+	oflags = 0;
  82
+
  83
+	for(;*mode;mode++) {
  84
+		switch(*mode) {
  85
+			/* Open for read access ("r", "r[+]", "r[b]",  "r[b+]", or "r[+b]") */
  86
+			case 'r':
  87
+				if(state == MODE_NONE) {
  88
+					/* Open for read access */
  89
+					oflags = O_RDONLY;
  90
+					state = MODE_R;
  91
+				} else
  92
+					goto errout;
  93
+				break;
  94
+
  95
+			/* Open for write access ("w", "w[+]", "w[b]",  "w[b+]", or "w[+b]") */
  96
+			case 'w':
  97
+				if(state == MODE_NONE) {
  98
+					/* Open for write access, truncating any existing file */
  99
+					oflags = O_WRONLY|O_CREAT|O_TRUNC;
  100
+					state = MODE_W;
  101
+				} else
  102
+					goto errout;
  103
+				break;
  104
+
  105
+			/* Open for write/append access ("a", "a[+]", "a[b]", "a[b+]", or "a[+b]") */
  106
+			case 'a' :
  107
+				if(state == MODE_NONE) {
  108
+					/* Write to the end of the file */
  109
+					oflags = O_WRONLY|O_CREAT|O_APPEND;
  110
+					state = MODE_A;
  111
+				} else
  112
+					goto errout;
  113
+				break;
  114
+
  115
+			/* Open for update access ("[r]+", "[rb]+]", "[r]+[b]", "[w]+",
  116
+			 * "[wb]+]", "[w]+[b]", "[a]+", "[ab]+]",  "[a]+[b]")
  117
+			 */
  118
+			case '+' :
  119
+				switch(state) {
  120
+					case MODE_R:
  121
+						/* Open for read/write access */
  122
+						oflags = O_RDWR;
  123
+						state = MODE_RPLUS;
  124
+						break;
  125
+
  126
+					case MODE_W:
  127
+						/* Open for write read/access, truncating any existing file */
  128
+						oflags = O_RDWR|O_CREAT|O_TRUNC;
  129
+						state = MODE_WPLUS;
  130
+						break;
  131
+
  132
+					case MODE_A:
  133
+						/* Read from the beginning of the file; write to the end */
  134
+						oflags = O_RDWR|O_CREAT|O_APPEND;
  135
+						state = MODE_APLUS;
  136
+						break;
  137
+
  138
+					default:
  139
+						goto errout;
  140
+						break;
  141
+				}
  142
+				break;
  143
+
  144
+			/* Open for binary access ("[r]b", "[r]b[+]", "[r+]b", "[w]b",
  145
+			 * "[w]b[+]", "[w+]b", "[a]b", "[a]b[+]",  "[a+]b")
  146
+			 */
  147
+			case 'b' :
  148
+				if(state != MODE_NONE) {
  149
+					/* nothing to do */
  150
+				} else
  151
+					goto errout;
  152
+			break;
  153
+
  154
+			/* Unrecognized or unsupported mode */
  155
+			default:
  156
+				goto errout;
  157
+				break;
  158
+		}
  159
+	}
  160
+
  161
+	return oflags;
  162
+
  163
+errout:
  164
+	errno = EINVAL;
  165
+	return -1;
38 166
 }
39 167
 
40  
-void yaffsfs_free(void *ptr)
  168
+
  169
+FILE *fopen(const char *path, const char *mode)
41 170
 {
  171
+	int oflags;
  172
+	int *fd;
  173
+	
  174
+	oflags = mode2oflags(mode);
  175
+	if(oflags < 0)
  176
+		return NULL;
  177
+	fd = malloc(sizeof(int));
  178
+	if(!fd)
  179
+		return NULL;
  180
+	*fd = yaffs_open(path, oflags, 0666);
  181
+	if(*fd < 0) {
  182
+		free(fd);
  183
+		return NULL;
  184
+	}
  185
+	return (FILE *)fd;
42 186
 }
43 187
 
44  
-void yaffs_bug_fn(const char *file_name, int line_no)
  188
+int fclose(FILE *fd)
45 189
 {
  190
+	return yaffs_close(*(int *)fd);
46 191
 }
47 192
 
48  
-
49  
-FILE *stdin;
50  
-FILE *stdout;
51  
-FILE *stderr;
52  
-
53 193
 int fprintf(FILE *stream, const char *format, ...)
54 194
 {
55 195
 	va_list args;
56 196
 	int len;
57  
-	char outbuf[256];
  197
+	char *outbuf;
58 198
 
59 199
 	va_start(args, format);
60  
-	len = vscnprintf(outbuf, sizeof(outbuf), format, args);
  200
+	len = vasprintf(&outbuf, format, args);
61 201
 	va_end(args);
62  
-	outbuf[len] = 0;
63  
-	putsnonl(outbuf);
  202
+	if(len < 0)
  203
+		return len;
  204
+	
  205
+	if(is_std_stream(stream)) {
  206
+		putsnonl(outbuf);
  207
+		free(outbuf);
  208
+	} else {
  209
+		int fd = *(int *)stream;
  210
+		
  211
+		len = yaffs_write(fd, outbuf, len);
  212
+		free(outbuf);
  213
+	}
64 214
 	return len;
65 215
 }
66 216
 
67 217
 int fflush(FILE *stream)
68 218
 {
  219
+	/* nothing to do */
69 220
 	return 0;
70 221
 }
71 222
 
72  
-FILE *fopen(const char *path, const char *mode)
73  
-{
74  
-	return NULL;
75  
-}
76  
-
77 223
 char *fgets(char *s, int size, FILE *stream)
78 224
 {
79 225
 	return NULL;
@@ -81,43 +227,81 @@ char *fgets(char *s, int size, FILE *stream)
81 227
 
82 228
 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
83 229
 {
84  
-	return 0;
  230
+	if(is_std_stream(stream))
  231
+		return 0;
  232
+	else {
  233
+		int fd = *(int *)stream;
  234
+		int r;
  235
+		
  236
+		r = yaffs_read(fd, ptr, size*nmemb);
  237
+		if(r < 0)
  238
+			return r;
  239
+		return r/size;
  240
+	}
85 241
 }
86 242
 
87 243
 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
88 244
 {
89  
-	const char *str = ptr;
90  
-	int i;
91  
-	
92  
-	for(i=0;i<size*nmemb;i++)
93  
-		putchar(str[i]);
94  
-	return nmemb;
  245
+	if(is_std_stream(stream)) {
  246
+		const char *str = ptr;
  247
+		int i;
  248
+		
  249
+		for(i=0;i<size*nmemb;i++)
  250
+			putchar(str[i]);
  251
+		return nmemb;
  252
+	} else {
  253
+		int fd = *(int *)stream;
  254
+		int r;
  255
+		
  256
+		r = yaffs_write(fd, ptr, size*nmemb);
  257
+		if(r < 0)
  258
+			return r;
  259
+		return r/size;
  260
+	}
95 261
 }
96 262
 
97 263
 int getc(FILE *stream)
98 264
 {
99  
-	return 0;
  265
+	if(is_std_stream(stream))
  266
+		return EOF;
  267
+	else {
  268
+		int fd = *(int *)stream;
  269
+		int r;
  270
+		char c;
  271
+		
  272
+		r = yaffs_read(fd, &c, 1);
  273
+		if(r < 0)
  274
+			return EOF;
  275
+		return c;
  276
+	}
100 277
 }
101 278
 
102 279
 int fputc(int c, FILE *stream)
103 280
 {
104  
-	return 0;
  281
+	if(is_std_stream(stream)) {
  282
+		putchar(c);
  283
+		return c;
  284
+	} else {
  285
+		int fd = *(int *)stream;
  286
+		int r;
  287
+		char c2;
  288
+		
  289
+		c2 = c;
  290
+		r = yaffs_write(fd, &c2, 1);
  291
+		if(r < 0)
  292
+			return EOF;
  293
+		return c;
  294
+	}
105 295
 }
106 296
 
107  
-
108 297
 int ferror(FILE *stream)
109 298
 {
110  
-	return 0;
  299
+	return 0; /* TODO */
111 300
 }
112 301
 
113 302
 int feof(FILE *stream)
114 303
 {
115  
-	return 0;
116  
-}
117  
-
118  
-int fclose(FILE *fp)
119  
-{
120  
-	return 0;
  304
+	return 0; /* TODO */
121 305
 }
122 306
 
123 307
 FILE *freopen(const char *path, const char *mode, FILE *stream)
9  libglue/include/asprintf.h
... ...
@@ -0,0 +1,9 @@
  1
+#ifndef __ASPRINTF_H
  2
+#define __ASPRINTF_H
  3
+
  4
+#include <stdarg.h>
  5
+
  6
+int asprintf(char **strp, const char *fmt, ...);
  7
+int vasprintf(char **strp, const char *fmt, va_list ap);
  8
+
  9
+#endif /* __ASPRINTF_H */
59  libglue/yaffs.c
... ...
@@ -0,0 +1,59 @@
  1
+#include <stdio.h>
  2
+#include <stdlib.h>
  3
+#include <errno.h>
  4
+#include <stdarg.h>
  5
+#include <console.h>
  6
+
  7
+#include <hw/mem.h>
  8
+
  9
+#include <yaffsfs.h>
  10
+
  11
+/*
  12
+ * YAFFS callbacks
  13
+ */
  14
+
  15
+unsigned int yaffs_trace_mask;
  16
+
  17
+void yaffsfs_Lock(void)
  18
+{
  19
+	/* nothing to do */
  20
+}
  21
+
  22
+void yaffsfs_Unlock(void)
  23
+{
  24
+	/* nothing to do */
  25
+}
  26
+
  27
+u32 yaffsfs_CurrentTime(void)
  28
+{
  29
+	return 0;
  30
+}
  31
+
  32
+void yaffsfs_SetError(int err)
  33
+{
  34
+	errno = -err;
  35
+}
  36
+
  37
+int yaffsfs_GetLastError(void)
  38
+{
  39
+	return -errno;
  40
+}
  41
+
  42
+void *yaffsfs_malloc(size_t size)
  43
+{
  44
+	return malloc(size);
  45
+}
  46
+
  47
+void yaffsfs_free(void *ptr)
  48
+{
  49
+	free(ptr);
  50
+}
  51
+
  52
+void yaffs_bug_fn(const char *file_name, int line_no)
  53
+{
  54
+	printf("YAFFS BUG in %s line %d\n", file_name, line_no);
  55
+}
  56
+
  57
+/*
  58
+ * YAFFS init and flash access
  59
+ */

No commit comments for this range

Something went wrong with that request. Please try again.