Linux system programming practice

System programming practice

The mfgtool programming tool and its working principle are introduced in the article Preliminary Exploration of Linux System Programming. The following uses the I.MX6U-ALPHA EMMC development board as a platform to introduce how to program NXP official system and self-made system .

1. Burn NXP official system

Burn the NXP official system to the I.MX6U-ALPHA EMMC development board (512MB DDR3 + 8G EMMC), the specific steps are as follows:

  • Connect the USB, dial the code switch to the USB download mode
  • Pop out the TF card, and then press the development board reset button
  • Open the MobaXterm serial port assistant terminal
  • Double-click mfgtool2-yocto-mx-evk-emmc.vbs
  • Click the Start button to program NXP official system

The burning process is as follows
insert image description here

The burning process displayed on the MobaXterm serial port assistant terminal

insert image description here

After the programming is completed, click the Stop button to stop the programming, and click the Exit button to exit

insert image description here

Pull out the USB cable, turn the DIP switch to EMMC startup mode, and it will start from EMMC after restarting

insert image description here

At this time, the system after startup is made by NXP for the I.MX6ULL EVK development board. You need to enter the user name, the user name is "root", and there is no password

2. Burn the homemade system

Program the self-made system into the I.MX6U-ALPHA EMMC development board (512MB DDR3 + 8G EMMC). Prepare the four programming files of self-made uboot, kernel, .dtb and rootfs (compressed package), and rename them

##根文件系统 rootfs 打包
cd rootfs/ 
tar -vcjf rootfs.tar.bz2 *

insert image description here

⏩ Copy the renamed uboot, kernel, and .dtb files to the firmware directory and replace the original files
⏩ Copy all the four renamed files to the files directory
⏩ Double-click mfgtool2-yocto-mx-evk- emmc.vbs file, open the burning software, click the Start button to burn
insert image description here

After the programming is completed, start the system from EMMC, as shown in the figure below, it can be seen that the self-made system has been programmed successfully
insert image description here

3. Modify the programming tool

3.1 Transform Mfgtool

The above is to replace the NXP official system with a self-made system to complete the programming. The following will introduce how to modify the MfgTool tool to support its own development board. Transform MfgTool, mainly from the following three aspects

⏩ Determine the name of the system file: Determine the name of the system file to be compatible with different products
insert image description here
⏩ Create a new .vbs file: Copy the mfgtool2-yocto-mx-evk-emmc.vbs file, and re-order it as needed, such as naming it mfgtool2-andyxi-emmc. vbs

⏩ Modify the ucl2.xml file in the OS Firmware folder: change it to the following

<!-- 修改后的 ucl2.xml 文件 -->
<UCL>
  <CFG>
    <STATE name="BootStrap" dev="MX6UL" vid="15A2" pid="007D"/>
    <STATE name="BootStrap" dev="MX6ULL" vid="15A2" pid="0080"/>
    <STATE name="Updater" dev="MSC" vid="066F" pid="37FF"/>
  </CFG>
	
  <!-- 向 EMMC 烧写系统 -->
  <LIST name="eMMC" desc="Choose eMMC as media">
    <CMD state="BootStrap" type="boot" body="BootStrap" file
    ="firmware/u-boot-andyxi-emmc.imx" ifdev="MX6ULL">Loading Uboot</CMD>
    <CMD state="BootStrap" type="load" file="firmware/zImage-andyxi-emmc" address="0x80800000"
    loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" 
    ifdev="MX6SL MX6SX MX7D MX6UL MX6ULL">Loading Kernel.</CMD>
    <CMD state="BootStrap" type="load" file="firmware/%initramfs%" address="0x83800000"
    loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE"
    ifdev="MX6SL MX6SX MX7D MX6UL MX6ULL">Loading Initramfs.</CMD>
    <CMD state="BootStrap" type="load" file="firmware/imx6ull-andyxi-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>

    <!-- 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/mmcblk%mmc%"> Partitioning...</CMD>

    <!-- burn uboot -->
    <CMD state="Updater" type="push" body="$ dd if=/dev/zero
    of=/dev/mmcblk%mmc% bs=1k seek=768 conv=fsync count=8">clear u-boot arg</CMD>

    <!-- access boot partition -->
    <CMD state="Updater" type="push" body="$ echo 0 > /sys/block/mmcblk%mmc%boot0/force_ro">
    access boot partition 1</CMD>
    <CMD state="Updater" type="push" body="send" file="files/u-boot-andyxi-emmc.imx" ifdev="MX6ULL">
    Sending u-boot.bin</CMD>
    <CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk%mmc%boot0 bs=512 seek=2">
    write U-Boot to sd card</CMD>
    <CMD state="Updater" type="push" body="$ echo 1 > /sys/block/mmcblk%mmc%boot0/force_ro"> 
    re-enable read-only access</CMD>
    <CMD state="Updater" type="push" body="$ mmc bootpart enable 1 1 /dev/mmcblk%mmc%">
    enable boot partion 1 to boot</CMD>

    <!-- create fat partition -->
    <CMD state="Updater" type="push" body="$ while [ ! -e
    /dev/mmcblk%mmc%p1 ]; do sleep 1; echo \"waiting...\"; done ">Waiting for the partition ready</CMD>
    <CMD state="Updater" type="push" body="$ mkfs.vfat /dev/mmcblk%mmc%p1">
    Formatting rootfs partition</CMD>
    <CMD state="Updater" type="push" body="$ mkdir -p /mnt/mmcblk%mmc%p1"/>
    <CMD state="Updater" type="push" body="$ mount -t vfat /dev/mmcblk%mmc%p1 /mnt/mmcblk%mmc%p1"/>

    <!-- burn zImage -->
    <CMD state="Updater" type="push" body="send" file="files/zImage-andyxi-emmc">
    Sending kernel zImage</CMD>
    <CMD state="Updater" type="push" body="$ cp $FILE /mnt/mmcblk%mmc%p1/zImage">
    write kernel image to sd card</CMD>

    <!-- burn dtb -->
    <CMD state="Updater" type="push" body="send" file="files/imx6ull-andyxi-emmc.dtb" ifdev="MX6ULL">
    Sending Device Tree file</CMD>
    <CMD state="Updater" type="push" body="$ cp $FILE /mnt/mmcblk%mmc%p1/imx6ull-andyxi-emmc.dtb" ifdev="MX6ULL">
    write device tree to sd card</CMD>
    <CMD state="Updater" type="push" body="$ umount /mnt/mmcblk%mmc%p1">
    Unmounting vfat partition</CMD>

    <!-- burn rootfs -->
    <CMD state="Updater" type="push" body="$ mkfs.ext3 -F -E nodiscard /dev/mmcblk%mmc%p2">
    Formatting rootfs partition</CMD>
    <CMD state="Updater" type="push" body="$ mkdir -p /mnt/mmcblk%mmc%p2"/>
    <CMD state="Updater" type="push" body="$ mount -t ext3 /dev/mmcblk%mmc%p2 /mnt/mmcblk%mmc%p2"/>
    <CMD state="Updater" type="push" body="pipe tar -jxv -C /mnt/mmcblk%mmc%p2" 
    file="files/rootfs-andyxi-emmc.tar.bz2" ifdev="MX6UL MX7D MX6ULL">Sending and writting rootfs</CMD>
    <CMD state="Updater" type="push" body="frf">Finishing rootfs write</CMD>
    <CMD state="Updater" type="push" body="$ umount /mnt/mmcblk%mmc%p2">Unmounting rootfs partition</CMD>
    <CMD state="Updater" type="push" body="$ echo Update Complete!">Done</CMD>
  </LIST>
