Jump to content

Odroid HC4 enable RTC clock


alecunsolo

Recommended Posts

Based on that wiki, it looks like it's probably the same RTC chip (pcf8563), and similar config between the C4 and N2, at least for the HardKernel kernel, which Armbian would probably mark as "legacy". You might be able to enable it in armbian-config, but long term it'd probably serve you better to keep the mainline kernel.

 

I'd probably start seeing if you can enable it manually with sudo or a root shell. Take a look HERE, which shows how to enable it manually. i2cdetect can verify if your RTC is visible on a given I2C bus (may need to test a bus other than 0).  Based on the wiki, it should probably be at address 0x51, and probably end up with a command like this:

 

# echo pcf8563 0x51 > /sys/class/i2c-adapter/i2c-0/new_device

 

Or on i2c-1, or whatever bus it's on. And then see if you can read your RTC via "hwclock". If you can, then you know what the tell the Linux kernel. You can do this through a Device Tree Overlay, or via a SystemD script which will run on startup.

 

If you go the overlay route, you'll need to see that the below block ends up inside the the DTB inside the appropriate I2C bus. The extra stuff in each overlay file just sorta specifies where your changes are going. Decompile your DTB with "dtc -o meson-sm1-odroid-hc4.dts meson-sm1-odroid-hc4.dtb", and take a look at the resulting DTS file to see what I mean.

 

rtc@51 {
	compatible = "nxp,pcf8563";
	reg = <0x51>;
};

 

Another way which may be more approachable is the SystemD route (see HERE). Basically you'd be writing a short script, and telling SystemD to start it on boot.

 

 

Link to comment
Share on other sites

Thank for the reply.

I can enable the rtc manually:

# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
# echo pcf8563 0x51 > /sys/class/i2c-adapter/i2c-0/new_device
# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
# ls /dev/rt*
/dev/rtc  /dev/rtc0  /dev/rtc1
# hwclock --rtc /dev/rtc1
2021-02-08 08:54:57.164679+00:00

I think the overlay is a cleaner solution, so I decompiled the "/boot/dtb/amlogic/meson-sm1-odroid-hc4.dtb"  (https://pastebin.com/FHJW3WN9) and try to make an overlay based on this post:

/dts-v1/;
/plugin/;

/ {
	fragment@0 {
		target-path = "/soc/bus@ffd00000/i2c@1d000";
		__overlay__ {
			pcf8563: rtc@51 {
				compatible = "nxp,pcf8563";
				reg = <0x51>;
			};
		};
	};
};

but when I tried to use the armbian-add-overlay script I got

sudo armbian-add-overlay pcf8563.dts
Overlays are not supported on Meson64 based boards.

So meson boards don't support overlays? Or is the script not up-to-date?

Link to comment
Share on other sites

Have you tried adding it as a user overlay?

Basically create a folder '/boot/overlay-user'. Compile your plugin with the usual 'dtc -I dts -O dtb [your file] -o [output name].dtbo' and put it into the created directory. Then edit '/boot/armbianEnv.txt' and add the line 'user_overlays=[output name]'. That is what worked for me every time so far.

 

 

Link to comment
Share on other sites

I've never really spent too much time using overlays myself, but I did some digging, and this is what I found:

 

In armbian-add-overlay, you have this chunk of code, which is generating the error.

 

case "${LINUXFAMILY}" in
        sunxi|sunxi64|rk3399|rockchip64|rockpis)
                :;;
        *)
                echo >&2 "Overlays are not supported on ${LINUXFAMILY^} based boards."
                exit -1
                ;;
esac

 

But what the script seems to do:

  1. Compiles the given dts file into a dtbo
  2. Copies the dtbo to /boot/overlay-user
  3. Adds "user_overlays=" to /boot/armbianEnv.txt and includes the given overlay file

 

Given that the following is in the ODroid C4 (Amlogic / meson64) image (/boot/boot.cmd), I'm tempted to say it's an oversight.

        for overlay_file in ${user_overlays}; do
                if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then
                        echo "Applying user provided DT overlay ${overlay_file}.dtbo"
                        fdt apply ${load_addr} || setenv overlay_error "true"
                fi
        done

 

So yeah, I'd suggest doing Genna suggests, or fix the script so it doesn't fail.

 

Also, file a bug on the armbian-add-overlay script, or even better, a PR that fixes it

Link to comment
Share on other sites

Sorry for the delay.

Yes, manually using the user-overlay worked, so it is an oversight in the armbian-add-script.

I was going to do a simple PR, but I think the issue was already addressed (and in a more elegant way) with this PR

 

Thank you

 

(I just noticed that the author of the PR is you @tparys )

Edited by alecunsolo
Missing information
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines