Move the TZ/Olson zoneinfo data set from apps/system/zoneinfo to libc/zoneinfo

This commit is contained in:
Gregory Nutt 2016-06-30 15:40:37 -06:00
parent 599c7963e8
commit aa96a1d2ec
13 changed files with 398 additions and 17 deletions

View file

@ -345,6 +345,7 @@ nuttx/
|- lib/
| `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/lib/README.txt" target="_blank">README.txt</a>
|- libc/
| |- <a href="https://bitbucket.org/nuttx/nuttx/src/master/libc/zoneinfo/README.txt" target="_blank">zoneinfo/README.txt</a>
| `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/libc/README.txt" target="_blank"><b><i>README.txt</i></b></a>
|- libnx/
| `- <a href="https://bitbucket.org/nuttx/nuttx/src/master/libnx/README.txt" target="_blank"><b><i>README.txt</i></b></a>
@ -402,8 +403,7 @@ apps/
|- <a href="https://bitbucket.org/nuttx/apps/src/master/system/nxplayer/README.txt" target="_blank"><b><i>nxplayer/README.txt</i></b></a>
|- <a href="https://bitbucket.org/nuttx/apps/src/master/system/symtab/README.txt" target="_blank"><b><i>symtab/README.txt</i></b></a>
|- <a href="https://bitbucket.org/nuttx/apps/src/master/system/usbmsc/README.txt" target="_blank">usbmsc/README.txt</a>
|- <a href="https://bitbucket.org/nuttx/apps/src/master/system/zmodem/README.txt" target="_blank">zmodem/README.txt</a>
`- <a href="https://bitbucket.org/nuttx/apps/src/master/system/zoneinfo/README.txt" target="_blank">zoneinfo/README.txt</a>
`- <a href="https://bitbucket.org/nuttx/apps/src/master/system/zmodem/README.txt" target="_blank">zmodem/README.txt</a>
</pre></ul>
<p>

View file

@ -1524,6 +1524,8 @@ nuttx/
|- lib/
| `- README.txt
|- libc/
| |- zoneinfo
| | `- README.txt
| `- README.txt
|- libnx/
| `- README.txt
@ -1590,9 +1592,7 @@ apps/
| | `- README.txt
| |- usbmsc
| | `- README.txt
| |- zmodem
| | `- README.txt
| `- zoneinfo
| `- zmodem
| `- README.txt
`- README.txt

View file

@ -8991,7 +8991,7 @@ Additional new features and extended functionality:
* Applications: apps/system:
- apps/system/zoneinfo: Add logic to build a ROMFS file system
- nuttx/zoneinfo: Add logic to build a ROMFS file system
containing the timezone data.
* Applications: apps/nshlib:

View file

@ -48,12 +48,12 @@ endif
ifeq ($(CONFIG_BOARD_INITIALIZE),y)
CSRCS += sim_bringup.c
ifeq ($(CONFIG_SYSTEM_ZONEINFO_ROMFS),y)
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
CSRCS += sim_zoneinfo.c
endif
else ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sim_bringup.c
ifeq ($(CONFIG_SYSTEM_ZONEINFO_ROMFS),y)
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
CSRCS += sim_zoneinfo.c
endif
endif

View file

@ -73,7 +73,7 @@ int sim_bringup(void);
* Name: sim_zoneinfo
*
* Description:
* Mount the TZ database. The apps/system/zoneinfo directory contains
* Mount the TZ database. The nuttx/zoneinfo directory contains
* logic to create a version of the TZ/Olson database.
* This database is required if localtime() support is selected via
* CONFIG_LIBC_LOCALTIME. This logic in that directory does the following:
@ -107,7 +107,7 @@ int sim_bringup(void);
*
****************************************************************************/
#ifdef CONFIG_SYSTEM_ZONEINFO_ROMFS
#ifdef CONFIG_LIB_ZONEINFO_ROMFS
int sim_zoneinfo(int minor);
#endif

View file

