Linux system porting: system programming

Linux system porting: system programming

Summary:

This chapter uses the MfgTool tool officially provided by NXP to program the system to the device through the USB OTG port

  • You can understand the general principle of downloading Mfgtool to the development board

  • Based on the understanding of the download principle, modify the download tool to suit our own development board for download

1. Mfgtool acquisition

Go to NXP official website and download the toolkit of IMX6ULL

20220409213344

Download address: Mfgtool download address , after downloading, decompress it as follows:

20220409214033

One with file system programming, one without

2. MfgTool download principle

2.1 Connect the development board and configure the download method

MfgTool burns the system into the EMMC through the USB OTG interface. Before writing, modify the system to USB to download:

20220410121613

After configuration, connect the development board through USB, and the connection is shown as follows:

20220409210841

2.2 Execute VBS file

Then enter L4.1.15_2.0.0-ga_mfg-tools\mfgtools-with-rootfs\mfgtoolsthe folder, there are a large number of .vbs files in the folder, .vbs is used to configure the download parameters, for example, there are the following .vbs files in the folder just downloaded, you can configure different download methods:

20220409214737

The content of the vbs script is as follows:

Set wshShell = CreateObject("WScript.shell")
wshShell.run "mfgtool2.exe -c ""linux"" -l ""eMMC"" -s ""board=sabresd"" -s ""mmc=1"" -s ""6uluboot=14x14evk"" -s ""6uldtb=14x14-evk"""
Set wshShell = Nothing

The mfgtool2.exe software is called, and the parameters are passed in to download. Then we take the execution mfgtool2-yocto-mx-evk-emmc.vbsdownload method as an example. After execution, open the program and the following mark appears, indicating that the connection to the development board is successful:

20220409215247

After clicking Start, the system will be programmed, and the four files of uboot, Linux kernel, .dtb and rootfs will be programmed!

MfgTool first downloads uboot, kernel and .dtb (device tree), which are three files, to the DDR of the development board through USB OTG. Note that it is not necessary to download rootfs. It is equivalent to starting the Linux system directly on the DDR of the development board, and then programming the complete system to the EMMC after the Linux system starts.

In the L4.1.15_2.0.0-ga_mfg-tools/mfgtools-with-rootfs/mfgtools/Profiles/Linux/OS Firmwaredirectory there are the following files:

20220409215912

The firmware folder has many uboot files ending with .imx, a zImage image file, and many device tree files ending with .dtb, and the files directory is basically the same as firmware, except that firmware is used to download to DDR, and file is used to download to EMMC

2.3 ucl2.xml configuration file

This file is mainly to determine which chip of the I.MX series is currently programming the system. ucl2.xml starts with <UCL> and ends with </UCL>. Between <CFG> and </CFG> is configuration related content

20220410091507

By reading the VID and PID of the chip, you can determine which processor system is currently being programmed. If VID=0X15A2, PID=0080, it means that the system needs to be programmed for I.MX6ULL

And configuration download related instructions, between <LIST> and </LIST> are programming commands for different memory chips

20220410094523

As mentioned above, the download is divided into two steps. The first step is to download to the DDR, start the system, and prepare for the subsequent download to the EMMC. The relevant download instructions are as follows:

<CMD state="BootStrap" type="boot" body="BootStrap" file ="firmware/u-boot-imx6ul%lite%%6uluboot%_emmc.imx" ifdev="MX6ULL">Loading U-boot</CMD>

<CMD state="BootStrap" type="load" file="firmware/zImage" address="0x80800000" loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" ifdev="MX6SL MX6SX MX7D MX6UL MX6ULL">Loading Kernel.</CMD>

<CMD state="BootStrap" type="load" file="firmware/zImage-imx6ul%lite%-%6uldtb%-emmc.dtb" address="0x83000000" loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" ifdev="MX6ULL">Loading device tree.</CMD>

BootStrap represents the first download stage , file represents the location of the file to be downloaded, find the cfg.ini file L4.1.15_2.0.0-ga_mfg-tools\mfgtools-with-rootfs\mfgtools-with-rootfs\mfgtoolsunder , which contains the relevant parameter values ​​in the file, such as lite=l, 6uluboot=14x14evk in the file, so the first The final value of the instruction file isu-boot-imx6ull14x14evk _emmc.imx

