STM32MP157A Linux kernel and root file system

(1) Linux kernel transplantation steps

The Linux kernel source code is very large and continues to grow with the development of versions. It uses a directory tree structure and uses Makefile to organize and configure the compilation

3.1》Import source code

1) Open the system source code and enter the Linux source code directory. The files ending with patch in this directory are the patch files officially provided by ST; linux-5.4.31.tar.xz is the standard Linux source code package.
/home/linux/fs_mp157a/kernel/stm32mp1-openstlinux-5.4-dunfell-mp1-20-06-24/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.4.31-r0
Insert image description here
2) Unzip the linux kernel source code , and enter the decompressed source code directory
tar -xvf linux-5.4.31.tar.xz
cd linux-5.4.31/
(********Note: All subsequent operations will be in this directory , don’t go to the wrong place.)

3.2》Add STMicroelectronics official patch

1) After decompressing the Linux kernel source code, you will get the standard kernel source code of the Linux community. Next, you need to add the source code patch officially provided by ST to the standard kernel.
for p in ls -1 ../*.patch; do patch -p1 < $p; done

3.3》Generate standard board configuration file

1) Generate multi_v7_defconfig default configuration
make ARCH=arm multi_v7_defconfig "fragment*.config"
2) Add the fragment config officially provided by ST to the default multi_v7_defconfig configuration
//Execute the following two instructions
for f in ls -1 ../fragment*.config; do scripts/kconfig/merge_config.sh -m -r .config $f; done
yes '' | make ARCH=arm oldconfig
3) Generate your own default configuration file
cp .config arch/arm/configs/stm32_fsmp1a_defconfig
4) Cancel SHA1 in git
echo "" > .scmversion /* The function of the echo command is to write content to the standard output. SHA1—Hash algorithm function*/

//The basic configuration of the standard version has been configured. If you need to compile additional functions or drivers before compilation, you can use make meunconfig to configure the kernel.

3.4》Generate device tree file

1) Using the reference board DK1 device tree files stm32mp15xx-dkx.dtsi and stm32mp157a-dk1.dts as a reference, add stm32mp15xx-fsmp1x.dtsi and stm32mp157a-fsmp1a.dts: Create a new stm32mp15xx-
in the arch/arm/boot/dts/ directory. fsmp1x.dtsi:
vim arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi
add the following content:
#include “stm32mp157-m4-srm.dtsi”
#include “stm32mp157-m4-srm-pinctrl.dtsi”
#include <dt -bindings/mfd/st,stpmic1.h>

