raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.22k stars 5.03k forks source link

Need help with Device Tree #381

Closed notro closed 10 years ago

notro commented 11 years ago

I'm trying to get Device Tree working, but has failed in my attempts so far. I have seen that it's reported working with U-boot, but I'm distributing my kernel with rpi-update, so I would like this to work without U-boot. Is it even possible? I tried adding all config.txt parameters from https://github.com/raspberrypi/linux/wiki/How-to-boot-using-device-tree, but then it wouldn't boot. So I only use the device_tree* parameters.

I'm using the next firmware with the rpi-3.10.y branch from raspberrypi/linux and use the device tree test data.

Added to kernel config

Boot options  --->
  [*] Flattened Device Tree support

Device Drivers  --->  Device Tree and Open Firmware support  --->
  [*] Support for device tree in /proc
  [*] Device Tree Runtime self tests

bcm2708.dts

/dts-v1/;
/include/ "testcases/tests.dtsi"

Compile device tree

./linux/scripts/dtc/dtc linux/arch/arm/boot/dts/bcm2708.dts -O dtb -o bcm2708.dtb

Added to /boot/config.txt

device_tree=bcm2708.dtb
device_tree_address=0x100

Kernel boot messages

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.12+ (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #1 Fri Sep 20 22:51:32 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2708
[    0.000000] cma: CMA: reserved 16 MiB at 1b000000
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 113792
[    0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 448MB = 448MB total
[    0.000000] Memory: 430684k/430684k available, 28068k reserved, 0K highmem
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
[    0.000000]     vmalloc : 0xdc800000 - 0xff000000   ( 552 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xdc000000   ( 448 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0614cf4   (6196 kB)
[    0.000000]       .init : 0xc0615000 - 0xc0659aa0   ( 275 kB)
[    0.000000]       .data : 0xc065a000 - 0xc069d968   ( 271 kB)
[    0.000000]        .bss : 0xc069d968 - 0xc076e968   ( 836 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

[    2.558239] ### dt-test ### No testcase data in device tree; not running tests

Nothing in proc

pi@raspberrypi:~$ ls -l /proc/device-tree/
total 0

Why? I want to use Device Tree to configure some framebuffer drivers I'm working on, not the base drivers.

Framebuffer drivers: https://github.com/notro/fbtft rpi-update distributed kernel: https://github.com/notro/rpi-firmware

popcornmix commented 11 years ago

Read: https://github.com/raspberrypi/linux/issues/24 first. As far as I know, the firmware populating the device tree was largely working, but there is probably a bug remaining. If you can dump the device tree recieved by the kernel and spot any discrepancies then I expect I can fix the firmware.

notro commented 11 years ago

I have tested three scenarios:

Firmware boot without disable_commandline_tags The kernel boots, but the Device Tree test case is not found. The kernel command line does not reflect the one in bcm2708.dtb Nothing in /proc/device-tree

Firmware boot with disable_commandline_tags=1 Nothing happens

U-boot Device Tree tests is passed /proc/device-tree is populated

Am I doing something wrong in the Firmware boot case?

I also tried setting config.txt: device_tree= to a nonextisting file, but no error message.

Additional kernel config changes

Kernel hacking  ---> 
    [*] Kernel low-level debugging functions (read help!)
        Kernel low-level debugging port (Broadcom BCM2708 UART0 (PL011))  --->
            (X) Broadcom BCM2708 UART0 (PL011)
    [*] Early printk

Kernel source changes

I got this error (using U-boot) before changing arch/arm/mach-bcm2708/bcm2708.c:

Starting kernel ...

Uncompressing Linux... done, booting the kernel.

Error: unrecognized/unsupported device tree compatible list:
[ 'brcm,bcm2708' ]

Available machine support:

ID (hex)        NAME
00000c42        BCM2708

Please check your kernel config and/or bootloader.

arch/arm/mach-bcm2708/bcm2708.c

diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
index 5662c1a..40d7ef1 100644
--- a/arch/arm/mach-bcm2708/bcm2708.c
+++ b/arch/arm/mach-bcm2708/bcm2708.c
@@ -900,6 +903,11 @@ static void __init board_reserve(void)
 #endif
 }

+static const char * const bcm2708_compat[] = {
+       "brcm,bcm2708",
+       NULL
+};
+
 MACHINE_START(BCM2708, "BCM2708")
     /* Maintainer: Broadcom Europe Ltd. */
        .map_io = bcm2708_map_io,
@@ -909,6 +917,7 @@ MACHINE_START(BCM2708, "BCM2708")
        .init_early = bcm2708_init_early,
        .reserve = board_reserve,
        .restart        = bcm2708_restart,
+       .dt_compat = bcm2708_compat,
 MACHINE_END

 module_param(boardrev, uint, 0644);

arch/arm/boot/dts/bcm2708.dts

/dts-v1/;
/include/ "bcm2835.dtsi"

/ {
    compatible = "brcm,bcm2708";
    model = "BCM2708";

    memory {
        reg = <0 0x10000000>;
    };

    chosen {
        bootargs = "earlyprintk loglevel=8 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait";
    };

    soc {
    };
};

/include/ "testcases/tests.dtsi"

Fimware boot without disable_commandline_tags

/boot/config.txt

device_tree=bcm2708.dtb
#disable_commandline_tags=1

Kernel messages

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.12+ (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #3 Mon Sep 23 19:44:32 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2708
[    0.000000] cma: CMA: reserved 16 MiB at 1b000000
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 113792
[    0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

[    2.567583] ### dt-test ### No testcase data in device tree; not running tests

øø
Debian GNU/Linux 7 raspberrypi ttyAMA0

raspberrypi login:

/proc/device-tree

pi@raspberrypi:~$ ls -l /proc/device-tree/
total 0

Fimware boot with disable_commandline_tags=1

/boot/config.txt

device_tree=bcm2708.dtb
disable_commandline_tags=1

Kernel messages

nothing happens

U-boot

Built from git.denx.de/u-boot-arm.git


U-Boot 2013.10-rc2-15890-gad31ff6 (Sep 22 2013 - 15:12:08)

DRAM:  448 MiB
WARNING: Caches not enabled
MMC:   bcm2835_sdhci: 0
Using default environment

In:    serial
Out:   lcd
Err:   lcd
Hit any key to stop autoboot:  0
mmc0 is current device
reading boot.scr.uimg
** Unable to read file boot.scr.uimg **

U-Boot> fatload ${devtype} ${devnum}:1 ${kernel_addr_r} /uImage.img
reading /uImage.img
3301280 bytes read in 524 ms (6 MiB/s)

U-Boot> fatload ${devtype} ${devnum}:1 ${fdt_addr_r} /bcm2708.dtb
reading /bcm2708.dtb
3411 bytes read in 14 ms (237.3 KiB/s)

U-Boot> bootm ${kernel_addr_r} - ${fdt_addr_r}
## Booting kernel from Legacy Image at 01000000 ...
   Image Name:   Linux-3.10.12+
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3301216 Bytes = 3.1 MiB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 02000000
   Booting using the fdt blob at 0x2000000
   Loading Kernel Image ... OK
   Loading Device Tree to 1bb8a000, end 1bb8dd52 ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.12+ (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #3 Mon Sep 23 19:44:32 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2708, model: BCM2708
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] cma: CMA: reserved 16 MiB at 1a800000
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] On node 0 totalpages: 114688
[    0.000000] free_area_init_node: node 0, pgdat c069af8c, node_mem_map c0771000
[    0.000000]   Normal zone: 896 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 114688 pages, LIFO batch:31
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 113792
[    0.000000] Kernel command line: earlyprintk loglevel=8 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 448MB = 448MB total
[    0.000000] Memory: 430668k/430668k available, 28084k reserved, 0K highmem
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
[    0.000000]     vmalloc : 0xdc800000 - 0xff000000   ( 552 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xdc000000   ( 448 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0616d5c   (6204 kB)
[    0.000000]       .init : 0xc0617000 - 0xc065bbac   ( 275 kB)
[    0.000000]       .data : 0xc065c000 - 0xc069f988   ( 271 kB)
[    0.000000]        .bss : 0xc069f988 - 0xc0770988   ( 836 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:330
[    0.000000] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 4294967ms
[    0.000000] Switching to timer-based delay loop
[    0.000000] Console: colour dummy device 80x30
[    0.000000] console [tty1] enabled, bootconsole disabled
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.12+ (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #3 Mon Sep 23 19:44:32 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2708, model: BCM2708
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] cma: CMA: reserved 16 MiB at 1a800000
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] On node 0 totalpages: 114688
[    0.000000] free_area_init_node: node 0, pgdat c069af8c, node_mem_map c0771000
[    0.000000]   Normal zone: 896 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 114688 pages, LIFO batch:31
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 113792
[    0.000000] Kernel command line: earlyprintk loglevel=8 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

[    2.654689] ### dt-test ### start of selftest - you will see error messages
[    2.663315] ### dt-test ### pass drivers/of/selftest.c:40
[    2.670273] ### dt-test ### pass drivers/of/selftest.c:93
[    2.677175] ### dt-test ### pass drivers/of/selftest.c:93
[    2.684015] ### dt-test ### pass drivers/of/selftest.c:93
[    2.690753] ### dt-test ### pass drivers/of/selftest.c:93
[    2.697457] ### dt-test ### pass drivers/of/selftest.c:93
[    2.704124] ### dt-test ### pass drivers/of/selftest.c:93
[    2.710688] ### dt-test ### pass drivers/of/selftest.c:93
[    2.717214] ### dt-test ### pass drivers/of/selftest.c:93
[    2.723694] ### dt-test ### pass drivers/of/selftest.c:99
[    2.730083] ### dt-test ### pass drivers/of/selftest.c:102
[    2.736548] /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1
[    2.750460] ### dt-test ### pass drivers/of/selftest.c:107
[    2.757026] /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1
[    2.771091] ### dt-test ### pass drivers/of/selftest.c:110
[    2.777603] /testcase-data/phandle-tests/consumer-a: could not find phandle
[    2.785657] ### dt-test ### pass drivers/of/selftest.c:115
[    2.792230] /testcase-data/phandle-tests/consumer-a: could not find phandle
[    2.800264] ### dt-test ### pass drivers/of/selftest.c:118
[    2.806856] /testcase-data/phandle-tests/consumer-a: arguments longer than property
[    2.816840] ### dt-test ### pass drivers/of/selftest.c:123
[    2.823648] /testcase-data/phandle-tests/consumer-a: arguments longer than property
[    2.834053] ### dt-test ### pass drivers/of/selftest.c:126
[    2.841082] ### dt-test ### start
[    2.845917] ### dt-test ### pass drivers/of/selftest.c:142
[    2.852990] ### dt-test ### pass drivers/of/selftest.c:144
[    2.860031] ### dt-test ### pass drivers/of/selftest.c:146
[    2.867089] ### dt-test ### pass drivers/of/selftest.c:148
[    2.874098] ### dt-test ### pass drivers/of/selftest.c:150
[    2.881063] ### dt-test ### pass drivers/of/selftest.c:152
[    2.887933] ### dt-test ### pass drivers/of/selftest.c:154
[    2.894747] ### dt-test ### end of selftest - PASS

[   10.255991] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   10.634122] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
øø
Debian GNU/Linux 7 raspberrypi ttyAMA0

raspberrypi login:

/proc/device-tree

pi@raspberrypi:~$ ls -l /proc/device-tree/
total 0
-r--r--r--  1 root root  4 Sep 23 19:19 #address-cells
dr-xr-xr-x  2 root root  0 Sep 23 19:19 aliases
dr-xr-xr-x  2 root root  0 Sep 23 19:19 chosen
dr-xr-xr-x  5 root root  0 Sep 23 19:19 clocks
-r--r--r--  1 root root 13 Sep 23 19:19 compatible
dr-xr-xr-x  2 root root  0 Sep 23 19:19 framebuffer
-r--r--r--  1 root root  4 Sep 23 19:19 interrupt-parent
dr-xr-xr-x  2 root root  0 Sep 23 19:19 memory
-r--r--r--  1 root root  8 Sep 23 19:19 model
-r--r--r--  1 root root  1 Sep 23 19:19 name
-r--r--r--  1 root root  4 Sep 23 19:19 #size-cells
dr-xr-xr-x 12 root root  0 Sep 23 19:19 soc
dr-xr-xr-x  3 root root  0 Sep 23 19:19 testcase-data
popcornmix commented 11 years ago

You want these settings:

device_tree=bcm2835.dtb
device_tree_address=0x100
kernel_address=0x8000
disable_commandline_tags=1

Do you have a uart attached? With these settings and a stock kernel, I can see uart output. It's not very happy due to the mising atags/command line but it shows the kernel is booting with disable_commandline_tags enabled.

http://pastebin.com/Bi28A5jw

P33M commented 11 years ago

I'm going to interject a bit here:

If you have a multi-platform enabled kernel, it will always panic because the machine ID passed in r1 is the 2708 machine ID. Multi-platform relies on the correct device tree being passed in r2 by the bootloader, thus the kernel expects the machine ID to be 0xFFFFFFFF if a specific arch hasn't been compiled in.

For reference: http://lwn.net/Articles/496400/

(I think the 2835 mainline port has actually been converted to multi-platform, therefore won't boot unless you use U-boot)

popcornmix commented 11 years ago

So would a config.txt option (e.g. linux_machine_id=0xffffffff) be useful (it will find it's way into r2 on kernel boot).

notro commented 11 years ago

I haven't been able to replicate what you did. Which kernel is the 'stock kernel' ?

I have tested raspberrypi/linux:3.10.y and torvalds/linux.

Image: 2013-09-10-wheezy-raspbian

config.txt

device_tree=bcm2835-rpi-b.dtb
device_tree_address=0x100
kernel_address=0x8000
disable_commandline_tags=1

Added to arch/arm/boot/dts/bcm2835-rpi-b.dts

    chosen {
        bootargs = "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait";
    };

Build

make mrproper
make bcm2835_defconfig
make -j4

Copy: arch/arm/boot/Image -> /boot/kernel.img arch/arm/boot/dts/bcm2835-rpi-b.dtb -> /boot/bcm2835-rpi-b.dtb

raspberrypi/linux 3.10.y

[    0.000000] Linux version 3.10.12+ (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #1 Tue Sep 24 09:27:00 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2835, model: Raspberry Pi Model B

[    0.706014] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
ø[    0.715692] Waiting for root device /dev/mmcblk0p2...
[    0.756968] mmc0: new SDHC card at address e624
[    0.762077] mmcblk0: mmc0:e624 SU16G 14.8 GiB
[    0.769401]  mmcblk0: p1 p2
[   10.837267] mmc0: Timeout waiting for hardware interrupt - cmd18.
[   10.843613] mmcblk0: error -110 sending stop command, original cmd response 0x900, card status 0x900
[   10.852787] mmcblk0: error -110 transferring data, sector 122882, nr 2, cmd response 0x900, card status 0x0
[   10.862551] mmcblk0: retrying using single block read
[   20.877265] mmc0: Timeout waiting for hardware interrupt - cmd18.
[   30.897265] mmc0: Timeout waiting for hardware interrupt - cmd12.
[   40.917279] mmc0: Timeout waiting for hardware interrupt - cmd13.
[   40.923507] mmcblk0: error -110 sending status command, retrying
[   50.957278] mmc0: Timeout waiting for hardware interrupt - cmd13.
[   50.963500] mmcblk0: error -110 sending status command, retrying

https://gist.github.com/notro/6687398

torvalds/linux

[    0.000000] Linux version 3.12.0-rc1 (pi@raspi1) (gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) ) #2 Tue Sep 24 00:46:31 CEST 2013
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2835, model: Raspberry Pi Model B

[info] Skipping font and keymap setup (handled by console-setup).
[ ok ] Setting up console font and keymap...done.
[ ok ] Setting up X socket directories... /tmp/.X11-unix /tmp/.ICE-unix.
INIT: PANIC: segmentation violation! sleeping for 30 seconds.
INIT: PANIC: segmentation violation! sleeping for 30 seconds.

https://gist.github.com/notro/6687345

P33M commented 11 years ago

@popcornmix

It would be useful in the long term for "generic" multiarch kernels to boot on the Pi. Basically a kernel compiled for an ARM1176 / ARMv6 processor (and had necessary device drivers built-in) would run on anything that provided it with a device tree with enough compatible devices. r1 needs to be 0xfffffff in these cases, indicating that the bootloader has passed through a devicetree describing the machine, rather than r1 being one of the set-in-stone machine IDs.

In the short term, it would allow for building multiarch kernels with a pi-specific DTB appended to the kernel zImage. This is useful for getting the dtb correct in the first place before pushing it across to videocore which (in theory) can then magically determine if we are running on a model A / B / rev1 / rev2 and pass the necessary stuff across (ram size in particular).

r2 still ends up as a pointer to ATAGS, but the kernel basically ignores ATAGS if a device tree tag is present.

popcornmix commented 11 years ago

My kernel is from "sudo BRANCH=next rpi-update". It is a non-device tree kernel. I've never attempted to run with bcm2835_defconfig.

I was just suggesting that the there is enough life in the kernel boot with the device tree config.txt options to get some debug infomation out (e.g. with printk through uart).

If you can perhaps dump the raw binary device tree data when booting from uboot and when booting direct, we might see where the problem is.

notro commented 11 years ago

With a Device Tree enabled kernel and _disable_commandlinetags=1 (and the other lines), I get nothing on the console after reset. Removing that line, it boots fine using atags. Booting with U-boot and Device Tree works fine.

Since not even Booting Linux on physical CPU 0 is displayed, the problem seems to be before _startkernel() is called, since a non Device Tree kernel boots with _disable_commandlinetags=1. I don't know assembly, so I'm lost here.

config.txt

device_tree=bcm2835-rpi-b.dtb
device_tree_address=0x100
kernel_address=0x8000
disable_commandline_tags=1

Relevant source code snippets

arch/arm/kernel/head-common.S

/*
 * The following fragment of code is executed with the MMU on in MMU mode,
 * and uses absolute addresses; this is not position independent.
 *
 *  r0  = cp#15 control register
 *  r1  = machine ID
 *  r2  = atags/dtb pointer
 *  r9  = processor ID
 */
[...]

    b       start_kernel
[...]
    .long   __atags_pointer                 @ r6
[...]

source/init/main.c

asmlinkage void __init start_kernel(void)
{
    char * command_line;
    extern const struct kernel_param __start___param[], __stop___param[];

    /*
     * Need to run as early as possible, to initialize the
     * lockdep hash:
     */
    lockdep_init();
    smp_setup_processor_id();
[...]
    setup_arch(&command_line);
[...]
}

arch/arm/kernel/setup.c

void __init smp_setup_processor_id(void)
{
[...]
    printk(KERN_INFO "Booting Linux on physical CPU 0x%x\n", mpidr);
}

arch/arm/kernel/setup.c

void __init setup_arch(char **cmdline_p)
{

    struct machine_desc *mdesc;

    setup_processor();
    mdesc = setup_machine_fdt(__atags_pointer);
    if (!mdesc)
        mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
[...]
}

arch/arm/kernel/devtree.c

/**
 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
 * @dt_phys: physical address of dt blob
 *
 * If a dtb was passed to the kernel in r2, then use it to choose the
 * correct machine_desc and to setup the system.
 */
struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
{
    struct boot_param_header *devtree;
[...]
    if (!dt_phys)
        return NULL;

    devtree = phys_to_virt(dt_phys);

    /* check device tree validity */
    if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
        return NULL;
[...]
    pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
[...]
}

arch/arm/kernel/atags_parse.c

struct machine_desc * __init setup_machine_tags(phys_addr_t __atags_pointer,
                                                unsigned int machine_nr)
{
[...]
    for_each_machine_desc(p)
        if (machine_nr == p->nr) {
            printk("Machine: %s\n", p->name);
            mdesc = p;
            break;
        }
[...]
}

Sidenote: It is possible to see in the kernel messages whether the kernel detects a Device Tree or not. When a Device Tree is detected, it also prints out model.

setup_machine_fdt()

pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);

setup_machine_tags()

printk("Machine: %s\n", p->name);
P33M commented 11 years ago

If you have early_printk, then the first set of console messages will be printed to the serial console ONLY. Are you connected to the gpio uart?

notro commented 11 years ago

Yes, I have a serial console and _CONFIG_EARLYPRINTK=y.

notro commented 11 years ago

I used zImage instead of Image and that gave me

Uncompressing Linux... done, booting the kernel.
notro commented 11 years ago

I was wrong in my assumption that _startkernel() wasn't called. Using early_print's I can see more.

I can see that the firmware alters the memory node from 256 to 512MB: This is what the .dtb file has:

    memory {
        reg = <0 0x10000000>;
    };

This is what the kernel receives and does:

data: 0 20 2000000 1000000,
early_init_dt_add_memory_arch(base=0x0, size=0x20000000)

Anything in particular I should look into ?

Uncompressing Linux... done, booting the kernel.
start_kernel()
setup_machine_fdt(dt_phys=0x100)
    Machine: BCM2708, model: Raspberry Pi Model B
early_init_dt_scan_chosen()
    search "chosen", depth: 0, uname:
early_init_dt_scan_chosen()
    search "chosen", depth: 1, uname: chosen
    Command line is: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
    early_init_dt_scan_chosen returned 1
early_init_dt_scan_root()
    dt_root_size_cells = 1
    dt_root_addr_cells = 1
    early_init_dt_scan_root returned 1
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
    memory scan node memory, reg size 8, data: 0 20 2000000 1000000,
early_init_dt_add_memory_arch(base=0x0, size=0x20000000)
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
early_init_dt_scan_memory()
    early_init_dt_scan_memory returned 0
Kernel command line: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
rest_init()
cpu_startup_entry()
cpu_idle_loop()
notro commented 11 years ago

I have found a way to make zImage boot. U-boot sets the memory size to 0x1C000000 and the firmware sets it to 0x20000000. Forcing size=0x1C000000 in drivers/of/fdt.c, makes zImage boot also.

Here is a kernel output diff without forcing the size: https://gist.github.com/notro/6712488

notro commented 11 years ago

By the way, this is zImage memory without DT

[    0.000000] Memory: 448MB = 448MB total
[    0.000000] Memory: 430716k/430716k available, 28036k reserved, 0K highmem

compared to U-boot with DT

[    0.000000] Memory: 448MB = 448MB total
[    0.000000] Memory: 430708k/430708k available, 28044k reserved, 0K highmem
popcornmix commented 11 years ago

Is the difference in 0x20000000 and 0x1c000000 due to the gpu_mem? Is your gpu_mem set to 64M?

Currenly I have: (with 512M part and 64M gpu_mem) totalmemsize = 512M memsize = 448M

"/memory/reg" to totalmemsize (e.g. 512M) and "//memreserve" to totalmemsize-memsize (e.g. 64M)

Would you prefer I set this to: "/memory/reg" to memsize (e.g. 448M) and "//memreserve" to totalmemsize-memsize (e.g. 64M). Or should this be 0?

notro commented 11 years ago

Is the difference in 0x20000000 and 0x1c000000 due to the gpu_mem? Is your gpu_mem set to 64M?

The only parameters I have in config.txt, is the DT related ones. So since the default gpu_mem is 64, I assume it is 64M.

This is how U-boot determines ramsize: http://git.denx.de/cgi-bin/gitweb.cgi?p=u-boot.git;a=blob;f=board/raspberrypi/rpi_b/rpi_b.c;hb=HEAD#l38

With regards to memreserve, it doesn't look like it is used (scripts/dtc/ is excluded):

pi@raspi1:~/3.10/linux$ grep -r memreserve .
./Documentation/arm64/booting.txt:  of memory (communicated to the kernel by a /memreserve/ region in the
./arch/arm/boot/dts/ecx-2000.dts:/memreserve/ 0x00000000 0x0001000;
./arch/arm/boot/dts/omap5.dtsi:/memreserve/ 0x9d000000 0x03000000;
./arch/arm/boot/dts/highbank.dts:/memreserve/ 0x00000000 0x0001000;
./arch/arm/boot/dts/omap4.dtsi:/memreserve/ 0x9d000000 0x03000000;
./arch/arm64/boot/dts/rtsm_ve-aemv8a.dts:/memreserve/ 0x80000000 0x00010000;
./arch/powerpc/boot/dts/currituck.dts:/memreserve/ 0x01f00000 0x00100000;       // spin table
./arch/powerpc/boot/dts/iss4xx-mpic.dts:/memreserve/ 0x01f00000 0x00100000;
./arch/powerpc/boot/dts/wii.dts: * contiguous RAM range and will BUG() if the memreserve is outside
./arch/powerpc/boot/dts/wii.dts:/*/memreserve/ 0x10000000 0x0004000;*/  /* DSP RAM */
./arch/powerpc/boot/dts/mpc836x_mds.dts:/memreserve/    00000000 1000000;
./arch/mips/mti-sead3/sead3.dts:/memreserve/ 0x00000000 0x00001000;     // reserved
./arch/mips/mti-sead3/sead3.dts:/memreserve/ 0x00001000 0x000ef000;     // ROM data
./arch/mips/mti-sead3/sead3.dts:/memreserve/ 0x000f0000 0x004cc000;     // reserved

This is the kernel function that reads the memory node: http://lxr.free-electrons.com/source/drivers/of/fdt.c?v=3.10;a=arm#L613

U-boot seem to honour it: http://lists.linaro.org/pipermail/linaro-kernel/2011-March/000161.html

Does the firmware set memreserve today? I can't find it in /proc/device-tree/

Would you prefer I set this to: "/memory/reg" to memsize (e.g. 448M)

Yes

and "//memreserve" to totalmemsize-memsize (e.g. 64M). Or should this be 0?

Skip this one?

popcornmix commented 11 years ago

24 requested:

/memreserve/ (u32 offset, u32 size of VideoCore memory - this is not a normal attribute) /memory/reg with the u32 memory range (e.g. 0x0 0x10000000 for 256MB)

so I am doing as requested by @lp0

I'll agree to change to your requested way at the weekend if no one shouts out that that is incorrect.

notro commented 11 years ago

I have another request. Can you make a config.txt parameter: device_tree_bootargs_add=1 or something. This will add the usual stuff to the chosen/bootargs property, like it does with cmdline.txt in ATAGS mode.

Some of these settings is needed to boot the 3.10.y kernel (I haven't tried to find out which). And this would make a FDT work correct on all boards with regards to bcm2708.boardrev for instance, and macaddr can't be hardcoded either. I don't know if any of the other parameters differ between boards.

usual stuff

dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x4939788f smsc95xx.macaddr=B8:27:EB:39:78:8F sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  
popcornmix commented 11 years ago

The mac address does come through device tree (as does serial/revision) /axi/usb/hub/ethernet/mac-address Does the 2835 kernel still use command line arguments for any of these? I'd be interested to know which.

But, yes, in theory I can send the "extended" command line through (just would be nice to know what is actually needed).

nomis commented 11 years ago

/memory/reg is always the total memory /memreserve/ is the memory to reserve

Just because omitting the reserved memory from /memory/reg works too does not mean it is correct.

notro commented 11 years ago

The mac address does come through device tree (as does serial/revision) /axi/usb/hub/ethernet/mac-address

I couldn't find any of those in /proc/device-tree https://gist.github.com/notro/6718376

Does the 2835 kernel still use command line arguments for any of these? I'd be interested to know which.

I extract the kernel config from the image in the rpi-firmware next branch and add DT support to that. So I don't know if that qualifies it as a BCM2708 or BCM2835 kernel. The next kernel uses arch/arm/mach-bcm2708/bcm2708.c which I have added .dt_compat support to. So that may qualify it as a BCM2708? Earlier in the thread I tried _bcm2835defconfig, but that was just for testing.

popcornmix commented 11 years ago

bcm2835_defconfig will actually use device tree for the hardware, and will purely use upstream kernel code. bcmrpi_defconfig will not use device tree for any pi specific hardware, and will use our own patches.

notro commented 11 years ago

Power.org™ Standard for Embedded Power Architecture™ Platform Requirements (ePAPR) https://www.power.org/wp-content/uploads/2012/06/Power_ePAPR_APPROVED_v1.1.pdf

3.4 Memory node A memory device node is required for all device trees and describesthe physical memory layout for the system. If a system has multiple ranges of memory, multiple memory nodes can be created, or the ranges can be specified in the reg property of a single memory node. [...] The client program may access memory not covered by any memory reservations(see section 8.3) using any storage attributes it chooses.

8.3 Memory Reservation Block 8.3.1 Purpose The memory reservation block provides the client program with a list of areas in physical memory which are reserved; that is, which shall not be used for general memory allocations. It is used to protect vital data structures from being overwritten by the client program.

/memory/reg is always the total memory

ePAPR states that multiple memory nodes/ranges can be used to describe the physical memory layout. driver/of/fdt.c seem to support that. I haven't found anything that states that all memory HAS to be accounted for.

/memreserve/ is the memory to reserve

Yes, but I haven't found anything in the 3.10.y tree that uses memreserve. And if that is the case, all memory can't be put in the memory node. Please prove me wrong.

Just because omitting the reserved memory from /memory/reg works too does not mean it is correct.

I agree with that, but I haven't found anything that proves it wrong.

notro commented 11 years ago

bcm2835_defconfig will actually use device tree for the hardware, and will purely use upstream kernel code. bcmrpi_defconfig will not use device tree for any pi specific hardware, and will use our own patches.

I want to deviate as little as possible from rpi-firmware. This way I benefit from the tesing of a lot of users. The upstream kernel code doesn't have that yet I believe. And I don't think the users of my kernel want to be part of that testing.

So while in rpi patched kernel land, I would like all extra ATAGS arguments to be added.

When 3.10.y becomes the standard, will the next branch start using Device Tree for the drivers that is already upstream?

popcornmix commented 11 years ago

We will move the main firmware branch to 3.10 in a few weeks. Moving to dev tree and 2835 machine is desirable but not planned by me. It is a significant amount of work, and will cause breakage. A number of drivers (like vchiq and dwc_otg) are not supported by 2835 and will need patching in.

nomis commented 11 years ago

The code that handles memserve on arm is arm_dt_memblock_reserve() in arch/arm/kernel/devtree.c called from arm_memblock_init() in arch/arm/mm/init.c

I know this works, because when you don't reserve it, the framebuffer memory overlaps with some kernel memory early in the boot process and bad things happen.

nomis commented 11 years ago

I don't see a real benefit to combining the original command line based parameters and device tree support. If you have device tree support enabled then it won't boot without it. All the configuration data should be there in device tree so you can trivially modify the existing drivers to use it.

notro commented 11 years ago

The code that handles memserve on arm is arm_dt_memblock_reserve() in arch/arm/kernel/devtree.c called from arm_memblock_init() in arch/arm/mm/init.c

Thanks, I stand corrected.

I added this to bcm2835-rpi-b.dts

/memreserve/ 0x9d000000 0x03000000;

And got this output

memblock_reserve: [0x0000009d000000-0x000000a0000000] arm_dt_memblock_reserve+0x94/0xa4
notro commented 11 years ago

I don't see a real benefit to combining the original command line based parameters and device tree support.

The point is, I don't want to spend a lot of time making all the drivers work with Device Tree. For the moment I only care about some framebuffer drivers and ads7846 (touch controller). It will be a transitional thing, before having full DT support. Having that expanded command line, makes the non-DT drivers work. Well, at least they load.

Except that this doesn't look right

[    2.190023] vc-cma: Videocore CMA driver
[    2.195405] vc-cma: vc_cma_base      = 0x00000000
[    2.201428] vc-cma: vc_cma_size      = 0x00000000 (0 MiB)
[    2.208119] vc-cma: vc_cma_initial   = 0x00000000 (0 MiB)

If you have device tree support enabled then it won't boot without it.

Not sure what you mean here. If you mean DT support is compiled in, but no DT is provided: With MACH_BCM2708 it will boot, but with ARCH_BCM2835 it won't. I use MACH_2708 as the rpi-firmware does.

All the configuration data should be there in device tree so you can trivially modify the existing drivers to use it.

For me it wouldn't be trivial, since I first looked into Device Tree a week ago, and all the kernel development I have done is writing some framebuffer drivers :-)

It looks like I would have to patch 6 files/drivers to achieve that:

dma.dmachans=0x7f35

bcm2708_fb.fbwidth=656
bcm2708_fb.fbheight=416

bcm2708.boardrev=0xe
bcm2708.serial=0x4939788f

smsc95xx.macaddr=B8:27:EB:39:78:8F

sdhci-bcm2708.emmc_clock_freq=100000000

vc_mem.mem_base=0x1ec00000
vc_mem.mem_size=0x20000000

OK, it's not as bad as I thought. I'll give it a go. Is this list from #24 valid in the current firmware?

I've updated to these field names:

"/memory/reg";
"/chosen/bootargs";
"/system/linux,revision";
"/system/linux,serial";
"/axi/usb/hub/ethernet/mac-address";
"/axi/dma/broadcom,channels";
"/display/broadcom,width";
"/display/broadcom,height";
"/display/broadcom,depth";
"/axi/sdhci/clock-frequency";
"/axi/uart0/clock-frequency";
popcornmix commented 11 years ago

Yes, that list matches current firmware (plus /memreserve).

notro commented 11 years ago

I need help to find those dynamic properties.

This gives me the static tree, but none from the #24 list, except for memory and chosen (which are present in the static tree):

print_device_tree_node(of_find_node_by_path("/"), 0);

Code: http://stackoverflow.com/a/9641039/2103047

And these returns NULL

np = of_find_node_by_path("/system");
np = of_find_node_with_property(NULL, "linux,serial");
np = of_find_node_by_path("/axi");
np = of_find_node_by_path("/axi@0");

I see that FreeBSD uses them: http://lists.freebsd.org/pipermail/svn-src-head/2013-January/043848.html

notro commented 11 years ago

I had completly forgotten about your work on this @lp0. Looking at: https://github.com/lp0/linux/blob/rpi-linear/arch/arm/mach-bcm2708/bcm2708.c I can see how you have done it. It looks like I don't receive those nodes.

I have also used U-boot to print the DT passed from the firmware, but no /system: https://gist.github.com/notro/6732379

notro commented 11 years ago

I found the problem. I had to add placeholders for the info in the Device Tree file.

popcornmix commented 11 years ago

Ah yes - the firmware just edits DT entries, it won't create new ones.

notro commented 11 years ago

Now all firmware provided entries work, except for memreserve. Edit: By "work" I mean I can see the firmware provided values.

If I do this the firmware fills in the values, but Linux doesn't reserve it, and the boot stops:

/ {
    compatible = "brcm,bcm2708";
    model = "v22 Raspberry Pi Model B";

        memreserve = <0x00000000 0x00000000>;
};

If I do this, Linux reserves the memory and booting completes. But I have to fill in the values my self. The firmware doesn't touch it:

/dts-v1/;

/memreserve/ 0x1c000000 0x04000000;

/include/ "skeleton.dtsi"

/ {
    compatible = "brcm,bcm2708";
    model = "v22 Raspberry Pi Model B";
};

Have a look at 8 Flat Device Tree Physical Structure in ePAPR. The memory reservation block is separate from the structure block.

DT file and result: https://gist.github.com/notro/6736821

notro commented 11 years ago

These are missing from the firmware provided DT entries:

vc_mem.mem_base=0x1ec00000
vc_mem.mem_size=0x20000000

https://github.com/raspberrypi/linux/blob/rpi-3.10.y/arch/arm/mach-bcm2708/vc_mem.c#L57

I have implemented the other entries.

popcornmix commented 11 years ago

Any suggestion for where they should go?

notro commented 11 years ago

Something like this?

    axi {
        compatible = "simple-bus";
        #address-cells = <1>;
        #size-cells = <1>;

        vc_mem {
            reg = <0x1ec00000 0x20000000>;
        };
};

_memsize looks wrong though. It is total memory, and not the size of vc_mem which is max. 0x20000000 - 0x1ec00000 = 0x1400000.

notro commented 11 years ago

Progress report: Device Tree and BCM2708

I can now add a device for spi-bcm2708 using Device Tree. Both 'clocks' and 'interrupts' properties are working. For 'interrupts' I use irq_domain_add_legacy(). For 'clocks' I tried CONFIG_COMMON_CLOCK and clk-bcm2835, but that didn't get me past Uncompressing Linux... done, booting the kernel. So instead I scan the tree for devices that uses clocks, find the clock node and add it with clkdev_add().

Diff: https://gist.github.com/notro/6903349

Let me know if there is any problems with this approach.

Now I'm going to look at pinctrl.

Sidenote: I had a look at BCM2835 to see if I could add BCM2708 drivers to that, but I didn't get past USB (which was the first I tried). There is ongoing work to get all the drivers upstream, but not in a state where I could easily use them. Here is a list of links I have collected:

popcornmix commented 11 years ago

I spotted this which seems to be 2835/devtree for vchiq and some other bits: https://github.com/hackerspace/rpi-linux/commits/lr-usb

notro commented 11 years ago

I now have pinctrl working. Two issues have come up:

sdhci-bcm2708
The firmware sets the clock frequency in this property: /axi/sdhci/clock-frequency Does this value change, or can I put the value in the Device Tree?

                clk_mmc: mmc {
                        compatible = "fixed-clock";
                        reg = <0>;
                        #clock-cells = <0>;
                        clock-frequency = <100000000>;
                };

vc_mem
Theses values are not available in the Device Tree:

vc_mem.mem_base=0x1ec00000
vc_mem.mem_size=0x20000000

Currently I have them like this in DT, but it will probably be wrong on a 256MB board?

    axi {
        compatible = "simple-bus";
        #address-cells = <1>;
        #size-cells = <1>;

        vc_mem {
            reg = <0x1ec00000 0x20000000>;
        };
};

To work around this, I tried to get the value from the mailbox, but that gave me a different value

#define VC_TAG_GET_VC_MEM 0x00010006

/* tag part of the message */
struct vc_msg_tag {
    uint32_t tag_id;        /* the tag ID */
    uint32_t buffer_size;       /* size of the buffer (should be 8) */
    uint32_t request_code;      /* identifies message as a request (should be 0) */
    uint32_t base;          /* base address in bytes */
    uint32_t size;          /* size in bytes */
};

/* message structure to be sent to videocore */
struct vc_msg {
    uint32_t msg_size;      /* simply, sizeof(struct vc_msg) */
    uint32_t request_code;      /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
    struct vc_msg_tag tag;      /* the tag structure above to make */
    uint32_t end_tag;       /* an end identifier, should be set to NULL */
};
    /* get values from Mailbox property */
    msg.msg_size = sizeof(msg);
    msg.tag.buffer_size = 8;
    msg.tag.tag_id = VC_TAG_GET_VC_MEM;
    result = bcm_mailbox_property(&msg, sizeof(msg));
    pr_info(DRIVER_NAME": from mailbox: base=0x%x, size=0x%x (%d, 0x%x)\n", msg.tag.base, msg.tag.size, result, msg.request_code);

Output

 vc-mem: from mailbox: base=0x1c000000, size=0x4000000 (0, 0x80000000)

Which is correct?

popcornmix commented 11 years ago

sdhci-bcm2708.emmc_clock_freq=100000000 will always be that value unless overridden. config.txt option init_emmc_clock will change the physical pll, the cmdline parameter and /axi/sdhci/clock-frequency.

Memory is split into 3 contiguous chunks: ARM, CMA, VC. CMA is 0 sized by default.

vc_mem.mem_base is start of VC vc_mem.mem_size is total memory (ARM+CMA+VC), e.g. 512M

VC_TAG_GET_VC_MEM returns start of CMA and size of CMA+VC VC_TAG_GET_ARM_MEM returns start of ARM and size of ARM

notro commented 11 years ago

sdhci-bcm2708.emmc_clock_freq=100000000 will always be that value unless overridden. config.txt option init_emmc_clock will change the physical pll, the cmdline parameter and /axi/sdhci/clock-frequency.

I'll stick with /axi/sdhci/clock-frequency then.

Memory is split into 3 contiguous chunks: ARM, CMA, VC. CMA is 0 sized by default.

vc_mem.mem_base is start of VC vc_mem.mem_size is total memory (ARM+CMA+VC), e.g. 512M

VC_TAG_GET_VC_MEM returns start of CMA and size of CMA+VC VC_TAG_GET_ARM_MEM returns start of ARM and size of ARM

Ok, can you add _/axi/vcmem/reg to the firmware?

popcornmix commented 11 years ago

Would you prefer that to match vc_mem.mem_base/vc_mem.mem_size or VC_TAG_GET_VC_MEM?

notro commented 11 years ago

Would you prefer that to match vc_mem.mem_base/vc_mem.mem_size or VC_TAG_GET_VC_MEM?

vc_mem.mem_base/vc_mem.mem_size

Device Tree

    axi {
        vc_mem {
            reg = <0x1ec00000 0x20000000>;
        };
    };

vc_mem.c

static void __init
vc_mem_of_parse(void)
{
    u32 reg[2];
    struct device_node *np = of_find_node_by_path("/axi/vc_mem");

    if (np && !of_property_read_u32_array(np, "reg", reg, 2)) {
        pr_debug("/axi/vc_mem/reg = <0x%04X 0x%04X>\n", reg[0], reg[1]);
        mem_base = reg[0];
        mem_size = reg[1];
    }
}
notro commented 11 years ago

As far as I can tell, these devices are not used by any drivers. Is that correct?

arch/arm/mach-bcm2708/bcm2708.c

static struct platform_device bcm2708_systemtimer_device = {
    .name = "bcm2708_systemtimer",
    .id = -1,       /* only one VideoCore I/O area */
    .resource = bcm2708_systemtimer_resources,
    .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
    .dev = {
        .dma_mask = &systemtimer_dmamask,
        .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
        },
};

struct platform_device bcm2708_powerman_device = {
    .name = "bcm2708_powerman",
    .id = 0,
    .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
    .resource = bcm2708_powerman_resources,
    .dev = {
        .dma_mask = &powerman_dmamask,
        .coherent_dma_mask = 0xffffffffUL},
};
popcornmix commented 11 years ago

My understanding is that the register range indicated in their resources is used within bcm2708.c, and if you remove those entries, you will get a panic on access.

notro commented 11 years ago

I'm having problems with /chosen/bootargs, it seems that the firmware is changing it under some circumstances.

This is the value in the Device Tree Blob

$ fdtget /boot/bcm2708-rpi-b.dtb /chosen bootargs
dtb debug dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

The boot messages says something else

Command line is: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

If I add some text to /boot/cmdline.txt, it varies whether it uses /boot/cmdline.txt or DTB:

Here it uses cmdline.txt with the added: addtext

Command line is: dwc_otg.lpm_enable=0 addtext console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Here it uses cmdline.txt with the added: cmdline (in an earlier test it used the DTB in this case, if I remember correctly)

Command line is: dwc_otg.lpm_enable=0 cmdline console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Here it uses DTB when I have added 'cmdline.txt' to the beginning of /boot/cmdline.txt

Command line is: dtb debug dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

What does the firmware say?

popcornmix commented 11 years ago

From the code, If the file cmdline.txt exists, then global_cmdline is set to its contents. Otherwise it is set to the default: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

/chosen/bootargs gets populated with global_cmdline. I believe the existing /chosen/bootargs is always overwritten. Are you seeing different behaviour? How do you want it to behave? (considering there may or may not be a /chosen/bootargs and there may or may not be a cmdline.txt)