After the download is complete, start the system

<CMD state="BootStrap" type="jump" > Jumping to OS image. </CMD>

After booting, create a partition on the EMMC, and then flash uboot, zImage, .dtb (device tree) and root file system

3. Customize Mfgtool programming system

We obtained Mfgtool above, and also roughly understood the basic principle of his running and downloading. Let's modify Mfgtool below.

3.1 Download file preparation

  • uboot boot file : u-boot.imx (generated by uboot source code compilation)
  • zImage image file : system kernel running file (generated by compiling Linux source code)
  • dtb device tree file : the device tree required for the kernel to run (generated by compiling the Linux source code)
  • rootfs root file system : the file system required for the correct operation of the kernel (made and packaged by Busybox)

Here I use the uboot, file system, kernel image and device tree I made earlier

20220410103012

Put the L4.1.15_2.0.0-ga_mfg-tools\mfgtools-with-rootfs\mfgtools\Profiles\Linux\OS Firmware、my_filefile under the folder, my_file is our own newly created folder

3.2 Create a new VBS

Copy the mfgtool2-yocto-mx-evk-emmc.vbs file and change it to the mfgtool2-my-alpha-emmc.vbs file. The content of the file is as follows:

20220410102713

We don't need to modify it, just use this file directly. Although he passed in some parameters, he will not be used later, and directly change the xml configuration file.

3.3 Modify ucl2.xml

Hardware identification continues to use the original

  <CFG>
    <STATE name="BootStrap" dev="MX6SL" vid="15A2" pid="0063"/>
    <STATE name="BootStrap" dev="MX6D" vid="15A2" pid="0061"/>
    <STATE name="BootStrap" dev="MX6Q" vid="15A2" pid="0054"/>
    <STATE name="BootStrap" dev="MX6SX" vid="15A2" pid="0071"/>
    <STATE name="BootStrap" dev="MX6UL" vid="15A2" pid="007D"/>
    <STATE name="BootStrap" dev="MX7D" vid="15A2" pid="0076"/>
    <STATE name="BootStrap" dev="MX6ULL" vid="15A2" pid="0080"/>
    <STATE name="Updater"   dev="MSC" vid="066F" pid="37FF"/>
  </CFG>

The xml of the official tool is divided into several parts:

20220410104307

We only need to pay attention to the ones related to EMMC, and modify the ifdev="MX6ULL" command, which is related to IMX6ULL, because the download is divided into two stages, the first stage is used to start the system on DDR, the second stage download Our file system, we keep the first stage unchanged, use the one provided by NXP, just replace the second stage file path with our own

The first stage instructions:

<CMD state="BootStrap" type="boot" body="BootStrap" file ="firmware/u-boot-imx6ul%lite%%6uluboot%_emmc.imx" ifdev="MX6ULL">Loading U-boot</CMD>
<CMD state="BootStrap" type="load" file="firmware/zImage" address="0x80800000" loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" ifdev="MX6ULL">Loading Kernel.</CMD>
<CMD state="BootStrap" type="load" file="firmware/%initramfs%" address="0x83800000" loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" ifdev="MX6ULL">Loading Initramfs.</CMD>
<CMD state="BootStrap" type="load" file="firmware/zImage-imx6ul%lite%-%6uldtb%-emmc.dtb" address="0x83000000" loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" ifdev="MX6ULL">Loading device tree.</CMD>

<CMD state="BootStrap" type="jump" > Jumping to OS image. </CMD>

second stage directive

Create a download environment

<!-- create partition -->
<CMD state="Updater" type="push" body="send" file="mksdcard.sh.tar">Sending partition shell</CMD>
<CMD state="Updater" type="push" body="$ tar -xf $FILE "> Partitioning...</CMD>
<CMD state="Updater" type="push" body="$ sh mksdcard.sh /dev/mmcblk1"> Partitioning...</CMD>

Download uboot and change the path to our own:

<!-- burn uboot -->
<CMD state="Updater" type="push" body="$ dd if=/dev/zero of=/dev/mmcblk1 bs=1k seek=768 conv=fsync count=8">clear u-boot env</CMD>
<CMD state="Updater" type="push" body="$ echo 0 > /sys/block/mmcblk1boot0/force_ro">access boot partition 1</CMD>
<CMD state="Updater" type="push" body="send" file="my_file/u-boot.imx" ifdev="MX6ULL">Sending u-boot.bin</CMD>
<CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk1boot0 bs=512 seek=2">write U-Boot to sd card</CMD>
<CMD state="Updater" type="push" body="$ echo 1 > /sys/block/mmcblk1boot0/force_ro"> re-enable read-only access </CMD>
<CMD state="Updater" type="push" body="$ mmc bootpart enable 1 1 /dev/mmcblk1">enable boot partion 1 to boot</CMD>

Format and mount the kernel filesystem partition:

<!-- format and mount boot partition -->
<CMD state="Updater" type="push" body="$ while [ ! -e /dev/mmcblk1p1 ]; do sleep 1; echo \"waiting...\"; done ">Waiting for the partition ready</CMD>
<CMD state="Updater" type="push" body="$ mkfs.vfat -F 32 /dev/mmcblk1p1">Formatting rootfs partition</CMD>
<CMD state="Updater" type="push" body="$ mkdir -p /mnt/mmcblk1p1"/>
<CMD state="Updater" type="push" body="$ mount -t vfat /dev/mmcblk1p1 /mnt/mmcblk1p1"/>

Set the LOGO during the download process:

<!-- burn logo -->
<!--<CMD state="Updater" type="push" body="send" file="files/alientek.bmp">Sending Boot Logo</CMD>
<CMD state="Updater" type="push" body="$ cp $FILE /mnt/mmcblk1p1/alientek.bmp">write boot logo to sd card</CMD> >

Download the zImage image and replace it with our own path

<!-- burn zImage -->
<CMD state="Updater" type="push" body="send" file="my_file/zImage">Sending kernel zImage</CMD>
<CMD state="Updater" type="push" body="$ cp $FILE /mnt/mmcblk1p1/zImage">write kernel image to sd card</CMD>

Download the device tree and replace it with our own device tree path:

<!-- burn dtb -->
<CMD state="Updater" type="push" body="send" file="my_file/imx6ull-my-emmc.dtb" ifdev="MX6ULL">Sending Device Tree file</CMD>
<CMD state="Updater" type="push" body="$ cp $FILE /mnt/mmcblk1p1/imx6ull-my-emmc.dtb" ifdev="MX6ULL">write device tree to eMMC card</CMD>

<CMD state="Updater" type="push" body="$ sleep 1">delay</CMD>
<CMD state="Updater" type="push" body="$ sync">Sync...</CMD>
<CMD state="Updater" type="push" body="$ umount /mnt/mmcblk1p1">Unmounting vfat partition</CMD>

Format and mount the root filesystem partition

<!-- format and mount rootfs partition -->
<CMD state="Updater" type="push" body="$ mkfs.ext3 -F -E nodiscard /dev/mmcblk1p2">Formatting rootfs partition</CMD>
<CMD state="Updater" type="push" body="$ mkdir -p /mnt/mmcblk1p2"/>
<CMD state="Updater" type="push" body="$ mount -t ext3 /dev/mmcblk1p2 /mnt/mmcblk1p2"/>

Download the root filesystem and replace it with our root filesystem path

<!-- burn rootfs -->
<CMD state="Updater" type="push" body="pipe tar -jxv -C /mnt/mmcblk1p2" file="my_file/rootfs.tar.bz2" ifdev="MX6ULL">Sending and writting rootfs</CMD>
<CMD state="Updater" type="push" body="frf">Finishing rootfs write</CMD>
<CMD state="Updater" type="push" body="$ sleep 1">delay</CMD>
<CMD state="Updater" type="push" body="$ sync">Sync...</CMD>
<CMD state="Updater" type="push" body="$ umount /mnt/mmcblk1p2">Unmounting rootfs partition</CMD>
<CMD state="Updater" type="push" body="$ echo Update Complete!">Done</CMD>

Save after modification and execute our VBS script

The download is complete as follows:

20220410115405

Adjust the BOOT DIP switch, start the system, it prompts that the device tree is missing, because I use the atomic compiled uboot, his device tree name is different, I directly modify it on the boot command line, set the device tree, and start directly

setenv fdt_file imx6ull-my-emmc.dtb
boot

The system started successfully:

20220410121218

Guess you like

Origin blog.csdn.net/qq_45396672/article/details/124075922