Passing Bootargs via Chosen node in Device Tree no

2020-03-03 19:28发布

问题:

As per my understanding chosen node is used to send boot arguments to the kernel. The following is the chosen node of the existing device code (am335x-bone-common.dtsi).

chosen {
  stdout-path = &uart0;
  };

So, I have modified chosen node to pass kernel arguments.

chosen {
        bootargs = "console=ttyO0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rw rootwait";
        stdout-path = &uart0;
    };

While bringing up the board I encountered KERNEL PANIC, Here is the log {https://pastebin.com/XHyrsmfG}

FYI: These are the u-boot commands issued on serial console(minicom) inorder to port kernel and devicetree using SDcard.

fatload mmc 0:1 0x81000000 zImage
fatload mmc 0:1 0x82000000 am335x-boneblack.dtb
bootz 0x81000000 - 0x82000000 

回答1:

As per my understanding chosen node is used to send boot arguments to the kernel.

Your understanding is incomplete.
As already mentioned in another answer, the kernel command line provided by the bootloader (i.e. U-Boot) is the actual list of parameters currently used when you boot the board.

For ARM Linux the default kernel configuration gives precedence to the bootloader's command line over the default kernel command string and the bootargs in the chosen node in the Device Tree.
The rationale according to U-Boot author/maintainer Wolfgang Denk seems to be that any hardcoded, built-in bootargs are inferior to bootargs that can be easily customized and supplied by a bootloader. This is exactly what you are seeing.

There are actually three possible ARM kernel boot configuration choices:

Kernel command line type:
  (X) Use bootloader kernel arguments if available  
  ( ) Extend bootloader kernel arguments
  ( ) Always use the default kernel command string

If you want to always ignore the command line in U-Boot's bootargs variable (and the command line from the DT), but exclusively use the default kernel command string as defined in CONFIG_CMDLINE, then the kernel should be configured for the third choice (CONFIG_CMDLINE_FORCE) on that list.
Note that this list of choices is only available when CONFIG_ATAGS is enabled ("Support for the traditional ATAGS boot data passing").

The scheme that selects the DT bootargs is to use the existing kernel configuration, but simply delete that U-Boot environment variable (i.e. setenv bootargs).
If you change U-Boot's bootargs variable to an empty string as mentioned in another answer, the kernel will use its default kernel command string (CONFIG_CMDLINE) rather than the DT.



回答2:

As per my understanding chosen node is used to send boot arguments to the kernel. The following is the chosen node of the existing device code (am335x-bone-common.dtsi).

chosen {
        bootargs = "console=ttyO0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rw rootwait";
        stdout-path = &uart0;
    };

Looking at your pastie, the boot log says the command line is the following:

Kernel command line: console=ttyO0,115200 ip=10.0.0.111:10.0.0.4::255.255. 255.0 rw root=/dev/nfs nfsroot=10.0.0.4:/home/dileep/beaglebone/rootfs,

And since you have also set the bootargs "bootargs = "console=ttyO0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rw rootwait";" in the devicetree wouldnt affect as uboot has already set those parameters, ie if same parameter is set in the device tree and in the tags (uboot), the one from the uboot tags will be chosen.

So you will have to clear up the bootargs set by u-boot.

1] setenv bootargs "";
2] saveenv
3] fatload mmc 0:1 0x81000000 zImage
4] fatload mmc 0:1 0x82000000 am335x-boneblack.dtb
5 bootz 0x81000000 - 0x82000000 

For fresh building uboot, where the board is not programmed yet make sure in the u-boot configs you don’t have bootargs variable defined.