User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Tue May 03, 2016 9:42 pm

Want to play a little bit with Dynamic Device Tree, but unfortunately having issue on my RPi3:

Folder /sys/kernel/config is empty

Using own kernel (currently 4.4.8), because root fs is btrfs so I can't use standard kernel. But rest of config is bcm2709_defconfig

I suppose kernel image has flag required, mkknlimg reports

Code: Select all

Version: Linux version 4.4.8+ (manfred@kmnote5.kmhome.com) (gcc version 4.9.3 20141031 (prerelease) (Linaro GCC 2014.11) ) #1 SMP Tue May 3 23:08:56 CEST 2016
DT: y
DDT: y
270x: y
283x: n
So, what I'm missing :?:

Any hints? Thanks

User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Tue May 03, 2016 9:59 pm

I have been experimenting with dynamic loading of overlays today but unfortunately it does not work

My /sys/kernel/config folder is empty

I'm using a self built kernel (4.4.8) because root fs is BTRFS, so I can not use standard kernel. But rest of config is bcm2709_defconfig.

Kernel images should be flagged correctly, because mkknlimg reports

Code: Select all

Version: Linux version 4.4.8+ (gcc version 4.9.3 20141031 (prerelease) (Linaro GCC 2014.11) ) #1 SMP Tue May 3 23:08:56 CEST 2016
DT: y
DDT: y
270x: y
283x: n
I suppose DDT means DynamicDeviceTree ;)

So what I'm missing :?:

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3321
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Upcoming Device Tree changes

Wed May 04, 2016 8:11 am

The DDT (yes, Dynamic Device Tree) detection isn't 100% accurate because the configfs support depends on modules.

Are you building from the rpi-4.4.y tree? If so, which commit do you have as your HEAD? Our tree contains some additional patches that are required to support the configfs overlay interface.

I suggest you try bcm2709_defconfig with no modifications first, and save a copy of .config. Then if that works try your changed configuration, take another copy of .config and post the diff of the two.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3321
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Upcoming Device Tree changes

Wed May 04, 2016 8:17 am

@skywatch The next Raspbian release (being prepared now) will include changes to the DTBs, overlays, utilities and lxpanel to make it possible to dynamically load and remove audio devices. There are almost bound to be some problem cases, but we'll be a few steps closer to a system that is fully reconfigurable at run time.

User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Wed May 04, 2016 11:14 am

PhilE wrote: Are you building from the rpi-4.4.y tree? If so, which commit do you have as your HEAD? Our tree contains some additional patches that are required to support the configfs overlay interface.
Yes I did

This is latest commit: 26f3b72a9c049be10e6af196252283e1f6ab9d1f

This is kernel source 'm using: https://github.com/xbianonpi/xbian-sour ... /rpi-4.4.y
PhilE wrote: I suggest you try bcm2709_defconfig with no modifications first, and save a copy of .config. Then if that works try your changed configuration, take another copy of .config and post the diff of the two.
As already told, I can not use defconfig without modification because have to have BTRFS in kernel not as module.

This is my diff between .config after defconfig and my .config

Code: Select all

--- .config.defconfig   2016-05-03 22:38:45.044292835 +0200
+++ .config     2016-05-03 23:05:19.062841098 +0200
@@ -32,7 +32,7 @@
 CONFIG_INIT_ENV_ARG_LIMIT=32
 CONFIG_CROSS_COMPILE=""
 # CONFIG_COMPILE_TEST is not set
-CONFIG_LOCALVERSION="-v7"
+CONFIG_LOCALVERSION=""
 # CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_LZMA=y
@@ -4722,7 +4722,7 @@
 CONFIG_OCFS2_FS_STATS=y
 CONFIG_OCFS2_DEBUG_MASKLOG=y
 # CONFIG_OCFS2_DEBUG_FS is not set
-CONFIG_BTRFS_FS=m
+CONFIG_BTRFS_FS=y
 CONFIG_BTRFS_FS_POSIX_ACL=y
 # CONFIG_BTRFS_FS_CHECK_INTEGRITY is not set
 # CONFIG_BTRFS_FS_RUN_SANITY_TESTS is not set
@@ -5166,7 +5166,7 @@
 # CONFIG_SECURITYFS is not set
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
-CONFIG_XOR_BLOCKS=m
+CONFIG_XOR_BLOCKS=y
 CONFIG_ASYNC_CORE=m
 CONFIG_ASYNC_MEMCPY=m
 CONFIG_ASYNC_XOR=m
@@ -5284,8 +5284,8 @@
 # CONFIG_CRYPTO_ZLIB is not set
 CONFIG_CRYPTO_LZO=m
 # CONFIG_CRYPTO_842 is not set