/ {
memory@c0000000 {
device_type = “memory”;
reg = <0xc0000000 0x20000000>;
};

reserved-memory {
 #address-cells = <1>;
 #size-cells = <1>;
 ranges;

 mcuram2: mcuram2@10000000 {
 compatible = "shared-dma-pool";
 reg = <0x10000000 0x40000>;
 no-map;
 };

 vdev0vring0: vdev0vring0@10040000 {
 compatible = "shared-dma-pool";
 reg = <0x10040000 0x1000>;
 no-map;
 };

 vdev0vring1: vdev0vring1@10041000 {
 compatible = "shared-dma-pool";
 reg = <0x10041000 0x1000>;
 no-map;
 };

 vdev0buffer: vdev0buffer@10042000 {
 compatible = "shared-dma-pool";
 reg = <0x10042000 0x4000>;
 no-map;
 };
 mcuram: mcuram@30000000 {
 compatible = "shared-dma-pool";
 reg = <0x30000000 0x40000>;
 no-map;
 };

 retram: retram@38000000 {
 compatible = "shared-dma-pool";
 reg = <0x38000000 0x10000>;
 no-map;
 };

};
vin: vin {
compatible = “regulator-fixed”;
regulator-name = “vin”;
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
regulator-always-on;
};
v3v3: regulator-3p3v {
compatible = “regulator-fixed”;
regulator-name = “v3v3”;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
vdd: regulator-vdd {
compatible = “regulator-fixed”;
regulator-name = “vdd”;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
};
/ HDMI CEC controller /
&cec { pinctrl-names = “default”,"sleep"; pinctrl-0 = <&cec_pins_b>; pinctrl-1 = <&cec_pins_sleep_b>; status = "okay"; }; / cyclic redundancy check calculation unit / &crc1 { status = "okay"; }; &dma1 { sram = <&dma_pool>; }; &dma2 { sram = <&dma_pool>; }; / digital clock temperature sensor / &dts { status = “okay”; }; / image processing unit / &gpu { contiguous-area = <&gpu_reserved>; status = "okay";























};
/ hash processor /
&hash1 { status = “okay”; }; / inter-processor communication controller / &ipcc { status = “okay”; }; / watchdog / &iwdg2 { timeout-sec = <32> ; status = “okay”; }; / random number generator / &rng1 { status = “okay”; }; / real-time clock / &rtc { status = “okay”; }; / sdmmc1 TF card / &sdmmc1 { pinctrl-names = "default", "opendrain", "sleep"; pinctrl-0 = <&sdmmc1_b4_pins_a>;























pinctrl-1 = <&sdmmc1_b4_od_pins_a>;
pinctrl-2 = <&sdmmc1_b4_sleep_pins_a>;
cd-gpios = <&gpioh 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
disable-wp;
st,neg-edge;
bus-width = <4>;
vmmc-supply = <&v3v3>;
status = “okay”;
};

&sram {
dma_pool: dma_pool@0 {
reg = <0x50000 0x10000>;
pool;
};
};

/ Command Line Terminal /
&uart4 { pinctrl-names = “default”, “sleep”, “idle”; pinctrl-0 = <&uart4_pins_a>; pinctrl-1 = <&uart4_sleep_pins_a>; pinctrl-2 = <&uart4_idle_pins_a>; pinctrl-3 = <&uart4_pins_a>; /delete-property/dmas; /delete-property/dma-names; status = “okay”; }; / power reference buffer / &vrefbuf { regulator-min-microvolt = <2500000>; regulator-max -microvolt = <2500000>; vdda-supply = <&vdd>; status = “okay”; }; 2) Create a new stm32mp157a-fsmp1a.dts in the arch/arm/boot/dts/ directory: vim arch/arm/boot/ dts/stm32mp157a-fsmp1a.dts adds the following content: /dts-v1/;




















#include “stm32mp157.dtsi”
#include “stm32mp15xa.dtsi”
#include “stm32mp15-pinctrl.dtsi”
#include “stm32mp15xxaa-pinctrl.dtsi”
#include “stm32mp15xx-fsmp1x.dtsi”
/ {
model = “HQYJ STM32MP157 FSMP1A Discovery Board”;
compatible = “st,stm32mp157a-dk1”, “st,stm32mp157”;
aliases {
serial0 = &uart4;
};
chosen {
stdout-path = “serial0:115200n8”;
};
reserved-memory {
gpu_reserved: gpu@da000000 {
reg = <0xda000000 0x4000000>;
no-map;
};
optee_memory: optee@0xde000000 {
reg = <0xde000000 0x02000000>;
no-map;
};
};
};
&optee { status = “okay”; }; 3) Since a new file has been added, the Makefile needs to be modified to compile. Modify arch/arm/boot/dts/Makefile and add the compilation options of stm32mp157a-fsmp1a.dts (the red font part is the added content) ) vim arch/arm/boot/dts/Makefile 4) Add red content stm32mp157a-dk1.dtb \ stm32mp157a-fsmp1a.dtb \ stm32mp157d-dk1.dtb \ in Makefile







3.5》Compile kernel and device tree

1) Import the cross-compiler
source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi

2) Compile the kernel and device tree
make -j4 uImage dtbs LOADADDR=0xC2000040
Insert image description here

The kernel file is in the arch/arm/boot/ directory and
the device tree file is in the arch/arm/boot/ dts directory.
Insert image description here

3) Compile the kernel module ----- This step can be omitted for the time being. It has been too long and the module will not be used for the time being. When needed, compile
make ARCH=arm modules.
This operation will configure the source code of the module in the kernel. Compile and finally get the ko file.
Insert image description here

4) Copy the compiled device tree file and kernel uImage file to the /tftpboot folder of the ubuntu host, which
will be used when downloading the kernel and device tree files using tftp.
cp arch/arm/boot/uImage /tftpboot/
cp arch/arm/boot/dts/stm32mp157a-fsmp1a.dtb /tftpboot/

3.6》Download the kernel through TFTP

In Linux system transplantation, we use tftp download method to verify the results. Why use TFTP to download the kernel? Because the Linux system is very large, it may take 5 hours to build the system directly. During the development stage, we usually use TFTP download, because the kernel configuration often needs to be changed, and it is impossible to change it and build the system once. So use TFTP to download the kernel.
Using tftp to download requires building pxelinux-related directories.
1) The content of the /tftpboot/pxelinux.cfg/01-00-80-e1-42-60-17 file in the ubuntu host needs to be temporarily replaced with the following content. It will be modified according to different needs during the subsequent transplantation process. .
sudo mkdir /tftpboot/pxelinux.cfg
sudo vim /tftpboot/pxelinux.cfg/01-00-80-e1-42-60-17
adds the following content:

Generic Distro Configuration file generated by OpenEmbedded

menu title Select the boot mode
TIMEOUT 20
DEFAULT stm32mp157a-fsmp1a-emmc
LABEL stm32mp157a-fsmp1a-emmc
KERNEL /uImage
FDT /stm32mp157a-fsmp1a.dtb
APPEND root=/dev/mmcblk1p4 rootwait rw console=ttySTM0,115200

