summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--arch/config.mk1
-rw-r--r--config/toolchain.mk3
-rw-r--r--demo.c20
-rw-r--r--os/src/romfs.c1
-rw-r--r--test-romfs/test.txt1
-rw-r--r--tools/mkromfs.c12
7 files changed, 36 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index d2b5619..194079c 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@ TARGET = demo.bin
LIBDEPS = FreeRTOS/libFreeRTOS.a arch/libarch.a os/libos.a
LIBS = -Wl,--start-group -lc $(LIBDEPS) -Wl,--end-group
+TARGET_SRCS = test-romfs.o
+
export ROOTDIR = $(CURDIR)
include common.mk
@@ -38,6 +40,12 @@ tools:
$(E) "[MAKE] Entering tools"
$(Q)$(MAKE) $(MAKE_OPTS) -C tools
+test-romfs.o: tools
+ $(E) "[ROMFS] Building test romfs"
+ $(Q) tools/mkromfs -d test test-romfs.bin
+ $(Q) $(TARGET_OBJCOPY_BIN) --prefix-sections '.romfs' test-romfs.bin test-romfs.o
+ $(Q)$(MAKE) $(MAKE_OPTS) -C tools
+
include FreeRTOS/config.mk
include arch/config.mk
include os/config.mk
diff --git a/arch/config.mk b/arch/config.mk
index 2e59ef6..94ea88e 100644
--- a/arch/config.mk
+++ b/arch/config.mk
@@ -1,4 +1,5 @@
ifeq ($(CPU),arm)
+TARGET_INCLUDES += $(ROOTDIR)/arch/arm/include
ifeq ($(CPU_FLAVOR),lpc1768)
TARGET_INCLUDES += $(ROOTDIR)/arch/arm/lpc17xx/Core/CM3/DeviceSupport/NXP/LPC17xx $(ROOTDIR)/arch/arm/lpc17xx/Core/CM3/CoreSupport $(ROOTDIR)/arch/arm/lpc17xx/Drivers/include $(ROOTDIR)/arch/arm/lpc17xx/mbed
LDSCRIPT = $(ROOTDIR)/arch/arm/lpc17xx/ldscript
diff --git a/config/toolchain.mk b/config/toolchain.mk
index 4e58227..ee9d5b5 100644
--- a/config/toolchain.mk
+++ b/config/toolchain.mk
@@ -1,5 +1,6 @@
ifeq ($(CPU),arm)
TOOLCHAIN = arm-none-eabi
+TARGET_FORMAT = elf32-littlearm
ifeq ($(CPU_FLAVOR),lpc1768)
TARGET_CPPFLAGS += -mcpu=cortex-m3 -mtune=cortex-m3 -D__thumb2__=1 -march=armv7-m -mfix-cortex-m3-ldrd
endif
@@ -14,3 +15,5 @@ TARGET_RANLIB = $(TOOLCHAIN)-ranlib
TARGET_AR = $(TOOLCHAIN)-ar
TARGET_AS = $(TOOLCHAIN)-gcc
TARGET_OBJCOPY = $(TOOLCHAIN)-objcopy
+
+TARGET_OBJCOPY_BIN = $(TARGET_OBJCOPY) -I binary -O $(TARGET_FORMAT) --binary-architecture $(CPU)
diff --git a/demo.c b/demo.c
index cde181a..fbf2b26 100644
--- a/demo.c
+++ b/demo.c
@@ -6,6 +6,7 @@
#include <osdebug.h>
#include <stdio.h>
#include <fio.h>
+#include <romfs.h>
#define LED1_wire 18
#define LED2_wire 20
@@ -62,16 +63,25 @@ static void badTask(void *x) {
static const char msg[] = "Hello world - from fwrite!\r\n";
+extern uint8_t _binary_test_romfs_bin_start[];
+
int main() {
- FILE * f;
+ FILE * f1, * f2;
+ char buf[32];
+ int c;
register_devfs();
+ register_romfs("romfs", _binary_test_romfs_bin_start);
handle = xSemaphoreCreateMutex();
printf("Hello world - from stdio!\r\n");
fflush(stdout);
- f = fopen("/dev/stdout", "w");
- fwrite(msg, 1, sizeof(msg), f);
- fflush(f);
- fclose(f);
+ f1 = fopen("/dev/stdout", "w");
+ fwrite(msg, 1, sizeof(msg), f1);
+ f2 = fopen("/romfs/test.txt", "r");
+ c = fread(buf, 1, 32, f2);
+ fwrite(buf, 1, c, f1);
+ fflush(f1);
+ fclose(f1);
+ fclose(f2);
setupLEDs();
litLED(1, 0);
litLED(2, 0);
diff --git a/os/src/romfs.c b/os/src/romfs.c
index 403bef9..270fb54 100644
--- a/os/src/romfs.c
+++ b/os/src/romfs.c
@@ -90,5 +90,6 @@ static int romfs_open(void * opaque, const char * path, int flags, int mode) {
}
void register_romfs(const char * mountpoint, const uint8_t * romfs) {
+ DBGOUT("Registering romfs `%s' @ %p\r\n", mountpoint, romfs);
register_fs(mountpoint, romfs_open, (void *) romfs);
}
diff --git a/test-romfs/test.txt b/test-romfs/test.txt
new file mode 100644
index 0000000..7fe3486
--- /dev/null
+++ b/test-romfs/test.txt
@@ -0,0 +1 @@
+Romfs test
diff --git a/tools/mkromfs.c b/tools/mkromfs.c
index be46a44..c3b43e0 100644
--- a/tools/mkromfs.c
+++ b/tools/mkromfs.c
@@ -21,7 +21,7 @@ void usage(const char * binname) {
exit(-1);
}
-void processdir(DIR * dirp, const char * curpath, FILE * outfile) {
+void processdir(DIR * dirp, const char * curpath, FILE * outfile, const char * prefix) {
char fullpath[1024];
char buf[16 * 1024];
struct dirent * ent;
@@ -32,7 +32,9 @@ void processdir(DIR * dirp, const char * curpath, FILE * outfile) {
FILE * infile;
while ((ent = readdir(dirp))) {
- strcpy(fullpath, curpath);
+ strcpy(fullpath, prefix);
+ strcat(fullpath, "/");
+ strcat(fullpath, curpath);
strcat(fullpath, ent->d_name);
switch(ent->d_type) {
case DT_DIR:
@@ -42,7 +44,7 @@ void processdir(DIR * dirp, const char * curpath, FILE * outfile) {
continue;
strcat(fullpath, "/");
rec_dirp = opendir(fullpath);
- processdir(rec_dirp, fullpath, outfile);
+ processdir(rec_dirp, fullpath, outfile, prefix);
closedir(rec_dirp);
break;
case DT_REG:
@@ -90,7 +92,7 @@ int main(int argc, char ** argv) {
o++;
switch (*o) {
case 'd':
- dirname = o;
+ dirname = *argv++;
break;
default:
usage(binname);
@@ -119,7 +121,7 @@ int main(int argc, char ** argv) {
exit(-1);
}
- processdir(dirp, "", outfile);
+ processdir(dirp, "", outfile, dirname);
fwrite(&z, 1, 8, outfile);
if (outname)
fclose(outfile);