-# CONFIG_CRYPTO_LZ4 is not set
-# CONFIG_CRYPTO_LZ4HC is not set
+CONFIG_CRYPTO_LZ4=y
+CONFIG_CRYPTO_LZ4HC=y
 
 #
 # Random Number Generation
@@ -5325,7 +5325,7 @@
 #
 # Library routines
 #
-CONFIG_RAID6_PQ=m
+CONFIG_RAID6_PQ=y
 CONFIG_BITREVERSE=y
 CONFIG_HAVE_ARCH_BITREVERSE=y
 CONFIG_RATIONAL=y
@@ -5351,10 +5351,11 @@
 # CONFIG_AUDIT_ARCH_COMPAT_GENERIC is not set
 # CONFIG_RANDOM32_SELFTEST is not set
 CONFIG_ZLIB_INFLATE=y
-CONFIG_ZLIB_DEFLATE=m
+CONFIG_ZLIB_DEFLATE=y
 CONFIG_LZO_COMPRESS=y
 CONFIG_LZO_DECOMPRESS=y
-CONFIG_LZ4_COMPRESS=m
+CONFIG_LZ4_COMPRESS=y
+CONFIG_LZ4HC_COMPRESS=y
 CONFIG_LZ4_DECOMPRESS=y
 CONFIG_XZ_DEC=y
 CONFIG_XZ_DEC_X86=y

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3321
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Upcoming Device Tree changes

Wed May 04, 2016 11:45 am

As already told, I can not use defconfig without modification because have to have BTRFS in kernel not as module.
You've missed the point. I want you to build a kernel the standard way to confirm that it works, even though it won't contain all the features you want. You can then modify the configuration step by step until it no longer works. If, of course, the kernel with the original configuration still has an empty /sys/kernel/config then the problem isn't the modified configuration.

What do get from dmesg just after boot?

User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Wed May 04, 2016 11:59 am

PhilE wrote: You've missed the point. I want you to build a kernel the standard way to confirm that it works, even though it won't contain all the features you want. You can then modify the configuration step by step until it no longer works. If, of course, the kernel with the original configuration still has an empty /sys/kernel/config then the problem isn't the modified configuration.
Ok, will try this. Using your unmodified sources from rpi-4.4.y branch build kernel with bcm2709_defconfig and see what happens. Will report later
PhilE wrote: What do get from dmesg just after boot?
That's what I get: http://paste.debian.net/680435/

Thanks for your help

User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Wed May 04, 2016 12:44 pm

@PhilE

Did it, but unfortunately no success. Folder is still empty.

Of course, can not boot into installed system (no btrfs in kernel) but recovery console is up

/sys fs is mounted but /sys/kernel/config is empty

What about firmware, do I need special fw, mine is from Apr 28, or special dtb file?
Or do I have to modify /boot/config.txt or /boot/cmdline.txt to make it work?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3321
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Upcoming Device Tree changes

Wed May 04, 2016 1:15 pm

Ah - you need something to mount configfs on /sys/kernel/config. In Raspbian it's either an init rule - /etc/init.d/mountkernfs.sh - or a systemd service - /lib/systemd/system/sys/kernel-config.mount. Try running this:

Code: Select all

sudo modprobe configfs
sudo mount -t configfs configfs /sys/kernel/config

User avatar
Nachteule
Posts: 22
Joined: Tue May 03, 2016 9:23 pm

Re: Upcoming Device Tree changes

Wed May 04, 2016 1:27 pm

PhilE wrote:Ah - you need something to mount configfs on /sys/kernel/config. In Raspbian it's either an init rule - /etc/init.d/mountkernfs.sh - or a systemd service - /lib/systemd/system/sys/kernel-config.mount. Try running this:

Code: Select all

sudo modprobe configfs
sudo mount -t configfs configfs /sys/kernel/config
Yeah, that was missing. Now it's working 8-)

Thanks a lot, PhilE

User avatar
skywatch
Posts: 49
Joined: Tue May 21, 2013 8:17 pm

Re: Upcoming Device Tree changes

Thu May 05, 2016 6:15 pm

PhilE wrote:@skywatch The next Raspbian release (being prepared now) will include changes to the DTBs, overlays, utilities and lxpanel to make it possible to dynamically load and remove audio devices. There are almost bound to be some problem cases, but we'll be a few steps closer to a system that is fully reconfigurable at run time.
Thank you for the update Phil, most encouraging news.

Nachteule is building the kernel that I would be interested in using (Xbian) and now it looks like a *very* useful feature culd be added to new release.

Cheers! :D

