RTC on BBB stop working after opkg upgrade

Hello,

Before the upgrade I was testing the RTC and it was normal, but after I runned the okpg upgrade this happens:

root@beaglebone:~# i2cdetect -y -r 1
] 0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- UU UU UU UU – -- – -- – -- – --
60: – -- – -- – -- – -- 68 – -- – -- – -- –
70: – -- – -- – -- – --
root@beaglebone:~# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
-sh: echo: write error: Invalid argument
root@beaglebone:~#

I was doing this tutorial:
http://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black/set-rtc-time

Anyone could help me?

I tried echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

and now is working, sort of, because the time it is not being set on restart.
here is my bash script:

/usr/share/rtc_ds1307/clock_init.sh

  1. echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
  2. hwclock -s -f /dev/rtc0
  3. hwclock -w

And here is my service:

/lib/systemd/system/rtc-ds1307.service

  1. [Unit]
  2. Description=DS1307 RTC Service
  3. [Service]
  4. Type=simple
  5. WorkingDirectory=/usr/share/rtc_ds1307
  6. ExecStart=/bin/bash clock_init.sh
  7. SyslogIdentifier=rtc_ds1307
  8. [Install]
  9. WantedBy=multi-user.target

My service is running on the restart, but if I run
dmesg | grep ds1307 I get:

[ 5.934660] rtc-ds1307: probe of 0-0068 failed with error -5
[ 5.970362] i2c i2c-0: new_device: Instantiated device ds1307 at 0x68

Yeah noob here, My /etc/localtime was not correct. Now the whole thing work just fine.

Hi Fernando,

Im having the same problem as you had after the update, but I’m using the BBB Rev C under Debian, and it does not get the time from the RTC during boot, but it does if I perform the commands (mentioned in the tutorial) manually:

hwclock -s -f /dev/rtc1 hwclock -w

So I’d like to ask you what did you do about the /etc/localtime to make it work, or how does this impact the RTC ?

Besides, I see in your bash script clock_init.sh, you are using:

  1. echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
  2. hwclock -s -f /dev/rtc0
  3. hwclock -w

and as far as I know this is the BBB built-in RTC’s path (not battery backened) so I wonder how is this working on your BBB ?

The Adafruit Tutorial is made for a RTC Battery Backened registered under /dev/rtc1, as follows:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device hwclock -s -f /dev/rtc1 hwclock -w

Any suggestion, comment, idea is welcome

Thanks

Regards

Hi there Ivan,

So my RTC was the problem, I fix it and now in my bash reads /rtc1 again and it is working fine.

To get my localtime working I did this

Hi Fernando,

Thanks for your quick answer and interest,

Yes, I have that service enabled and either de clock_init.sh script as the service file are exactly the same as yours, I think I found the problem but I haven’t been able to fix it beacause I can’t find a workaround,

The problem is when the next line is executed on the script:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

I get the following error:

-bash: echo: write error: Invalid argument

This does not happen under Angstrom but it does in Debian

`
root@beaglebone:/opt# systemctl status rtc-ds1307.service
rtc-ds1307.service - DS1307 RTC Service
Loaded: loaded (/lib/systemd/system/rtc-ds1307.service; enabled)
Active: inactive (dead) since Fri, 01 Aug 2014 04:22:00 -0500; 1s ago
Process: 1284 ExecStart=/bin/bash clock_init.sh (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/rtc-ds1307.service

Apr 23 15:22:20 beaglebone rtc_ds1307[1284]: clock_init.sh: line 1: echo: write error: Invalid argument
`

And this is my clock_init.sh

root@beaglebone:/opt# cat /usr/share/rtc_ds1307/clock_init.sh echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device hwclock -s -f /dev/rtc1 hwclock -w

The same trying to execute that particular line manually:

`

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

-bash: echo: write error: Invalid argument
`

So I don’t really know how to workaround this, I have tried to execute those commands using crontab without any success,

If you have any idea, please let me know

Thank you very much for your time

Best Regards

Ivan

Hi there Ivan,

So my RTC was the problem, I fix it and now in my bash reads /rtc1 again and it is working fine.

To get my localtime working I did this

root@beaglebone:~# ntpdate -b -s -u pool.ntp.org
root@beaglebone:/etc# rm localtime
root@beaglebone:/etc# ln -s /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime

You can replace with your zone. But besides the correct timezone I don’t think that localtime have something to do with the RTC.

Here is my bash:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s -f /dev/rtc1
hwclock -w

and the service:

[Unit]
Description=DS1307 RTC Service

[Service]
Type=simple
WorkingDirectory=/usr/share/rtc_ds1307
ExecStart=/bin/bash clock_init.sh
SyslogIdentifier=rtc_ds1307

[Install]
WantedBy=multi-user.target

You enable the service? because if not when you restart he will not gonna start.

Regards.

Hi Fernando,

Im having the same problem as you had after the update, but I’m using the BBB Rev C under Debian, and it does not get the time from the RTC during boot, but it does if I perform the commands (mentioned in the tutorial) manually:

hwclock -s -f /dev/rtc1 hwclock -w

So I’d like to ask you what did you do about the /etc/localtime to make it work, or how does this impact the RTC ?

