Resolving time zone issues in embedded Linux

Source: Internet
Author: User

If let me do the work of the upper software, I can do it handy, but let me do platform work (System problem solving, driver writing, software porting, etc.), really unfamiliar. So many problems are stones, no experience. Many problems are a piece of cake for experienced friends, and it is always in front of me to meet the mountain. Be laughed at as a "weak chicken" ~

Recently I was doing research and development on the home gateway based on the Realtek chip rtl8196e. Realtek provides an SDK development environment for Linux. Because there is no RTC on the hardware, the clocks in which the Linux system (hereinafter referred to as RTLinux) are not correct. Time synchronization is required. I have integrated the ntpd from the BusyBox. However, I found that even if the time is synchronized, the time zone is incorrect when the date command output is executed.

I have found many ways to set the time zone for Linux systems on the Internet. From the section: Link the/usr/share/zoneinfo/asia/shanghai symbol to/etc/localtime. I tried it on my PC Linux (hereinafter referred to as Pclinux) and it worked. The same approach applied to rtlinux without a little effect.

This is the blogger wants to complain two sentences: the information found on the internet is mostly to tell you how to do to achieve what goal, and did not explain why to do so, its intrinsic principle is what. If you do not know why, then once a little change, there is no flexibility.

There are two ways to solve the problem:

    1. Set the/etc/tz file to indicate the time zone in the file

    2. Setting the TZ environment variable

If the reader does not want to delve into its reasons, then the content behind it will not have to be looked at.

Bloggers first found/etc/tz This file seems to mean the time zone, the content is: PST8PDT7, do not know what it means. Try to change it.

Go to BusyBox to find "/etc/tz", see who is, how practical this file. No related references were found.

Go to the Linux kernel to find it. There is no ~

Go and find it in the boards. Results found:

Can be seen in the romfs/lib/libc.so.0 C library file.

This library file is copied from the Toolchain tool set.

Then went to toolchain down to find, the result is many:

Then the problem of the district was decided by UCLIBC.

Go and see how the/etc/tz file is resolved in uclibc/libc/misc/time/time.c.

The Read_tz_file () function reads data from the __UCLIBC_TZ_FILE_PATH__ macro (the value "/etc/tz") refers to the file.

Set the time zone in _time_tzset (int use_old_rules).

Approximate process:

E = getenv ("TZ"); if (!e &&! ( E = Read_tz_file (BUF))) | | !*e) {//! ERROR}

Visible,e is first read from the environment variable, and if it is not read from the/etc/tz ? ?,? ? That's the principle we want.

Next is a big push to parse related processing. I will not take the time to study the process, mainly to see if there is no relevant documentation.

In UCLIBC's official website: http://www.uclibc.org/FAQ.html to find "TZ", there are:

Find Answers in http://lists.uclibc.org/pipermail/uclibc/2002-August/004010.html:

OK, I got it all figured out. If it is in China, then the variable should be set to: "CST-8", try:

Success!

There are now two scenarios:

    • Write to the/etc/tz file directly to the time zone information

    • Set environment variable TZ at system startup

Both of these can be done. We'll write "CST-8" in the/etc/tz file by default.

Problem Solving!


Resolving time zone issues in embedded Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.