@ -71,7 +71,7 @@ int sim_bringup(void)
int ret;
#endif
#ifdef CONFIG_SYSTEM_ZONEINFO_ROMFS
#ifdef CONFIG_LIB_ZONEINFO_ROMFS
/* Mount the TZ database */
(void)sim_zoneinfo(3);

View file

@ -1,7 +1,7 @@
/****************************************************************************
* config/sim/src/sim_zoneinfo.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -45,9 +45,9 @@
#include <errno.h>
#include <nuttx/fs/ramdisk.h>
#include <apps/zoneinfo.h>
#include <nuttx/zoneinfo.h>
#ifdef CONFIG_SYSTEM_ZONEINFO_ROMFS
#ifdef CONFIG_LIB_ZONEINFO_ROMFS
/****************************************************************************
* Pre-processor Definitions
@ -80,7 +80,7 @@
* Name: sim_zoneinfo
*
* Description:
* Mount the TZ database. The apps/system/zoneinfo directory contains
* Mount the TZ database. The nuttx/zoneinfo directory contains
* logic to create a version of the TZ/Olson database.
* This database is required if localtime() support is selected via
* CONFIG_LIBC_LOCALTIME. This logic in that directory does the following:
@ -149,5 +149,5 @@ int sim_zoneinfo(int minor)
return OK;
}
#endif /* CONFIG_SYSTEM_ZONEINFO_ROMFS */
#endif /* CONFIG_LIB_ZONEINFO_ROMFS */

83
include/nuttx/zoneinfo.h Normal file
View file

@ -0,0 +1,83 @@
/****************************************************************************
* include/nuttx/zoneinfo.h
*
* Copyright (C) 2016 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 __INCLUDE_NUTTX_ZONEINFO_H
#define __INCLUDE_NUTTX_ZONEINFO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_LIB_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_LIB_ZONEINFO_ROMFS */
#endif /* __INCLUDE_NUTTX_ZONEINFO_H */

View file

@ -288,7 +288,7 @@ config LIBC_LOCALTIME
environment variable TZ must be set to the name of that timezone file
when tzset() is called.
See https://www.iana.org/time-zones . See also apps/system/zoneinfo
See https://www.iana.org/time-zones . See also nuttx/zoneinfo
which provides a framework for incorporating the TZ database into a
NuttX build.
@ -884,3 +884,21 @@ config LIB_HEX2BIN
---help---
Build in support for conversions from Intel Hex format to binary.
This selection enables the interfaces of include/hex2bin.h.
config LIB_ZONEINFO
bool "TZ database"
default n
depends on LIBC_LOCALTIME
---help---
Build the TZ/Olson database.
if LIB_ZONEINFO
config LIB_ZONEINFO_ROMFS
bool "Build ROMFS filesystem"
default n
depends on FS_ROMFS
---help---
Build a mountable ROMFS filesystem containing the TZ database
endif # LIB_ZONEINFO

2
libc/zoneinfo/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/romfs_zoneinfo.h

47
libc/zoneinfo/Make.defs Normal file
View file

@ -0,0 +1,47 @@
############################################################################
# nuttx/zoneinfo/Make.defs
#
# Copyright (C) 2016 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.
#
############################################################################
ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
# Add the zoneinifo sources to the build
CSRCS += tzromfs.c
# Add the zoneinfo directory to the build
DEPPATH += --dep-path zoneinfo
VPATH += :zoneinfo
endif

180
libc/zoneinfo/README.txt Normal file
View file