</UCL>

3.2 Burn test

After the MfgTool tool is modified, the programming test can be performed. Copy the self-made uboot, linux kernel, and .dtb files to the firmware directory, and replace the original files; copy all four files to the files directory.

Double-click the mfgtool2-andyxi-emmc.vbs file to open the programming software, and click the "Start" button to program. After programming is completed, set the DIP switch to EMMC startup, restart the development board, and the system startup information is as shown below:
insert image description here

The development board ends up stuck at "Starting kernel ..." and the kernel fails to start. The following describes how to solve the problem of kernel startup failure

3.3 Solve the kernel startup failure

Carefully observe the log information output by uboot, and you will find two lines of information as shown in the figure below:
insert image description here

It can be seen that an error occurred when reading the device tree file. Restart uboot, enter the command line mode, enter the following command to check whether there is a device tree file in partition 1 of EMMC

mmc dev 1 	//切换到EMMC
ls mmc 1:1 	//输出EMMC1分区1中的所有文件

insert image description here

It can be seen that there is a device tree file in partition 1 of EMMC at this time, but the name is different, so reading imx6ull-14x14-evk.dtb will definitely make an error. The reason for this error is that the default device tree name in uboot is imx6ull-14x14-evk.dtb. There are two solutions:

⏩ Reset the value of the bootcmd environment variable: In the command line mode of uboot, reset the values ​​of the two environment variables bootcmd and bootargs

setenv bootcmd 'mmc dev 1;fatload mmc 1:1 80800000 zImage;fatload mmc 1:1 83000000
			    imx6ull-andyxi-emmc.dtb;bootz 80800000 - 83000000'
setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw'
saveenv\

⏩ Modify the uboot source code: The above method needs to be set again every time it is reprogrammed. The following method only needs to be set once. In the uboot source code include/configs/mx6ull_andyxi_emmc.h file, find the following content in the macro CONFIG_EXTRA_ENV_SETTINGS:

"findfdt="\
  "if test $fdt_file = undefined; then " \
    "if test $board_name = EVK && test $board_rev = 9X9; then " \
	"setenv fdt_file imx6ull-9x9-evk.dtb; fi; " \
    "if test $board_name = EVK && test $board_rev = 14X14; then " \
	"setenv fdt_file imx6ull-14x14-evk.dtb; fi; " \
    "if test $fdt_file = undefined; then " \
	"echo WARNING: Could not determine dtb to use; fi; " \
  "fi;\0" \

findfdt is an environment variable used to determine the name of the device tree file, and the fdt_file environment variable holds the name of the device tree file. The two device trees in the above code are used by NXP official development boards. So change the findfdt value to the following:

"findfdt="\
  "if test $fdt_file = undefined; then " \
    "setenv fdt_file imx6ull-andyxi-emmc.dtb; " \
  "fi;\0" \

Recompile uboot after modification, then burn the new uboot to the development board and restart the test, the kernel starts normally. At this point, the programming of the self-made system is completed, and the test is successful, and the development board can be started normally without the network

Follow the official account, send "mfgtool" to get mfgtool related information

Guess you like

Origin blog.csdn.net/Chuangke_Andy/article/details/126831995