2) Open the development board
in the following way: the computer and the development board are connected to the same switch.
Set the following content in uboot
env set -f ethaddr 00:80:E1:42:60:17 //This is the MAC
env set serverip 192.168.20.100 //Ubuntu's IP
env save //Save
the following method: the computer and the development board are directly connected (that is, the network port of the computer and the network port of the development board are connected with a network cable) and
set in uboot The following content
env set -f ethaddr 00:80:E1:42:60:17 //This is the MAC
env set serverip 192.168.20.100 //Ubuntu's IP
env set gatewayip 192.168.20.1 //Gateway
env set ipaddr 192.168.20.120 / /IP env set for the board
save //Save
(note that if you use direct connection, you need to do the following steps:
1) Open ubuntu and click Edit ------> Virtual Network Editor
Insert image description here

2) Select your network card, switch the network card to ubuntu, and let ubuntu use your network card
Insert image description here

3) Connect the network cable between the computer and the development board
)
3) Start with
static IP startup or direct connection between the computer and the development board
if pxe get; then pxe boot; fi
automatically obtain the IP to start
run bootcmd_pxe
Insert image description here

Since no modifications have been made to the source code yet, it will stay at the following place during the kernel startup process.

3.7》Linux kernel eMMC driver transplantation

Referring to the schematic diagram, we can see that eMMC uses the sdmmc2 bus. There is no support for sdmmc2 in the currently used device tree file, so relevant content needs to be added to drive eMMC normally.
Note: Still under the Linux kernel source code.
1) Import the cross-compiler
source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
2) Add eMMC device Tree configuration, modify the arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi file
vim arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi
and add the following content:
&sdmmc2 { pinctrl-names = “default”, “opendrain”, "sleep"; pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_d47_pins_a>; pinctrl-1 = <&sdmmc2_b4_od_pins_a &sdmmc2_d47_pins_a>; pinctrl-2 = <&sdmmc2_b4_sleep_pins_a &sdmmc2_d47_slee p_pins_a> ; non-removable; no-sd; no-sdio; st,neg-edge;








bus-width = <8>;
vmmc-supply = <&v3v3>;
vqmmc-supply = <&vdd>;
mmc-ddr-3_3v;
status = “okay”;
};
3) Configure the kernel, since the default configuration of the kernel source code already supports eMMC, this section lists the main options, as follows
make menuconfig
Device Drivers —>
< > MMC/SD/SDIO card support —>
[
] STMicroelectronics STM32 SDMMC Controller
4) Compile the kernel-level device tree
make -j4 uImage dtbs LOADADDR=0xC2000040
5) Copy the compiled device tree file and kernel uImage file to the /tftpboot folder of the ubuntu host, which will be used when downloading the kernel and device tree files using tftp.
cp arch/arm/boot/uImage /tftpboot/
cp arch/arm/boot/dts/stm32mp157a-fsmp1a.dtb /tftpboot/
6) Restart the development board
Insert image description here

3.8》Linux kernel network card driver transplantation

Still under the Linux kernel source code.
1) Import the cross-compilation tool chain
source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
2) Add a network card Device tree configuration.
Modify the arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi file
vim arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi
and add the following content at the end of the file:
ðernet0 { status = “okay”; pinctrl-0 = <ðernet0_rgmii_pins_a >; pinctrl-1 = <ðernet0_rgmii_pins_sleep_a>; pinctrl-names = “default”, “sleep”; phy-mode = “rgmii-id”; max-speed = <1000>; phy-handle = <&phy0>; mdio0 { #address-cells = <1>; #size-cells = <0>; compatible = “snps,dwmac-mdio”;











phy0: ethernet-phy@0 { reg = <0>; }; }; }; 3) Compile the kernel and device tree make -j16 uImage dtbs LOADADDR=0xC2000040





4) Copy the compiled device tree file and kernel uImage file to the /tftpboot folder of the ubuntu host, which will be used when downloading the kernel and device tree files using tftp.
cp arch/arm/boot/uImage /tftpboot/
cp arch/arm/boot/dts/stm32mp157a-fsmp1a.dtb /tftpboot/
4) Restart the development board
Insert image description here

If you can ping the host, it means the network is open.

(2) Creation and mounting of root file system

4.1》Configure the cross-compilation tool chain for making the file system.

1) Install the cross compiler, your own arm-none-linux-gnueabihf-
linux@ubuntu:$ sudo apt-get install gcc-arm-linux-gnueabihf
linux@ubuntu:$ sudo apt-get install g+±arm-linux- gnueabihf