@ -0,0 +1,180 @@
apps/system/zoninfo/README.txt
Author: Gregory Nutt <gnutt@nuttx.org>
Directory Contents
==================
This directory contains logic to create a version of the TZ/Olson database.
This database is required if localtime() support is selected via
CONFIG_LIBC_LOCALTIME. This logic in this directory does the following:
- It downloads the current TZ database from the IANA website
- It downloads the current timezone tools from the same location
- It builds the tools and constructs the binary TZ database
- It will then, optionally, build a ROMFS filesystem image containing
the data base.
Creating and Mounting a ROMFS TZ Database
=========================================
The ROMFS filesystem image can that be mounted during the boot-up sequence
so that it is available for the localtime() logic. There are two steps to
doing this:
- First, a ROM disk device must be created. This is done by calling
the function romdisk_register() as described in
nuttx/include/nuttx/fs/ramdisk.h. This is an OS level operation
and must be done in the board-level logic before your application
starts.
romdisk_register() will create a block driver at /dev/ramN where N
is the device minor number that was provided to romdisk_regsiter.
- The second step is to mount the file system. This step can be
performed either in your board configuration logic or by your
application using the mount() interface described in
nuttx/include/sys/mount.h.
These steps, however, must be done very early in initialization,
before there is any need for time-related services.
Both of these steps are shown together in the following code sample at the
end of this README file.
Example Configuration
=====================
I have tested this using the sim/nsh configuration. Here are the
modifications to the configuration that I used for testing:
CONFIG_BOARD_INITIALIZE=y
CONFIG_LIBC_LOCALTIME=y
CONFIG_LIBC_TZDIR="/share/zoneinfo"
CONFIG_LIBC_TZ_MAX_TIMES=370
CONFIG_LIBC_TZ_MAX_TYPES=20
CONFIG_LIB_ZONEINFO=y
CONFIG_LIB_ZONEINFO_ROMFS=y
NOTE: The full TZ database is quite large. To create a reasonable sized
ROMFS image, I had to trim some of the files like this:
cd nuttx
cd tools
./configure.sh sim/nsh
cd ..
make menuconfig
Select the above localtime() and nuttx/zoneinfo configuration settings.
Then:
make context
cd ../nuttx/zoneinfo/tzbin/etc/zoneinfo
Remove as many timezone files as you can. Do not remove the GMT, localtime,
or posixrules files. Those might be needed in any event. Then you can
force rebuilding of the ROMFS filesystem be removing some files:
cd ../../..
rm romfs_zoneinfo.*
rm *.o
cd ../../nuttx
make
If you have problems building the simulator on your platform, check out
nuttx/configs/sim/README.txt. You might find some help there.
Here is a sample run. I have not seen any errors in single stepping through
the logic but neither am I certain that everything is working properly:
NuttShell (NSH)
nsh> date
Jul 01 00:00:02 2008
nsh> set TZ US/Mountain
nsh> date -s "Apr 11 11:53:00 2015"
nsh> date
Apr 11 17:53:00 2015
NOTE: Because of daylight savings time, US/Mountain is GMT-6 on Apr 11. The
above suggests that perhaps the NSH data command may be setting local time,
but printing GMT time?
Sample Code to Mount the ROMFS Filesystem
=========================================
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <nuttx/fs/ramdisk.h>
#include <nuttx/zoneinfo.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#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)
/****************************************************************************
* Public Functions
****************************************************************************/
int mount_zoneinfo(int minor)
{
char devname[32];
int ret;
/* Create a RAM disk for the test */
ret = romdisk_register(minor, romfs_zoneinfo_img,
NSECTORS(romfs_zoneinfo_img_len), SECTORSIZE);
if (ret < 0)
{
printf("ERROR: Failed to create RAM disk\n");
return ret;
}
/* Use the minor number to create a name for the ROM disk block device */
snprintf(devname, 32, "/dev/ram%d", minor);
/* Mount the ROMFS file system */
printf("Mounting ROMFS filesystem at target=%s with source=%s\n",
CONFIG_LIBC_TZDIR, devname);
ret = mount(devname, CONFIG_LIBC_TZDIR, "romfs", MS_RDONLY, NULL);
if (ret < 0)
{
printf("ERROR: Mount failed: %d\n", errno);
return ret;
}
printf("TZ database mounted at %s\n", CONFIG_LIBC_TZDIR);
return OK;
}

51
libc/zoneinfo/tzromfs.c Normal file
View file

@ -0,0 +1,51 @@
/****************************************************************************
* nuttx/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 <nuttx/zoneinfo.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#include "romfs_zoneinfo.h"