summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-04-15 08:39:44 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-04-15 08:39:44 -0600
commit7f6fde293cccf7d84af9e9b05eb6fb7b57bb6ce3 (patch)
tree6169c7c04433aa967759cc02711912b4e9e15a51
parent3a23faff9f4074d4be39010c115835a32eed7d74 (diff)
downloadpx4-nuttx-7f6fde293cccf7d84af9e9b05eb6fb7b57bb6ce3.tar.gz
px4-nuttx-7f6fde293cccf7d84af9e9b05eb6fb7b57bb6ce3.tar.bz2
px4-nuttx-7f6fde293cccf7d84af9e9b05eb6fb7b57bb6ce3.zip
apps/system/zoneinfo: Add logic to build a ROMFS file system containing the timezone data
-rw-r--r--apps/examples/romfs/Kconfig1
-rw-r--r--apps/examples/romfs/romfs_main.c2
-rwxr-xr-xapps/include/zoneinfo.h83
-rw-r--r--apps/system/zoneinfo/.gitignore7
-rw-r--r--apps/system/zoneinfo/Kconfig28
-rwxr-xr-xapps/system/zoneinfo/Makefile66
-rw-r--r--apps/system/zoneinfo/tzmount.c68
-rwxr-xr-xapps/system/zoneinfo/tzromfs.c51
8 files changed, 284 insertions, 22 deletions
diff --git a/apps/examples/romfs/Kconfig b/apps/examples/romfs/Kconfig
index 5a8c824a3..4da4d5052 100644
--- a/apps/examples/romfs/Kconfig
+++ b/apps/examples/romfs/Kconfig
@@ -6,6 +6,7 @@
config EXAMPLES_ROMFS
bool "ROMFS example"
default n
+ depends on FS_ROMFS
---help---
Enable the ROMFS example
diff --git a/apps/examples/romfs/romfs_main.c b/apps/examples/romfs/romfs_main.c
index ce1c53d60..fdea119fe 100644
--- a/apps/examples/romfs/romfs_main.c
+++ b/apps/examples/romfs/romfs_main.c
@@ -74,7 +74,7 @@
#include "romfs_testdir.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/* Configuration settings */
diff --git a/apps/include/zoneinfo.h b/apps/include/zoneinfo.h
new file mode 100755
index 000000000..db271ce7f
--- /dev/null
+++ b/apps/include/zoneinfo.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * apps/include/zoneinfo.h
+ *
+ * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_INCLUDE_ZONEINFO_H
+#define __APPS_INCLUDE_ZONEINFO_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifdef CONFIG_SYSTEM_ZONEINFO_ROMFS
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/* If the TZ database is built as a ROMFS file system, then these variables
+ * provide (1) the address of the array in FLASH/ROM that contains the
+ * ROMFS file system image, and (2) the size of the ROMFS file system image
+ * in bytes. This is sufficient information to permit external logic to
+ * mount the ROMF file system.
+ */
+
+EXTERN unsigned char romfs_zoneinfo_img[];
+EXTERN unsigned int romfs_zoneinfo_img_len;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_SYSTEM_ZONEINFO_ROMFS */
+#endif /* __APPS_INCLUDE_ZONEINFO_H */
diff --git a/apps/system/zoneinfo/.gitignore b/apps/system/zoneinfo/.gitignore
index 6c67706bd..cf64977cb 100644
--- a/apps/system/zoneinfo/.gitignore
+++ b/apps/system/zoneinfo/.gitignore
@@ -1,9 +1,12 @@
/Make.dep
/.depend
/.built
-/.tzbin
-/.tzcode
+/.tzbuilt
+/.tzunpack
+/tzbin
+/tzcode
/tz*-latest.tar.gz
+/romfs_zoneinfo.*
/*.asm
/*.rel
/*.lst
diff --git a/apps/system/zoneinfo/Kconfig b/apps/system/zoneinfo/Kconfig
index bece2d31f..65b87940c 100644
--- a/apps/system/zoneinfo/Kconfig
+++ b/apps/system/zoneinfo/Kconfig
@@ -11,5 +11,31 @@ config SYSTEM_ZONEINFO
Build the TZ/Olson database.
if SYSTEM_ZONEINFO
-endif
+config SYSTEM_ZONEINFO_ROMFS
+ bool "Build ROMFS filesystem"
+ default n
+ depends on FS_ROMFS
+ ---help---
+ Build a mountable ROMFS filesystem containing the TZ database
+
+config SYSTEM_ZONEINFO_MNTCMD
+ bool "Zoneinfo mount command"
+ default n
+ depends on SYSTEM_ZONEINFO_ROMFS && NSH_BUILTIN_APPS
+ ---help---
+ Build an NSH command that will mount the ROMFS filesystem containing
+ the TZ database at CONFIG_LIBC_TZDIR.
+
+config SYSTEM_ZONEINFO_RAMDEVNO
+ int "ROMFS minor number"
+ default 0
+ depends on SYSTEM_ZONEINFO_MNTCMD
+ ---help---
+ Minor number to use when registering the ROM disk block driver. The
+ driver will be registers as /dev/ramN where N is provided by
+ CONFIG_SYSTEM_ZONEINFO_RAMDEVNO. This, of course, must not conflict
+ with other RAM/ROM disk devices that may have been previously
+ registered.
+
+endif # SYSTEM_ZONEINFO
diff --git a/apps/system/zoneinfo/Makefile b/apps/system/zoneinfo/Makefile
index 1e8ebc50d..99240206d 100755
--- a/apps/system/zoneinfo/Makefile
+++ b/apps/system/zoneinfo/Makefile
@@ -49,7 +49,14 @@ STACKSIZE = 768
ASRCS =
CSRCS =
+
+ifeq ($(CONFIG_SYSTEM_ZONEINFO_ROMFS),y)
+CSRCS += tzromfs.c
+endif
+
+ifeq ($(CONFIG_SYSTEM_ZONEINFO_MNTCMD),y)
MAINSRC = tzmount.c
+endif
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
@@ -62,6 +69,10 @@ ifneq ($(CONFIG_BUILD_KERNEL),y)
OBJS += $(MAINOBJ)
endif
+ZONEINFO_PATH = $(APPDIR)/system/zoneinfo
+TZBIN_PATH = $(ZONEINFO_PATH)/tzbin
+TZCODE_PATH = $(ZONEINFO_PATH)/tzcode
+
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
@@ -88,7 +99,7 @@ ROOTDEPPATH = --dep-path .
VPATH =
all: .built
-.PHONY: tzcode_unpack tzdata_unpack tzcode_build tzbuild register context depend clean distclean
+.PHONY: romfs register context depend clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@@ -96,10 +107,12 @@ $(AOBJS): %$(OBJEXT): %.S
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
-.built: $(OBJS)
+.built: .tzbuilt romfs $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
$(Q) touch .built
+# Kernel mode program build
+
ifeq ($(CONFIG_BUILD_KERNEL),y)
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
@echo "LD: $(PROGNAME)"
@@ -113,6 +126,31 @@ install:
endif
+# ROMFS file system containing the TZ database
+
+ifeq ($(CONFIG_SYSTEM_ZONEINFO_MNTCMD),y)
+
+checkgenromfs:
+ @genromfs -h 1>/dev/null 2>&1 || { \
+ echo "Host executable genromfs not available in PATH"; \
+ echo "You may need to download in from http://romfs.sourceforge.net/"; \
+ exit 1; \
+ }
+
+romfs_zoneinfo.img : checkgenromfs .tzbuilt
+ @genromfs -f $@ -d $(TZBIN_PATH)/etc/zoneinfo -V "TZDatbase" || { echo "genromfs failed" ; exit 1 ; }
+
+romfs_zoneinfo.h : romfs_zoneinfo.img
+ @xxd -i $< >$@ || { echo "xxd of $< failed" ; exit 1 ; }
+
+romfs: romfs_zoneinfo.h
+
+else
+
+romfs:
+
+endif # CONFIG_SYSTEM_ZONEINFO_MNTCMD
+
# Build TZ database
tzcode:
@@ -127,20 +165,18 @@ tzcode-latest.tar.gz:
tzdata-latest.tar.gz:
$(Q) wget --retr-symlinks ftp://ftp.iana.org/tz/tzdata-latest.tar.gz
-tzcode_unpack: tzcode tzcode-latest.tar.gz
+.tzunpack: tzcode tzcode-latest.tar.gz tzdata-latest.tar.gz
$(Q) tar zx -C tzcode -f tzcode-latest.tar.gz
-
-tzdata_unpack: tzcode tzdata-latest.tar.gz
$(Q) tar zx -C tzcode -f tzdata-latest.tar.gz
+ $(Q) touch .tzunpack
-tzcode_build: tzcode_unpack
-
-tzbuild: tzcode_build tzdata_unpack tzbin
- $(Q) $(MAKE) -C tzcode TOPDIR=$(PWD)$(DELIM)tzbin install
+.tzbuilt: tzcode tzbin .tzunpack
+ $(Q) $(MAKE) -C tzcode TOPDIR=$(TZBIN_PATH) install
+ $(Q) touch .tzbuilt
# Register application
-ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
+ifeq ($(CONFIG_SYSTEM_ZONEINFO_MNTCMD),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@@ -149,7 +185,7 @@ else
register:
endif
-context: tzbuild register
+context: .tzbuilt romfs register
# Create dependencies
@@ -161,14 +197,18 @@ depend: .depend
clean:
$(call DELFILE, .built)
- $(call DELDIR, tzbin)
- $(call DELDIR, tzcode)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
+ $(call DELFILE, .tzunpack)
+ $(call DELFILE, .tzbuilt)
+ $(call DELFILE, romfs_zoneinfo.img)
+ $(call DELFILE, romfs_zoneinfo.h)
$(call DELFILE, tzdata-latest.tar.gz)
$(call DELFILE, tzcode-latest.tar.gz)
+ $(call DELDIR, tzbin)
+ $(call DELDIR, tzcode)
-include Make.dep
diff --git a/apps/system/zoneinfo/tzmount.c b/apps/system/zoneinfo/tzmount.c
index def05e4f4..ca3329894 100644
--- a/apps/system/zoneinfo/tzmount.c
+++ b/apps/system/zoneinfo/tzmount.c
@@ -38,10 +38,45 @@
****************************************************************************/
#include <nuttx/config.h>
-#include <nuttx/progmem.h>
+#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
+
+#include <nuttx/fs/ramdisk.h>
+#include <apps/zoneinfo.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SYSTEM_ZONEINFO_RAMDEVNO
+# define CONFIG_SYSTEM_ZONEINFO_RAMDEVNO 1
+#endif
+
+#ifndef CONFIG_LIBC_TZDIR
+# errror CONFIG_LIBC_TZDIR is not defined
+#endif
+
+#ifdef CONFIG_DISABLE_MOUNTPOINT
+# error "Mountpoint support is disabled"
+#endif
+
+#if CONFIG_NFILE_DESCRIPTORS < 4
+# error "Not enough file descriptors"
+#endif
+
+#ifndef CONFIG_FS_ROMFS
+# error "ROMFS support not enabled"
+#endif
+
+#define SECTORSIZE 64
+#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
+
+#define STR_RAMDEVNO(m) #m
+#define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m)
+#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_SYSTEM_ZONEINFO_RAMDEVNO)
/****************************************************************************
* Private Functions
@@ -57,9 +92,32 @@ int main(int argc, FAR char *argv[])
int tzmount_main(int argc, char **argv)
#endif
{
- /* This function is currently just a placeholder. Future logic will
- * mount a ROMFS volume here that hold the TZ database.
- */
+ int ret;
+
+ /* Create a RAM disk for the test */
+
+ ret = romdisk_register(CONFIG_SYSTEM_ZONEINFO_RAMDEVNO,
+ romfs_zoneinfo_img,
+ NSECTORS(romfs_zoneinfo_img_len),
+ SECTORSIZE);
+ if (ret < 0)
+ {
+ printf("ERROR: Failed to create RAM disk\n");
+ return EXIT_FAILURE;
+ }
+
+ /* Mount the test file system */
+
+ printf("Mounting ROMFS filesystem at target=%s with source=%s\n",
+ CONFIG_LIBC_TZDIR, MOUNT_DEVNAME);
+
+ ret = mount(MOUNT_DEVNAME, CONFIG_LIBC_TZDIR, "romfs", MS_RDONLY, NULL);
+ if (ret < 0)
+ {
+ printf("ERROR: Mount failed: %d\n", errno);
+ return EXIT_FAILURE;
+ }
- return OK;
+ printf("TZ database mounted at %s\n", CONFIG_LIBC_TZDIR);
+ return EXIT_SUCCESS;
}
diff --git a/apps/system/zoneinfo/tzromfs.c b/apps/system/zoneinfo/tzromfs.c
new file mode 100755
index 000000000..8cf382db9
--- /dev/null
+++ b/apps/system/zoneinfo/tzromfs.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * apps/system/zoneinfo/tzromfs.c
+ *
+ * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 <nuttx/config.h>
+#include <apps/zoneinfo.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#include "romfs_zoneinfo.h"