From 8035d12a83a5b64d589a38d9becae164cd62f3f6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 7 Dec 2014 12:26:30 -0600 Subject: Add logic to build the demo world as a ROMFS file system --- apps/graphics/traveler/.gitignore | 2 + apps/graphics/traveler/Kconfig | 17 +++++- apps/graphics/traveler/Makefile | 35 ++++++++++-- apps/graphics/traveler/trv_romfs.c | 106 +++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 apps/graphics/traveler/trv_romfs.c (limited to 'apps/graphics') diff --git a/apps/graphics/traveler/.gitignore b/apps/graphics/traveler/.gitignore index 83bd7b811..c7cf4c8ae 100644 --- a/apps/graphics/traveler/.gitignore +++ b/apps/graphics/traveler/.gitignore @@ -1,6 +1,8 @@ /Make.dep /.depend /.built +/trv_romfs.h +/trv_romfs.img /*.asm /*.rel /*.lst diff --git a/apps/graphics/traveler/Kconfig b/apps/graphics/traveler/Kconfig index b3edc7174..719b5c3a1 100644 --- a/apps/graphics/traveler/Kconfig +++ b/apps/graphics/traveler/Kconfig @@ -62,10 +62,25 @@ config GRAPHICS_TRAVELER_JOYDEV comment "Debug options" +config GRAPHICS_TRAVELER_ROMFSDEMO + bool "Build ROMFS demo world" + default y + depends on FS_ROMFS + ---help--- + The traveller code will do nothing unless you also provide a world + data set for it to work on. The world/ sub-directory contains a + demo world suitable for testing. If this option is selected, then + the demo world is build as a mountable ROMFS file system. This new + function is then exported that can be used to mount the demo world: + + int trv_mount_world(int minor, FAR const char *mountpoint) + + This function must be called somewhere in your board-specific start- + up logic in order to mount the world at 'mountpoint' + config GRAPHICS_TRAVELER_PERFMON bool "Performance monitor" default y - depends on FS_READABLE ---help--- Enable or disable performance monitoring instrumentation and output. diff --git a/apps/graphics/traveler/Makefile b/apps/graphics/traveler/Makefile index 516613703..1f39d1af6 100644 --- a/apps/graphics/traveler/Makefile +++ b/apps/graphics/traveler/Makefile @@ -37,6 +37,13 @@ -include $(TOPDIR)/Make.defs include $(APPDIR)/Make.defs +# Directories + +TRAVELER_DIR = $(APPDIR)/graphics/traveler +TRAVELER_SRC = $(TRAVELER_DIR)/src +TRAVELER_INC = $(TRAVELER_DIR)/include +TRAVELER_DEMO = $(TRAVELER_DIR)/world + # Traveler built-in application info APPNAME = traveler @@ -52,6 +59,11 @@ CSRCS += trv_mem.c trv_paltbl.c trv_pcx.c trv_planefiles.c trv_planelists.c CSRCS += trv_pov.c trv_rayavoid.c trv_raycast.c trv_raycntl.c CSRCS += trv_rayprune.c trv_rayrend.c trv_texturefile.c trv_trigtbl.c CSRCS += trv_world.c + +ifeq ($(CONFIG_GRAPHICS_TRAVELER_ROMFSDEMO),y) +CSRCS += trv_romfs.c +endif + MAINSRC = trv_main.c ifeq ($(CONFIG_NX),y) @@ -72,6 +84,11 @@ ifneq ($(CONFIG_BUILD_KERNEL),y) OBJS += $(MAINOBJ) endif +ifeq ($(CONFIG_GRAPHICS_TRAVELER_ROMFSDEMO),y) +ROMFS_IMG = trv_romfs.img +ROMFS_HDR = trv_romfs.h +endif + ifeq ($(CONFIG_WINDOWS_NATIVE),y) BIN = ..\..\libapps$(LIBEXT) else @@ -95,10 +112,10 @@ ifeq ($(WINTOOL),y) INCDIROPT = -w endif -CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/traveler/include} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TRAVELER_INC)} -DEPPATH = --dep-path src -VPATH = src +DEPPATH = --dep-path . --dep-path src +VPATH = .:src # Common build @@ -111,7 +128,15 @@ $(AOBJS): %$(OBJEXT): %.S $(COBJS) $(MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -.built: $(OBJS) +ifeq ($(CONFIG_GRAPHICS_TRAVELER_ROMFSDEMO),y) +$(ROMFS_IMG): + $(Q) genromfs -f $@ -d $(TRAVELER_DEMO) -V "DemoWorld" + +$(ROMFS_HDR): $(ROMFS_IMG) + $(Q) (xxd -i $< | sed -e "s/^unsigned/static const unsigned/g" >$@) +endif + +.built: $(ROMFS_HDR) $(OBJS) $(call ARCHIVE, $(BIN), $(OBJS)) @touch .built @@ -145,6 +170,8 @@ depend: .depend clean: $(call DELFILE, .built) + $(call DELFILE, $(ROMFS_IMG)) + $(call DELFILE, $(ROMFS_HDR)) $(call CLEAN) distclean: clean diff --git a/apps/graphics/traveler/trv_romfs.c b/apps/graphics/traveler/trv_romfs.c new file mode 100644 index 000000000..651affc03 --- /dev/null +++ b/apps/graphics/traveler/trv_romfs.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_romfs.c + * Mount the ROMFS demo world + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_GRAPHICS_TRAVELER_ROMFSDEMO + +#include +#include +#include + +#include + +#include "trv_romfs.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_FS_ROMFS +# error You must select CONFIG_FS_ROMFS in your configuration file +#endif + +#ifdef CONFIG_DISABLE_MOUNTPOINT +# error You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT +#endif + +/* Describe the ROMFS file system */ + +#define SECTORSIZE 512 +#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_mount_world + * + * Description: + * Mount the demo world as a ROMFS file system mounted at 'mountpoint' + * + ****************************************************************************/ + +int trv_mount_world(int minor, FAR const char *mountpoint) +{ + char devpath[16]; + int ret; + + /* Create a ROM disk for the ROMFS filesystem */ + + ret = romdisk_register(minor, (FAR uint8_t *)trv_romfs_img, + NSECTORS(trv_romfs_img_len), SECTORSIZE); + if (ret < 0) + { + return ret; + } + + /* Get the ROM disk device name */ + + snprintf(devpath, 16, "/dev/ram%d", minor); + + /* Mount the file system */ + + ret = mount(devpath, mountpoint, "romfs", MS_RDONLY, NULL); + return ret; +} + +#endif /* CONFIG_GRAPHICS_TRAVELER_ROMFSDEMO */ -- cgit v1.2.3