Mastering Embedded Linux Programming 学习 (三)在百问网157开发板上,编译构建linux内核
一、下载内核源码
wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.223.tar.gz
tar -zxvf linux-5.4.223.tar.gz
mv linux-5.4.223 linux-stable
书上用的是5.4.50版本的,但又提到了如果有新的5.4.x的就用新的5.4.x的,这里下载下来测试一下
设备树文件添加、修改
从原有的157设备树文件复制成我们的板子的文件
cp arch/arm/boot/dts/stm32mp157a-dk1.dts arch/arm/boot/dts/stm32mp157c-myboard.dts
并把arch/arm/boot/dts/stm32mp157c-dk2.dts的额外内容添加到arch/arm/boot/dts/stm32mp157c-myboard.dts中
修改arch/arm/boot/dts/Makefile,在157系列下面添加我们的设备树文件,这样在编译stm32mp157系列的设备树的时候就可以自动编译我们的设备树文件了
删除i2c4节点
在根节点下添加电源配置
v3v3: regulator-3p3v {
compatible = "regulator-fixed";
regulator-name = "v3v3";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
v1v8_audio: regulator-v1v8-audio {
compatible = "regulator-fixed";
regulator-name = "v1v8_audio";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
regulator-boot-on;
};
v3v3_hdmi: regulator-v3v3-hdmi {
compatible = "regulator-fixed";
regulator-name = "v3v3_hdmi";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
v1v2_hdmi: regulator-v1v2-hdmi {
compatible = "regulator-fixed";
regulator-name = "v1v2_hdmi";
regulator-min-microvolt = <1200000>;
regulator-max-microvolt = <1200000>;
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;
};
vdd: regulator-vdd {
compatible = "regulator-fixed";
regulator-name = "vdd";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
vdd_usb: regulator-vdd-usb {
compatible = "regulator-fixed";
regulator-name = "vdd_usb";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
regulator-boot-on;
};
有了u-boot的经历,这里就轻车熟路了
编译命令
使用stm32的配置来编译
make ARCH=arm multi_v7_defconfig
make ARCH=arm LOADADDR=0xC2000040 -j 64 uImage
make ARCH=arm dtbs
格式化SD卡
将SD卡的第四个分区格式化为fat格式,然后挂载到ubuntu,最后把生成的uImage和stm32mp157c-myboard.dtb拷贝进去
加载启动内核
通过SD卡进入到u-boot,然后通过如下命令把uImage和设备树加载到DDRAM
fatload mmc 0:4 0xC2000040 uImage
上面这个命令是把0号mmc设备,也就是SD卡的第四个分区里的uImage文件加载到0xC2000040这个位置,这里使用的fatload,所以在这之前要把SD卡第四个分区格式化成fat格式
fatload mmc 0:4 0xC4000040 stm32mp157c-myboard.dtb
同样,把设备树文件加载到内存,这里选择0xC4000040是防止设备树覆盖了内核镜像,这里需要计算一下
结果如下所示
然后开始启动我们的内核
bootm 0xC2000040 - 0xC4000040
有输出,但是卡在了文件系统这里了,没关系