4, uboot support for the device tree

Section 01 _ dtb passed to the kernel: R2

A U-Boot kernel start command:.
The bootm <uImage_addr> // no device tree, the bootm 0x30007FC0
the bootm <uImage_addr> <initrd_addr> <dtb_addr> // device tree has

for example:
NAND read.jffs2 0x30007FC0 kernel; // read uImage kernel into memory 0x30007FC0
the NAND read.jffs2 32000000 device_tree; // read into memory dtb 32000000
bootm 0x30007FC0 - 0x32000000 // start, when the corresponding parameter no initrd is written "-"

b. bootm how the command register r2 dtb_addr written to the kernel?
the ARM program calls the rule (the ATPCS)

c_function (P0, P1, P2) // P0 => r0 of, P1 => R1, P2 => r2

defines the function pointer the_kernel , the starting address pointing to the kernel,
then execute: the_kernel (0, machine_id, 0x32000000 );

. c dtb_addr can pick it?
C.1 not to damage the u-boot itself
road c.2 Do not block the kernel: the kernel itself can not take up space, use the kernel memory area can not be occupied
when the kernel starts it will normally be lower location of the page table is placed, this space (i.e., typically 0x4000 16K bytes) can not be occupied

JZ2440 memory usage:
      --------------------- ---------
0x33f80000 -> | U-the Boot |
      ------------------------------
      | u- boot memory used (stack, etc.) |
      ------------------------------
      | |
      | |
      | free area |
      | |
      | |
      | |
      | |
      ------------------------------
0x30008000 -> | zImage |
      -------- ---------------------- uImage = 64-byte header + zImage
0x30007FC0 -> | uImage head |
        ------------------------------
0x30004000 -> | kernel page tables created | head. S
       ------------------------------
      | |
      | |
      -----> --------- ---------------------
      |
      |
      --- (memory base address 0x30000000)


Example commands:
. A can start:
NAND read.jffs2 30000000 device_tree
NAND read.jffs2 Kernel 0x30007FC0
the bootm 0x30007FC0 - 30000000

. b not start: 0x30004000 will be used when the kernel memory starts to store page table, dtb will be destroyed
the NAND read.jffs2 30.004 million device_tree
the NAND read.jffs2 0x30007FC0 Kernel
bootm 0x30007FC0 - 30.004 million


Modify principle of Section 02 _dtb

Example 1. attribute modification value,
    assuming the old value: len
    new value: newlen (assuming newlen> len)

. a space occupied by the original extended attribute val len bytes from byte newlen:
  all the contents of the old value after rearward movement (newlen - len) of bytes

b. Place new value into newlen byte space occupied by val

. C modify information structure block header length dtb: size_dt_struct

d dtb modify header information string block offset value:. off_dt_strings

e dtb modify the total length of the header information:. totalsize

 

Examples 2. Add a new property of
a, if not the name of the property in the string block in.
  To add a new string in the tail string block: the name of the property
  and modify header information dtb length of string block: size_dt_strings
  modify dtb the total length of the header information: totalsize

. b property where found node, tail node in a spatial extension, and the length of content:
  the TAG //. 4 bytes, corresponding 0x00000003
  len bytes. 4 //, val attribute indicates the length
  nameoff // 4 bytes, the attribute represents offset name
  val // len bytes used to store val

. C modify information structure block header length dtb: size_dt_struct

d dtb modify header information string block offset value:. off_dt_strings

e dtb modify the total length of the header information:. totalsize


U-boot can be downloaded from the official website to source a relatively new u-boot, view its cmd / fdt.c
  ftp://ftp.denx.de/pub/u-boot/

fdt command calls procedure:
  fdt SET <path> <prop> [<val>]

A node according to find path.
B determines the new value according to the length of newlen val, val and convert a stream of bytes.
C fdt_setprop.
  C.1 fdt_setprop_placeholder / / make room for the new value in the DTB
    fdt_get_property_w // length oldlen old value obtained
    fdt_splice_struct_ // make room
      fdt_splice_ // use memmove mobile DTB data, mobile (newlen-oldlen)
      fdt_set_size_dt_struct // DTB header modification, size_dt_struct
      fdt_set_off_dt_strings / / DTB header modification, off_dt_strings

C.2 the memcpy (prop_data, Val, len); // the new value is stored in the DTB


Section 03 _dtb modification command fdt transplant

We still use the u-boot 1.1.6, in this version we have achieved a lot of features: usb download, menu operation, the card is always enabled and so on, could not bear to discard.
Need to add fdc Command on the inside, this command can be used to view, modify dtb
from u-boot official website to download the latest source, the inside cmd / fdt.c transplant.

u-boot official website Source:
ftp://ftp.denx.de/pub/u-boot/

The final patch stored in the directory is as follows: doc_and_sources_for_device_tree \ source_and_images \ u-boot \ u-boot-1.1.6_device_tree_for_jz2440_add_fdt_20181022.patch
patch Usage:
Export the PATH = the PATH = / usr / local / sbin: / usr / local / bin: / usr /sbin:/usr/bin:/sbin:/bin:/usr/games:/work/system/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin
tar XJF the Boot-U-1.1.6 unzip .tar.bz2 //
cd u-boot-1.1.6
patch -p1 <../u-boot-1.1.6_device_tree_for_jz2440_add_fdt_20181022.patch // patched
make 100ask24x0_config // configuration
make // compiler, you can get u-boot .bin


a. transplantation fdt command
a.1 first move past the code, modify Makefile to compile
  u-boot-2018.11-rc2 \ lib \ libfdt mainly use this directory,
          it contains most of the files are included directly scripts \ dtc \ libfdt in the same file name
          only two files is their own version of
  u-boot-2018.11-rc2 \ scripts \ dtc \ libfdt


The new u-boot in cmd / fdt.c rename cmd_fdt.c, and lib / libfdt / * Copy together u-boot of the old common / fdt directory
modify old u-boot / Makefile, add a line: LIBS + = common / fdt / libfdt.a
modify old u-boot / common / fdt / Makefile, modeled drivers / nand / Makefile modified


a.2 according to modify the source code compilation error message

When transplanting FAQ:
i No SUCH File or Directory:.
  To note,
  #include "xxx.h" // Find xxx.h is in the current directory
  #include <xxx.h> // xxx is to look in the specified directory ? .h, which specify the directory it
    // can be used when compiling the file "-I" option specifies the header file directory,
    // for example: ARM-Linux-gcc the -I <dir> -c -o ....
    // for u-boot, the general is the source include directory

solution:
determine where the header file, directory, or move it to include the source of the current directory

. ii xxx undeclared:
  macro variables, function is not declared / defined

  for the macro to define it;
  for variables to define it, or declared as an external variable;
  for function, or to realize that the external function declarations;

. iii above two compile-time error occurs,
  when everything is okay, the last is the linker, which often occur: undefined reference to `xxx '
  This means that the code uses xxx function, but this function is not implemented

solution : to achieve it, or find it in the file, this file to the project

b. fdt command uses the example of
nand read.jffs2 32000000 device_tree // read dtb files from flash memory (0x32000000)
FDT addr 32000000 // tell fdt, dtb file in which
pin // print fdt print / led pin / led node properties
fdt get value XXX / led pin // read attribute pin / led node, and assigned to an environment variable XXX
Print XXX XXX // printing environment variable value
fdt set / led pin <0x00050005> // set / led node properties pin
fdt print / led pin // print / pin led attribute node
nand erase device_tree // erase the flash partition
nand write.jffs2 32000000 device_tree // dtb the modified file into flash partition

Guess you like

Origin www.cnblogs.com/liusiluandzhangkun/p/11875463.html