3. U-boot environment variables: bootcmd and bootargs

u-bootcmd
bootcmd is some commands executed by default when uboot starts automatically, so you can define various configurations in the current environment, parameter settings for different environments, and then set bootcmd to the kind of parameters you often use.
 
Now the parameters of my bootcmd are set as: bootcmd=nfs 0x30008000 192.168.1.149:/opt/FriendlyARM/uImage;bootm
Indicates that uboot loads the uImage file under the directory 192.168.1.149:/opt/FriendlyARM/ in the manner of nfs, and executes bootm after loading.

The bootm command is specifically used to boot a kernel image in SDRAM that has been processed with U-boot's mkimage tool. Therefore, when executing the bootm command, you must ensure that the image file is already in memory.


u-bootargs
Bootargs is the most important environment variable, and it can even be said that the entire environment variable is set around bootargs. There are many types of bootargs. We usually only use a few. If you are interested, you can read this article: http://blog.chinaunix.net/u2/79570/showart_1675071.html. Bootargs is very flexible. Different combinations of kernel and file system will have different setting methods. Even you can not set bootargs, but write it directly to the kernel (this setting can be done in the options of configuring the kernel) , it is these reasons that lead to the difficulty of using bootargs.
The following introduces the common parameters of bootargs. There are many types of bootargs, and with the development of the kernel, some new parameters will appear, making the settings more flexible and diverse.
A. root 
is used to specify the location of rootfs. Common situations are: 
root=/dev/ram rw 
root=/dev/ram0 rw
Please note that the above two settings are common, I have done tests and even root=/ dev/ram1 rw and root=/dev/ram2 rw are also possible. Some people on the Internet say that it is not universal in some cases, that is, it must be set to ram or ram0, but it has not been encountered yet, and further confirmation is needed. You can try one by one when it doesn't work.

root=/dev/mtdx rw
root=/dev/mtdblockx rw
root=/dev/mtdblock/x rw
root=31:0x

The above are common under certain circumstances. Of course, it depends on whether your current system supports it. However, mtd is a character device, and mtdblock is a block device. Sometimes you try one by one. The current system supports the above. In this case, but root=/dev/mtdblockx rw is more general. In addition, if it is possible to specify the device name directly, it is also possible to use the device number of this device.
root=/dev/mtdblockx rw indicates the directory where your root file system is located, where the value of x needs to be determined according to your own flash partition.
Creating 5 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "supervivi"
0x000000040000-0x000000060000 : "param"
0x000000060000-0x000000560000 : "Kernel"
0x000000560000-0x000040560000 : "root"
mtd: partition "root" extends beyond the end of device "NAND 128MiB 3,3V 8-bit" -- size truncated to 0x7aa0000
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 128MiB 3,3V 8-bit" -- size truncated to 0x8000000
The fourth partition in the above flash partition is used to store the root file system, so the value of x in mtdblaockx should be 3. (numbered from 0)
root=/dev/nfs
in the file system is an nfs -based file system time to use. Of course, after specifying root=/dev/nfs, you also need to specify nfsroot=serverip:nfs_dir , which means that the file system exists under the directory of the host .
My bootargs parameter is set to:
bootargs=noinitrd root=/dev/nfs proto=tcp,nolock,nfsvers=3, rw nfsroot=192.168.1.149:/mini2440/rootfs ip=192.168.1.146:192.168.1.149::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
It is to load the linux file system in the way of the nfs file system

B. This option of rootfstype 
needs to be used together with root. Generally, if the root file system is ext2, it does not matter whether there is this option, but if it is a file system such as jffs2, squashfs, etc., you need rootfstype to indicate the type of the file system, otherwise It will fail to mount the root partition.

C. console 
console=tty uses a virtual serial port terminal device.
console=ttyS[,options] uses a specific serial port , options can be in the form of bbbbpnx, where bbbb refers to the baud rate of the serial port , p is the parity bit (never seen it used), and n refers to the bits.
console=ttySAC[,options] Same as above.

Why should console=ttySAC0,115200  be set to ttySAC0 in its parameters? I don't know why?
In the linux kernel the macro #define S3C24XX_SERIAL_NAME "ttySAC0" is defined in linux/drivers/serial/samsuing.c I myself tried to change it to other value
#define S3C24XX_SERIAL_NAME "ttySuiYuan0" , at the same time, the parameters of uboot are also changed to console=ttySuiYuan0 , compile the kernel, download, but in the end, the kernel will not start as follows.

done
Bytes transferred = 2268932 (229f04 hex)
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   linux_kernel_2012-02-06 14:54:15
   Created:      2012-02-06   6:54:15 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2268868 Bytes =  2.2 MB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux................................................................................................................................................... done, booting the kernel.

In the end, there is no way, and we should do: #define S3C24XX_SERIAL_NAME "ttySAC0" 

D. mem
mem=xxM Specify the size of the memory, not necessary