Besides, I see in your bash script clock_init.sh, you are using:

  1. echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
  2. hwclock -s -f /dev/rtc0
  3. hwclock -w

and as far as I know this is the BBB built-in RTC’s path (not battery backened) so I wonder how is this working on your BBB ?

The Adafruit Tutorial is made for a RTC Battery Backened registered under /dev/rtc1, as follows:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device hwclock -s -f /dev/rtc1 hwclock -w

Any suggestion, comment, idea is welcome

Thanks

Regards

Yeah noob here, My /etc/localtime was not correct. Now the whole thing work just fine.

I tried echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

and now is working, sort of, because the time it is not being set on restart.
here is my bash script:

/usr/share/rtc_ds1307/clock_init.sh

  1. echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
  2. hwclock -s -f /dev/rtc0
  3. hwclock -w

And here is my service:

/lib/systemd/system/rtc-ds1307.service

  1. [Unit]
  2. Description=DS1307 RTC Service
  3. [Service]
  4. Type=simple
  5. WorkingDirectory=/usr/share/rtc_ds1307
  6. ExecStart=/bin/bash clock_init.sh
  7. SyslogIdentifier=rtc_ds1307
  8. [Install]
  9. WantedBy=multi-user.target

My service is running on the restart, but if I run
dmesg | grep ds1307 I get:

[ 5.934660] rtc-ds1307: probe of 0-0068 failed with error -5
[ 5.970362] i2c i2c-0: new_device: Instantiated device ds1307 at 0x68

Hello,

Before the upgrade I was testing the RTC and it was normal, but after I runned the okpg upgrade this happens:

root@beaglebone:~# i2cdetect -y -r 1
] 0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- UU UU UU UU – -- – -- – -- – --
60: – -- – -- – -- – -- 68 – -- – -- – -- –
70: – -- – -- – -- – --
root@beaglebone:~# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
-sh: echo: write error: Invalid argument
root@beaglebone:~#

I was doing this tutorial:
http://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black/set-rtc-time

Anyone could help me?

`
root@beagleboneD:/opt# systemctl status rtc-ds1307.service
rtc-ds1307.service - DS1307 RTC Service
Loaded: loaded (/lib/systemd/system/rtc-ds1307.service; enabled)
Active: inactive (dead) since Fri, 01 Aug 2014 04:22:35 -0500; 441ms ago
Process: 1299 ExecStart=/bin/bash clock_init.sh (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/rtc-ds1307.service

Aug 01 04:22:33 beagleboneD rtc_ds1307[1299]: clock_init.sh: line 1: echo: write error: Invalid argument

`

Hi Ivan,

Your RTC is fine? the battery is charged? because I had the same error before the guys that I work with fixed the RTC.

I asume it’s working fine Fernando, since I can get the correct date manually using the hwclock command, this is what I get:

The first time the BBB is Turned on

root@beaglebone:/debian# date Wed Apr 23 15:22:42 CDT 2014

Read the date and time from RTC

root@beaglebone:/debian# hwclock -r -f /dev/rtc1 Fri Aug 1 13:44:15 2014 -0.907724 seconds

Put that date and time to the system

root@beaglebone:/debian# hwclock -s -f /dev/rtc1 root@beaglebone:/debian# date Fri Aug 1 13:44:29 CDT 2014

I don’t really understand what is happening, the permissions of that new_device file writtiable:

root@beaglebone:/sys/class/i2c-adapter/i2c-1# ll | grep new --w------- 1 root root 4096 Dec 31 1999 new_device

What do think?

Thanks for taking the time

Best regards

Ivan

Ivan try this, in the .sh remove the part that is causing problem and then reboot to see if it works.

Ok just tried removing that line from the .sh file, and unfortunately I had no luck:

After reboot it shows factory date:

root@beaglebone:# date Wed Apr 23 15:20:28 CDT 2014

status of the service:

`
root@beaglebone:# systemctl status rtc-ds1307.service
rtc-ds1307.service - DS1307 RTC Service
Loaded: loaded (/lib/systemd/system/rtc-ds1307.service; enabled)
Active: inactive (dead) since Wed, 23 Apr 2014 15:20:00 -0500; 46s ago
Process: 618 ExecStart=/bin/bash clock_init.sh (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/rtc-ds1307.service

Dec 31 18:00:09 beaglebone rtc_ds1307[618]: hwclock: Cannot access the Hardware Clock via any known method.
Dec 31 18:00:09 beaglebone rtc_ds1307[618]: hwclock: Use the --debug option to see the details of our search for an access method.
`

I have no idea how to continue

I tried also to modify the system source from the RTC clock modifying the file /lib/udev/hwclock-set

BADYEAR=no
HWCLOCKACCESS=yes
HWCLOCKPARS=
#HCTOSYS_DEVICE=rtc0
HCTOSYS_DEVICE=rtc1

But it didn´t work neither, I might need to find another solution for it

Thanks

Sorry I couldn’t help you, I have no idea what is the problem.

Best regards.

Not a problem I really appreciate your help Fernando, thanks for taking the time to answer the questions I should find the root cause for it and get a workaround, If I do I’ll put it here to be useful for somebody else,

Thanks