Adding kernel modules (1-wire sensors) - also compiling coreelec

I want to connect a DS18B20 thermal sensor to my odroid-c2 running CoreELEC. It’s supported via the w1_gpio and w1_therm kernel modules, but CoreELEC does not include them in the distribution. For the record, in raspbian these kernel modules take about 256k of disk space.

My first attempt was to try to rebuild a CoreELEC image, and then just copy the kernel modules over to see if that would work. I cloned the github repo, checked out tag 9.0.2 (current release), and ran “make” in the repo. It started building, and many things built correctly include the linux kernel, but runs into trouble when compiling u-boot-LePotato. I’ve put a log file up at https://pastebin.com/pBiwukux but it seems to be related to libfdt.h, it’s somehow apparently pulling in my local copy of header files instead of the dev environment ones.

So that’s problem number 1.

I figured that even though u-boot-LePotato doesn’t build, the kernel does, so I can just modify the kernel configuration and recompile that. However, when I try to run “make menuconfig” within the linux-${SHA256SUM} folder, I get
make: *** No rule to make target linux-${SHA256SUM}//arch/Makefile. Stop.

I’m guessing this is because the kernel is being cross-compiled, and I’m not specifying that, but I don’t know how to specify the cross-compilation details for the linux kernel. Is there an easy way to adjust the kernel configuration within CoreELEC?

Okay, I worked out the command for menuconfig, it is
make menuconfig ARCH=arm64 HOSTCC=…/toolchain/bin/host-gcc HOSTCXX=…/toolchain/bin/host-g++

With that, I was then able to build the linux kernel (and modules) with w1_gpio and w1_therm modules. Since the system is read-only on CoreELEC, I copied the module files to flash, and used insmod ./w1-gpio.ko to load them, and they loaded fine. I have not yet tested them, as I did this remotely and still need to connect an actual thermal sensor, but this part appears to be working.

Slow progress recently. The w1-gpio master is not being detected, probably because the device tree doesn’t have a onewire section. I’m fiddling around with adding the onewire section from Armbian, or from the hardkernel sources, but I’m not as yet having any luck with getting it noticed.

Have you read this: https://wiki.odroid.com/odroid-n2/application_note/gpio/1wire ?

Yup, but the problem is that those instructions expect you to already have a onewire section in your FDT, which is not true in CoreELEC (fdtget /flash/dtb.img /onewire gpios gives FDT_ERR_NOTFOUND). I’ve tried modifying boot.ini to load the overlay (meson-w1-gpio.dtbo) but all attempts to do that resulted in a non-booting C2. I’ve also tried adding “fdt put” commands in boot.ini, this results in a booting system that has some /onewire parts in the FDT, but the kernel complains about not being able to find the phandle, which seems to be a result of not properly loading the overlay but manually inserting only bits and pieces of the fdt. I’m not that hugely fussed about this, so I’m tempted to just fast-forward my plans to get an rpi zero to control the lighting, and use that for the temp sensor as well, as at this point I think it’s a simpler way forward.

Core922:~ # fdtget /flash/dtb.img /onewire gpios
25 63 0

CoreELEC:/flash # fdtget /flash/dtb.img /onewire gpios
Error at ‘/onewire’: FDT_ERR_NOTFOUND

That’s the message I get on my C2.

Have you tried modprobe w1-gpio && modprobe w1-therm?
It should work.
Which build you use?
I tried in latest nightly on my N2.

With the CoreELEC image, neither of those modules exist. If I build them manually and copy them over, I can insmod them, and dmesg shows “Driver for 1-wire Dallas network protocol.”, but the master is not detected (nor any slave devices).

This is all with the latest stable, on a C2, not N2.

That’s right, there is no onewire entry in the 3.14 kernel DTBs.

Hello, I am new here and have also a question :slight_smile:

I have now installed 20.1-Nexus on an ODROID N2+. Runs great, thanks for that.

Now I want to connect OneWire temperature sensors, For this I loaded the modules w1_gpio and w1_therm, that worked so far:

lsmod |grep w1
w1_gpio 16384 0
w1_therm 16384 0
wire 45056 2 w1_gpio,w1_therm

The folder /sys/bus/w1 was also created, but I don’t see any of the connected devices, not even w1_bus_master.
I have read that you have to activate the OneWire bus with overlay=onewire but I can’t find a place to enter this.

Does OneWire generally work under CoreELEC and if so how can I set it up?

Thanks and greetings
horchi

Is it a boot parameter?

Then modify your config.ini

Like coreelec='quiet overlay=onewire'

Not sure. Overlay dts is not supported. Maybe you need to edit dtb.img DT?

Node is needed in DTB. Like that with correct gpio name.

	onewire {
		compatible = "w1-gpio";
		pinctrl-names = "default";
		gpios = <&gpio GPIOZ_15 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

Ihx, I now added this to /flash/config.ini and booted

#------------------------------------------------------------------------------------------------------
#
# CoreELEC Developer Options
#   Valid options are: textmode debugging progress nofsck nosplash noram overlay quiet ssh
#
# coreelec='quiet'
#
#------------------------------------------------------------------------------------------------------

coreelec='overlay=onewire'

unfortunately nothing changed so far.

Regarding:

onewire {
		compatible = "w1-gpio";
		pinctrl-names = "default";
		gpios = <&gpio GPIOZ_15 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

where do i have to enter this? I’m sorry I’m completely new to CodeELEC.

On which GPIO you want to use 1-wire? And I will make you device tree file.

I assume GPIOX_7 as writtent here?

https://wiki.odroid.com/odroid-n2/application_note/gpio/1wire

yes GPIOX_7 will be fine.

Thank you!

mount -o remount,rw /flash
cp /flash/dtb.img /flash/dtb.img-orig
megadl https://mega.nz/file/vFginTwJ#WFOhz_KjLovlUdQr_pqu9ZGdU1wwXITLJsIjkRIbhqU
mv g12b_s922x_odroid_n2.dtb-w1-gpio /flash/dtb.img
sync
reboot

installed as you described and rebooted. This I have still in /flash/config.ini:

coreelec='overlay=onewire'

It seems still not working:

pooluhd:~ # ll /sys/bus/w1/devices/
total 0      
drwxr-xr-x    2 root     root           0 Mar 27 11:10 .
drwxr-xr-x    4 root     root           0 Mar 27 11:10 ..

and

pooluhd:~ # fdtget /flash/dtb.img /onewire gpios
Error at '/onewire': FDT_ERR_NOTFOUND

I’ve loaded the modules

pooluhd:~ # lsmod |grep w1
w1_therm               16384  0
w1_gpio                16384  0
wire                   45056  2 w1_gpio,w1_therm

regarding dmesq the Kernel command line shows the onewire option:

[    0.000000@0]d Kernel command line: BOOT_IMAGE=kernel.img boot=UUID=1603-2730 disk=UUID=106ceae0-5f77-47ce-9133-946bfaf1aff6 console=ttyS0,115200 console=tty0 no_console_suspend keymap=de   enable_wol=1  remotewakeup=0x800f040c decode_type=0x5 remotewakeupmask=0xffff7fff     vout=1080p60hz,en logo=osd0,loaded,0x3d800000 frac_rate_policy=0 native_4k_gui=0 hdr_policy=1 overlay=onewire  systemd.show_status=auto

Any idea what I’m doing wrong?

overlay=onewire is not needed and has no effect. Remove it.

And sorry, I put onewire node at wrong place. This one should work.

same result:

pooluhd:~ # fdtget /flash/dtb.img /onewire gpios
Error at '/onewire': FDT_ERR_NOTFOUND
pooluhd:~ # ll /sys/bus/w1/devices/
total 0      
drwxr-xr-x    2 root     root           0 Mar 27 15:28 .
drwxr-xr-x    4 root     root           0 Mar 27 15:28 ..