Adding RTC to OpenWrt devices (part 2)

Some time ago I wrote how to add Real Time Clock (RTC) support to OpenWrt.

Currently support for RTC chip DS1370 is still not 100% there in OpenWrt because there is a bug that causes OpenWrt builder to just skip over compiling RTC kernel modules. Tools are there, driver is there, but you have to compile them manually.

In this article I'll give detailed step by step instructions on how to compile all needed kernel modules and to get them up and running.

First step is to download whole OpenWrt source tree from github and to do basic steps for configuring default config make file:

git clone
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig

and to add few config options via make menuconfig, in this example I used Carambola 2 board so I configured ar71xx as targed and carambola2 as device.

echo "CONFIG_TARGET_ar71xx=y
CONFIG_PACKAGE_kmod-rtc-ds1307=y" >> .config

make defconfig

Make sure to use correct TARGET and DEVICE for your own hardware.

Next step is to download all dependencies and then compile:

make download
ionice -c 3 nice -n19 make -j10

add this line to /etc/rc.local:

echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device

and maka sure i2c via bitbanging is correctly initialized:

echo "i2c-gpio-custom bus0=0,19,18" > /etc/modules.d/i2c-gpio-custom

If you get a response from i2cdetect -y 0 then you can start using your RTC hardware clock:

hwclock -r ... to "read" contents of RTC
hwclock -s ... to "set" time/date from contents of RTC
hwclock -w ... to "write" current date into RTC