User avatar
Realizator
Posts: 68
Joined: Thu Jul 14, 2016 12:53 pm
Contact: Website Twitter

Re: Upcoming Device Tree changes

Thu Jul 14, 2016 1:12 pm

Hi all!
I work with custom PCB with Compute Module and have own DT overlay file (it enables SD card)
When I load it at boot, by adding line

Code: Select all

dtoverlay=sd1,overclock_50=5
to my config.txt it works without any issues.
When I exclude it from config.txt and try to load it as dynamic device tree after boot by

Code: Select all

sudo dtoverlay sd1 overclock_50=5
it loads succesfully, and "dtoverlay -l" shows me

Code: Select all

Overlays (in load order):
0:    sd1   overclock_50=5
But SD does not appears (no mmcblk1) as it was in boot with config.txt line.

Here's DTS file I'm using. (this DTS discussion is here on Github)

Code: Select all

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2708";

    fragment@0 {
        target = <&sdhost>;
        frag0: __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&sdhost_pins>;
            bus-width = <4>;
            brcm,overclock-50 = <0>;
            brcm,pio-limit = <1>;
            status = "okay";
        };
    };

    fragment@1 {
        target = <&gpio>;
        __overlay__ {
            sdhost_pins: sdhost_pins {
                brcm,pins = <22 23 24 25 26 27>;
                brcm,function = <4 4 4 4 4 4>;    /* alt0: SD0*/
                brcm,pull = <0 2 2 2 2 2>;    /* pull up all except clk */
            };
        };
    };

    __overrides__ {
        overclock_50     = <&frag0>,"brcm,overclock-50:0";
        force_pio        = <&frag0>,"brcm,force-pio?";
        pio_limit        = <&frag0>,"brcm,pio-limit:0";
        debug            = <&frag0>,"brcm,debug?";
        poll_once        = <&frag0>,"non-removable?";
        bus_width        = <&frag0>,"bus-width:0";
    };
};
What am I doing wrong?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3321
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Upcoming Device Tree changes

Thu Jul 14, 2016 4:05 pm

There is a hint in dmesg:

Code: Select all

[  102.540852] sdhost-bcm2835 3f202000.sdhost: prop pinctrl-0 index 0 invalid phandle
Overwriting an existing node using an overlay is dangerous because doing so may break any phandle references. Try this:

Code: Select all

# Reboot if you've already loaded sd1.
dtc -I fs -O dtb -o before.dtb /proc/device-tree
sudo dtoverlay sd1.dtbo
dtc -I fs -O dtb -o after.dtb /proc/device-tree
dtdiff before.dtb after.dtb
You will get output like this:

Code: Select all

--- /dev/fd/63  2016-07-14 16:50:47.667140533 +0100
+++ /dev/fd/62  2016-07-14 16:50:47.667140533 +0100
@@ -419,8 +419,9 @@
                        };

                        sdhost_pins {
-                               brcm,function = <0x4>;
-                               brcm,pins = <0x30 0x31 0x32 0x33 0x34 0x35>;
+                               brcm,function = <0x4 0x4 0x4 0x4 0x4 0x4>;
+                               brcm,pins = <0x16 0x17 0x18 0x19 0x1a 0x1b>;
+                               brcm,pull = <0x0 0x2 0x2 0x2 0x2 0x2>;
                                phandle = <0xa>;
                        };

@@ -650,10 +651,10 @@
                        dmas = <0x9 0xd>;
                        interrupts = <0x2 0x18>;
                        phandle = <0x2d>;
-                       pinctrl-0 = <0xa>;
+                       pinctrl-0 = <0x47>;
                        pinctrl-names = "default";
                        reg = <0x7e202000 0x100>;
-                       status = "disabled";
+                       status = "okay";
                };

                smi@7e600000 {
You can see that the pinctrl-0 property of sdhost has been changed, but the phandle of sdhost_pins hasn't, resulting in a broken reference. The details of the kernel overlay application is subtly different to that in the firmware (and the dtmerge utility which uses the same source code). If you are curious, try:

Code: Select all

dtmerge before.dtb before_fw.dtb -
dtmerge before_fw.dtb after_fw.dtb sd1.dtbo
dtdiff before_fw.dtb after_fw.dtb
You will see that the firmware changes the phandle in sdhost_pins as well which makes it work, but this is also bad because it would break any pre-existing links to the same pins (not likely in this case, but you get the point).

Instead you need to modify the overlay so that fragment 1 targets the existing sdhost_pins node, and just overwrite its contents.

On a side note I don't think you need to overwrite so many of sdhost's properties, but it should be harmless.

Return to “Device Tree”