系统版本:Ubuntu18.04-64
编译器版本:gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
uboot版本:2018.07 -linux4sam_6.0
板子型号:at91sama5d3x-xplained
MCU型号:sama5d36
内核交叉工具链依赖于Makefile文件去级联编译,Kconfig文件做配置,比如现在的ESP32也是采用这种图形化配置,好用的东西接受度就会广。
一、调出配置界面
查看Makefile文件,查看版本信息4.19
make menuconfig
General setup ---> //通用配置 <======
[*] Enable loadable module support ---> // 使能insmod
-*- Enable the block layer ---> // 磁盘IO调度, 一般使用默认的就ok
System Type ---> //选择特定的arm core /cpu 类型,以及它们的一下属性, make menuconfig之后应当确认一下该部分
Bus support ---> // 一些总线的支持,一般使用默认就ok
Kernel Features ---> //内核的特性,比如应用和内核空间的内存分布
Boot options ---> //启动选项, 内核启动过程当中,可以修改的特性
CPU Power Management ---> // cpu电源管理, 一般在用电池设备当中会要做选择
Power management options ---> // 外围设备的电源管理 suspend() resum()
Networking support ---> // 网络的支持,基本上都是协议方面的,比如TCP/IP, 域套接字, 组播 , ppp协议
Device Drivers ---> // 设备驱动,包含两部分驱动: 控制器===设备的驱动, 经常光顾的选项
File systems ---> // 文件系统的支持,比如支持ntfs, ext4, nfs, cramfs, jiffs, minix................... yaffs, ubifs
使用*号选择编译项
[*]
< > 可以用空格去选择
()==>往里面填一个值,使用回车进入,比如 (arm-none-linux-gnueabi-) Cross-compiler tool prefix
General setup --->
[*] Configure standard kernel features (for small systems) --->
[*] Sysctl syscall support (NEW)
[*] Load all symbols for debugging/ksymoops (NEW)
[*] Include all symbols in kallsyms
//内核崩溃kernel panic, 会提示代码执行栈
System Type --->
ARM system type (Samsung S5PC100) --->
[*] SMDKC100
Kernel Features --->
[*] Use the ARM EABI to compile the kernel //如果交叉工具链中出现了eabi,一定要选上
[*] Allow old ABI binaries to run with this kernel (EXPERIMENTAL)
cmdline和bootags的关系: 一样的
[ * ] Networking support --->
Networking options --->
<*> Unix domain sockets
[*] TCP/IP networking <==========如果有网卡,一个一定要选上
[*] IP: multicasting
File systems --->
<*> Ext3 journalling file system support
<*> The Extended 4 (ext4) filesystem
Pseudo filesystems ---> // 虚拟文件系统: 在内存中管理文件,掉电之后,文件就不存在, 开机的时候临时创建
// dev/, proc/, sys/几个目录中的文件都是临时
[*] /proc file system support (NEW)
[*] sysfs file system support (NEW)
[*] Virtual memory file system support (former shm fs)
[*] Tmpfs POSIX Access Control Lists
[*] Miscellaneous filesystems ---> //杂项文件系统, 对支持存放在nand中文件的管理方式
<*> Compressed ROM file system support (cramfs)
<*> SquashFS 4.0 - Squashed file system support
[*] Network File Systems (NEW) ---> // 网络文件系统: nfs
<*> NFS client support
[*] NFS client support for NFS version 3
[*] NFS client support for the NFSv3 ACL protocol extension
<*> Native language support ---> //内核支持的字符编码方式
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
<*> ASCII (United States)
<*> NLS ISO 8859-1 (Latin 1; Western European Languages)
<*> NLS UTF-8
Device Drivers --->
<*> Connector - unified userspace <-> kernelspace linker --->
<*> Memory Technology Device (MTD) support ---> // 有nand,onenand等等设备,需要选择mtd
[*] MTD partitioning support
[*] Command line partition table parsing //uboot可以传递分区表
<*> NAND Device Support ---> //nand设备支持, 具体的某个平台的nand控制器选项
[*] Network device support ---> //需要有网卡
[*] Ethernet (10 or 100Mbit) (NEW) --->
<*> DM9000 support
[*] USB support --->
<*> Support for Host-side USB
[*] USB device filesystem (DEPRECATED)
[*] USB device class-devices (DEPRECATED) (NEW)
<*> USB Modem (CDC ACM) support // 3G配置
<*> USB Serial Converter support ---> usb转串口
[*] Networking support —>
网卡驱动选择
Device Drivers --->
[*] Network device support --->
[*] Ethernet driver support --->
-*- MDIO bus device drivers ---- //MDIO控制器读取PHY寄存器
-*- PHY Device support and infrastructure --->
<*> Micrel PHYs //Micrel公司的ksz9031和ksz8081
I2C总线
I2C support --->
<*> I2C device interface //i2c驱动接口
-*- I2C bus multiplexing support
I2C Hardware Bus support ---> //硬件总线
<*> GPIO-based bitbanging I2C //对应GPIO引脚复用
SPI总线
[*] SPI support --->
<*> GPIO-based bitbanging SPI Master
<M> User mode SPI device driver support //驱动以模块的方式加载,和外部的MCU通过spi通讯
GPIO总线
[*] GPIO Support --->
[*] /sys/class/gpio/... (sysfs interface) //支持sysfs接口,方便调试字符驱动
USB支持,挂载鼠标键盘,和U盘设备
[*] USB support --->
<*> Support for Host-side USB
[*] USB announce new devices
<*> USB Serial Converter support ---> //usb转串口
<*> MMC/SD/SDIO card support ---> //EMMC
<*> MMC block device driver //驱动
(8) Number of minors per block device //数据总线位数
[*] MMC host drivers debugging //打印调试信息
<*> Secure Digital Host Controller Interface support
<*> SDHCI platform and OF driver helper
<*> SDHCI OF support for the Atmel SDMMC controller
<*> SDHCI support for the Cadence SD/SDIO/eMMC controller
[*] LED Support --->
[*] LED Trigger support --->
<*> LED Heartbeat Trigger //内核正常运行时,心跳LED指示灯,硬件需要设计指示灯
内核的编译的控制:
all: vmlinux
# Build vmlinux
# ---------------------------------------------------------------------------
# vmlinux is built from the objects selected by $(vmlinux-init) and
# $(vmlinux-main). Most are built-in.o files from top-level directories
# in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
# Ordering when linking is important, and $(vmlinux-init) must be first.
#
# vmlinux
# ^
# |
# +-< $(vmlinux-init)
# | +--< init/version.o + more
# |
# +--< $(vmlinux-main)
# | +--< driver/built-in.o mm/built-in.o + more
# |
# +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
============>
init-y := init/
drivers-y := drivers/ sound/ firmware/
net-y := net/
libs-y := lib/
core-y := usr/
==================================
vmlinux-init := $(head-y) $(init-y)
vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
vmlinux-all := $(vmlinux-init) $(vmlinux-main)
vmlinux-lds := arch/$(SRCARCH)/kernel/vmlinux.lds //链接脚本arch/arm/kernel/vmlinux.lds
head-y在顶层的Makefile中找不到:实际是arch/arm/Makefile中
include $(srctree)/arch/$(SRCARCH)/Makefile
ifeq ($(CONFIG_MMU),) // CONFIG_MMU肯定不为空, CONFIG_MMU=y
MMUEXT := -nommu
endif
head-y := arch/arm/kernel/head.o arch/arm/kernel/init_task.o
arch/arm/kernel/head.S //入口文件
arch/arm/kernel/vmlinux.lds //链接脚本
OUTPUT_ARCH(arm)
ENTRY(stext) //入口函数
SECTIONS
{
. = 0xC0000000 + 0x00008000; // 3G以上的空间
.init : { /* Init code and data 包含代码和数据的. free 144K mem */
_stext = .; // 起始的段
_sinittext = .;
*(.head.text) // 有个text段
*(.init.text) *(.cpuinit.text) *(.meminit.text)
_einittext = .;
__proc_info_begin = .; //起始位置
*(.proc.info.init) // 特殊的段,和.u_boot_cmd段很相似
__proc_info_end = .; //结束位置
__arch_info_begin = .;
*(.arch.info.init)
__arch_info_end = .;
__tagtable_begin = .;
*(.taglist.init)
__tagtable_end = .;
========================================================
Kconfig---> Makefile的关系
make menuconfig --> 各个目录下Kcongfig ==> 保存.config
CONFIG_CPU_S5PC100=y
==> Kbuild处理: 1, 给Makefile
obj-$(CONFIG_CPU_S5PC100) += cpu.o init.o clock.o gpiolib.o irq-gpio.o
2,产生一个头文件,给c语言代码代码中使用
./include/generated/autoconf.h:98:#define CONFIG_CPU_S5PC100 1
#define CONFIG_CPU_S5PC100 1
如果CONFIG_INET6_XFRM_MODE_TUNNEL值为y
#define CONFIG_INET6_XFRM_MODE_TUNNEL 1
如果CONFIG_INET6_XFRM_MODE_TUNNEL值为m
#define CONFIG_INET6_XFRM_MODE_TUNNEL_MODULE 1
================================================
如果在内核中编译代码mytest.c
1, 编写Kcongfig
config MY_TEST
tristate "this is a config test"
help
this is a help info to choose my_test
编写Makefile
obj-$(CONFIG_MY_TEST) += mytest.o
2,直接修改Makfile
obj-y += mytest.o
File systems --->
<*> The Extended 4 (ext4) filesystem
[*] Use ext4 for ext2 file systems
[*] Network File Systems --->
<*> NFS client support
<*> NFS client support for NFS version 2
<*> NFS client support for NFS version 3
<*> NFS client support for NFS version 4 //网络文件系统,18.04的linux对应04版本的NFS
[*] Root file system on NFS //支持从NFS启动,调试字符驱动非常方便,
不用拷贝,可直接共享运行
更多linux知识点推荐:
[linux kernel]内核移植过程记录
[linux kernel] 内核启动流程梳理
[linux 底层]u-boot EMMC驱动
[linux 底层]u-boot图形化裁剪配置
[Linux 底层]U-boot ksz9031网络驱动调试
[Linux 底层]U-boot调试命令使用技巧
[Linux 底层]U-boot编译移植
[Linux 底层]U-boot烧录脚本介绍SecureCRT
[Linux 底层]bootstrap移植裁剪及编译
[Linux 底层] 平台软件分层介绍
[Linux 驱动] RS485测试程序编写
[Linux 驱动] CAN测试程序编写
推荐阅读:
芯片手册解读 | Linux底层
关注微信公众号,更多精彩内容及时推送。
图片