E. ramdisk_size
ramdisk=xxxxx Not recommended 
ramdisk_size=xxxxx
Recommended Both of the above can tell the ramdisk driver, The size of the created ramdisk is 4m by default (s390 defaults to 8M). You can check Documentation/ramdisk.txt to find the relevant description, but ramdisk=xxxxx has not been mentioned in the new version of the kernel, so it is not recommended.

F. initrd, noinitrd
When you do not use ramdisk to start the system, you need to use the noinitrd parameter, but if you use it, you need to specify initrd=r_addr, size, r_addr represents the location of initrd in memory, and size represents initrd the size of.

G. init
init specifies the first script to run in the system after the kernel is started , generally init=/linuxrc, or init=/etc/preinit, the content of preinit is generally to create console, null device nodes, and run init programs, mount some filesystems, etc. Please note that many beginners think that init=/linuxrc is a fixed way of writing, but it is not. /linuxrc refers to the linuxrc script under the / directory, which is generally just a connection.
This parameter is optional in the file system made by yourself, and the /linuxrc file in the root file system directory is not necessary. I have tried.
The code related to linuxrc can be found in uboot.

if (execute_command) {
run_init_process(execute_command);
printk(KERN_WARNING "Failed to execute %s. Attempting "
"defaults...\n", execute_command);
}
run_init_process("/sbin/init");
run_init_process("/etc /init");
run_init_process("/bin/init");
run_init_process("/bin/sh");

panic("No init found. Try passing init= option to kernel.");
Just look at this code , if linuxrc is not found, just
run_init_process("/sbin/init");
run_init_process("/etc/init");
run_init_process("/bin/init");
run_init_process("/bin/sh");
It is OK for any one of them to be executed, the linuxrc file is not necessary


H. mtdparts
mtdparts=fc000000.nor_flash:1920k(linux),128k(fdt),20M(ramdisk),4M(jffs2),38272k(user),256k(env),384k(uboot) For
this parameter to work, The mtd driver in the kernel must be supported, that is, you need to select Device Drivers ---> Memory Technology Device (MTD) support ---> Command line partition table parsing

when configuring the kernel. The format of mtdparts is as follows:
mtdparts=[;
:= : [,]
:= [@offset][][ro]
:= unique id used in mapping driver/device
:= standard linux memsize OR "-" to denote all remaining space
:= (NAME)
so you need to use Set it according to the following format:
mtdparts=mtd-id:@(),@()
There are a few things to pay attention to:
a. mtd-id must be the same as the mtd-id of the flash of your current platform, otherwise The entire mtdparts will be invalid
. b. The size can be the actual size (xxM, xxk, xx) when setting it, or it can be '-' which means all the remaining space.
Example:
Suppose the mtd-id of the flash is sa1100, then you can use the following way to set:
mtdparts=sa1100:- → only one partition
mtdparts=sa1100:256k(ARMboot)ro,-(root) → there are two partitions
to view drivers Find the description in the comments in /mtd/cmdlinepart.c.

I. ip
specifies the ip address of the network card after the system is started. If you use an nfs-based file system, you must have this parameter. In other cases, it depends on your own preferences. There are two ways to set ip:
ip = ip addr
ip=ip addr:server ip addr:gateway:netmask::which netcard:off
These two methods can be used, but obviously the second is much more detailed, please pay attention to the second Which netcard refers to the network card on the development board, not the network card on the host.

After talking about several common bootargs, let's discuss several combinations that I often use:
1). Assuming that the file system is a ramdisk and is directly in memory, the settings of bootargs should be as follows:
setenv bootargs 'initrd=0x32000000, 0xa00000 root=/dev/ram0 console=ttySAC0 mem=64M init=/linuxrc'

2). Assuming the file system is ramdisk, and in flash, the bootargs settings should be as follows:
setenv bootargs 'mem=32M console=ttyS0,115200 root=/dev/ram rw init=/linuxrc'
Note that in this case you should specify the address of the ramdisk in the flash in the bootm command, such as bootm kernel_addr ramdisk_addr (fdt_addr)

3). Assuming that the file system is of type jffs2, and in flash, the settings of bootargs should be as follows:
setenv bootargs 'mem=32M console=ttyS0,115200 noinitrd root=/dev/mtdblock2 rw rootfstype=jffs2 init=/linuxrc'

4) . Assuming the file system is based on nfs, bootargs should be set as follows:
setenv bootargs 'noinitrd mem=64M console=ttySAC0 root=/dev/nfs nfsroot=192.168.0.3:/nfs ip=192.168.0.5:192.168.0.3:192.168. 0.3:255.255.255.0::eth0:
off'or
setenv bootargs 'noinitrd mem=64M console=ttySAC0 root=/dev/nfs nfsroot=192.168.0.3:/nfs ip=192.168.0.5'The


above are the ones we often use The combination of bootargs, to be honest, bootargs is very flexible, so there are many ways to set it, and it should be set according to the specific situation of your platform.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325299394&siteId=291194637
Recommended