开始基于at91sam9261ek 的 linux kernel的编译,下载运行
一、at91 linux kernel下载
1、atmel 提供at91系列的linux kernel,当然,也可以直接由指定的linux kernel版本开始。
参考地址:
https://www.linux4sam.org/bin/view/Linux4SAM/LinuxKernel#Getting_Kernel_sources
当前最新的Linux kernel 版本:5.8.14
atmel 官网提示的linux kernel版本为:v5.4.41
目前为了方便,使用 linux kernel v5.4.41,作为at91sam9261ek的开发版本。
2、代码下载:
git clone git://github.com/linux4sam/linux-at91.git
(不过最近github.com 国内访问还是比较慢的,这个linux kernel代码仓库较大,下载非常的慢)
gitee上找了几个地址:
git clone https://gitee.com/mirrors_mrjimenez/linux-at91.git (速度较快,版本不是最新)
3、可以把仓库下载下来,再
git remote remove origin
git remote add origin git://github.com/linux4sam/linux-at91.git
git pull
更新到最新,这样速度可能会快一些
二、配置、编译、下载
1、make ARCH=arm at91_dt_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
2、图形配置,前期基本不用改。
make ARCH=arm menuconfig
3、编译内核
make ARCH=arm uImage LOADADDR=0x20008000 CROSS_COMPILE=arm-linux-gnueabi-
4、编译问题总结:
(1)
scripts/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory
#include <openssl/bio.h>
解决方法:
sudo apt-get install openssl
sudo apt-get install libssl-dev
(2)
"mkimage" command not found - U-Boot images will not be built
解决方法:
sudo apt-get install u-boot-tools
3、生成uImage
Image Name: Linux-4.19.78-linux4sam-6.2-icp-
Created: Thu Oct 8 14:20:15 2020
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4562752 Bytes = 4455.81 KiB = 4.35 MiB
Load Address: 20008000
Entry Point: 20008000
Kernel: arch/arm/boot/uImage is ready
4、设备树代码的编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs
5、内核下载:
根据uboot传递的linux内核启动参数,linux kernel文件放置在 NandFlash 2M之后的位置。
也就是:偏移地址为0x20 0000。
三、串口打印
1、第一次生成的内核,下载到板子上,没有运行成功,提示文件CRC错误。原因为生成的uImage文件较大,修改uboot,nand read的块太小,改大。
diff --git a/include/configs/at91sam9261ek.h b/include/configs/at91sam9261ek.h
index 39b879b3b1..3aaf72c9f7 100644
--- a/include/configs/at91sam9261ek.h
+++ b/include/configs/at91sam9261ek.h
@@ -115,7 +115,7 @@
#else /* CONFIG_SYS_USE_NANDFLASH */
/* bootstrap + u-boot + env + linux in nandflash */
-#define CONFIG_BOOTCOMMAND "nand read 0x22000000 0x200000 0x300000; bootm"
+#define CONFIG_BOOTCOMMAND "nand read 0x22000000 0x200000 0x600000; bootm"
2、读内核文件成功了,但内核还是没有跑起来,停在:Starting kernel .. 原因是后面继续分析
NAND read: device 0 offset 0x200000, size 0x600000
6291456 bytes read: OK
## Booting kernel from Legacy Image at 22000000 ...
Image Name: Linux-4.19.78-linux4sam-6.2-icp-
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4562752 Bytes = 4.4 MiB
Load Address: 20008000
Entry Point: 20008000
Verifying Checksum ... OK
Loading Kernel Image
Starting kernel ...
四、思考总结
1、uImage之前只有1~2M,这次编译的为 4~5MB,原因为何?
2、uImage不能启动,是传递的参数问题,还是其他问题?
3、编译内核与内核下载已经清楚。