2) Verify that the development tools are installed correctly and the version information is displayed as shown below
linux@ubuntu:$ arm-linux-gnueabihf-gcc -v
Insert image description here

4.2》Import busybox source code

1) Copy the source code of the tool for making the file system: Source code: E:\Spring\System Transplantation\System Transplantation Tools\The source code of the tool for making the file system\busybox-1.29.3.tar.bz2 Copy to /home/linux/fs_mp157a in
Ubuntu /kernel/
2) Decompress the source code: busybox-1.29.3.tar.bz2, enter the source code directory
tar -xvf busybox-1.29.3.tar.bz2
cd busybox-1.29.3
*******Note: the following All operations are in this directory.
3) Configure busybox source code:
add "arm-linux-gnueabihf-" after CROSS_COMPILE in the Makefile in the top directory, and do not have spaces after it, otherwise there will be problems with compilation
vim Makefile
Insert image description here

4) You can use the following command to configure the source code:
make menuconfig
must be executed without changing any content, and must be saved to generate the .config configuration file.

4.3》Create file system

1) Compile busybox source code
make
Insert image description here


2) Installation: The default installation path of busybox is _install make install in the source directory
Insert image description here

3) Enter the installation directory
cd _install
4) Create other required directories
mkdir dev etc mnt proc var tmp sys root

5) Add libraries: Copy the libraries in the tool chain to the _install directory: look at your own cross-compilation tool arm-none-linux-gnueabihf- cp /
usr/arm-linux-gnueabihf/lib/ . -a
6) Delete Static library:
rm lib/*.a
7) Add system startup file: Add the file inittab under etc. The file content is as follows: Note: Modify the files to add the following content to
vim etc/inittab in the _install directory: #this is run first except when booting in single-user mode. ::sysinit:/etc/init.d/rcS


/bin/sh invocations on selected ttys

start an “askfirst” shell on the console (whatever that may be)

::askfirst:-/bin/sh

stuff to do when restarting the init process

::restart:/sbin/init

stuff to do before rebooting

::ctrlaltdel:/sbin/reboot

7) Add the file fstab under etc. The file content is as follows:
vim etc/fstab
add the following content:
#device mount-point type options dump fsck order
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
8) Create the init.d directory under etc and create the rcS file under init.d. The content of the rcS file is:
mkdir etc/init.d
vim etc/init.d/rcS
add The following content:
#!/bin/sh

This is the first script called by init process

/bin/mount -a
/sbin/mdev -s
9) Add executable permissions to rcS:
chmod a+x etc/init.d/rcS
10) Add profile file under etc, the file content is:
vim etc/profile
added The following:
#!/bin/sh
export HOSTNAME=fsmp1a
export USER=root
export HOME=root
export PS1="[ USER @ USER@USER@HOSTNAME \W]# "
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH

4.3》Test------Use NFS mounting method here

1) Delete the original /opt/rootfs:
sudo rm -rf /opt/rootfs

2) Copy our newly created root file system to the /opt/rootfs directory
sudo mkdir /opt/rootfs
sudo cp ./* /opt/rootfs -a
3) Modify /tftpboot/pxelinux.cfg/01- in the ubuntu host 00-80-e1-42-60-17 file adds nfs startup option
sudo vim /tftpboot/pxelinux.cfg/01-00-80-e1-42-60-17
and replaces it with the following content: nfsroot is the ip of ubantu, development Board ip
# Generic Distro Configuration file generated by OpenEmbedded
menu title Select the boot mode
MENU BACKGROUND /splash.bmp
TIMEOUT 20
DEFAULT stm32mp157a-fsmp1a-emmc
LABEL stm32mp157a-fsmp1a-emmc
KERNEL /uImage
FDT /stm32mp157a-fsmp1a.dtb
APPEND root= /dev/mmcblk1p4 rootwait rw console=ttySTM0,115200

	LABEL stm32mp157a-fsmp1a-nfs
	 KERNEL /uImage
	 FDT /stm32mp157a-fsmp1a.dtb
	 APPEND root=/dev/nfs nfsroot=192.168.20.100:/opt/rootfs ip=192.168.20.120 rootwait rw earlyprintk console=ttySTM0,115200

4) Open the development board
and start with static IP or direct connection between the computer and the development board
if pxe get; then pxe boot; fi
press Enter and enter the startup command run bootcmd_pxe
Insert image description here

Select nfs mounting method to start input 2
Insert image description here

You can use ls to check whether you have successfully entered the development board.
Insert image description here

Notice:

Insert image description here
If this error occurs, it means there is a problem with creating the root file system. Please try again. You can come in. The blogger has also been stuck here for a long time. He always thought that what he did was fine and he could access it on other people's computers, but his own computer was stuck here.

Guess you like

Origin blog.csdn.net/qq_52531759/article/details/131834958