Linux 内核编译

本文详细介绍了Linux内核的编译过程,包括打补丁、配置、编译以及查看生成文件。同时,为了配合U-boot引导,还讲述了如何编译uImage,指定LOADADDR,并解释了u-boot的环境变量。最后提到了设备树的编译以及对zImage的测试,虽然因缺少文件系统而报错,但确认了内核启动的可行性。
摘要由CSDN通过智能技术生成

 

对内核打上补丁,参考 https://blog.csdn.net/sunqian666888/article/details/85003007

 

创建输出文件夹:

sun@machine:~/share/build/linux-4.9.145$ mkdir out
sun@machine:~/share/build/linux-4.9.145$

设置默认config文件

sun@machine:~/share/build/linux-4.9.145$ make ARCH=arm O=out vexpress_defconfig
make[1]: 进入目录“/home/sun/share/build/linux-4.9.145/out”
  HOSTCC  scripts/basic/fixdep
  GEN     ./Makefile
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
make[1]: 离开目录“/home/sun/share/build/linux-4.9.145/out”
sun@machine:~/share/build/linux-4.9.145$ 
make ARCH=arm O=out menuconfig

然后进行修改:

 

 

 

进行编译:

 make ARCH=arm O=out zImage -j4

编译完成:

  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map
  OBJCOPY arch/arm/boot/Image
  Kernel: arch/arm/boot/Image is ready
  LDS     arch/arm/boot/compressed/vmlinux.lds
  AS      arch/arm/boot/compressed/head.o
  GZIP    arch/arm/boot/compressed/piggy_data
  CC      arch/arm/boot/compressed/misc.o
  CC      arch/arm/boot/compressed/decompress.o
  CC      arch/arm/boot/compressed/string.o
  SHIPPED arch/arm/boot/compressed/hyp-stub.S
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  SHIPPED arch/arm/boot/compressed/ashldi3.S
  SHIPPED arch/arm/boot/compressed/bswapsdi2.S
  AS      arch/arm/boot/compressed/hyp-stub.o
  AS      arch/arm/boot/compressed/lib1funcs.o
  AS      arch/arm/boot/compressed/ashldi3.o
  AS      arch/arm/boot/compressed/bswapsdi2.o
  AS      arch/arm/boot/compressed/piggy.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

查看生成的文件:

查看生成的文件的属性:

 

因为我要练习 U-boot 引导,所以还需编译 uImage

make V=1 ARCH=arm O=out uImage -j4

make -f ../scripts/Makefile.build obj=drivers/video/logo
make -f ../scripts/Makefile.build obj=drivers/video/fbdev/omap2
make -f ../scripts/Makefile.build obj=drivers/video/fbdev/omap2/omapfb
make -f ../scripts/Makefile.build obj=drivers/video/fbdev/omap2/omapfb/displays
make -f ../scripts/Makefile.build obj=drivers/video/fbdev/omap2/omapfb/dss
make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/Image
make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/zImage
make -f ../scripts/Makefile.build obj=arch/arm/boot/compressed arch/arm/boot/compressed/vmlinux
make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/uImage
make -f ../scripts/Makefile.build obj=arch/arm/boot/compressed arch/arm/boot/compressed/vmlinux
multiple (or no) load addresses: 
This is incompatible with uImages
Specify LOADADDR on the commandline to build an uImage
../arch/arm/boot/Makefile:79: recipe for target 'arch/arm/boot/uImage' failed
make[2]: *** [arch/arm/boot/uImage] Error 1
arch/arm/Makefile:329: recipe for target 'uImage' failed
make[1]: *** [uImage] Error 2
make[1]: 离开目录“/home/sun/share/build/linux-4.9.145/out”
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

 指定 LOADADDR=0xa0008000 后继续编译:

make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/Image
make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/zImage
make -f ../scripts/Makefile.build obj=arch/arm/boot/compressed arch/arm/boot/compressed/vmlinux
make -f ../scripts/Makefile.build obj=arch/arm/boot MACHINE= arch/arm/boot/uImage
make -f ../scripts/Makefile.build obj=arch/arm/boot/compressed arch/arm/boot/compressed/vmlinux
  /bin/bash ../scripts/mkuboot.sh -A arm -O linux -C none  -T kernel -a 0xa0008000 -e 0xa0008000 -n 'Linux-4.9.145' -d arch/arm/boot/zImage arch/arm/boot/uImage
"mkimage" command not found - U-Boot images will not be built
../arch/arm/boot/Makefile:79: recipe for target 'arch/arm/boot/uImage' failed
make[2]: *** [arch/arm/boot/uImage] Error 1
arch/arm/Makefile:329: recipe for target 'uImage' failed
make[1]: *** [uImage] Error 2
make[1]: 离开目录“/home/sun/share/build/linux-4.9.145/out”
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
sun@machine:~/share/build/linux-4.9.145$ make V=1 ARCH=arm O=out LOADADDR=0xa0008000 uImage -j4

其中 LOADADDR=0xa0008000 来自于 u-boot启动时的打印,暂时这么定

U-Boot 2018.11 (Nov 26 2018 - 11:45:35 +0800)

DRAM:  128 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 
MMC Device 1 not found
no mmc device at slot 1
Card did not respond to voltage select!
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (3 ms)
*** Warning: no boot file name; using '0A00020F.img'
Using smc911x-0 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename '0A00020F.img'.
Load address: 0xa0008000
Loading: *
TFTP error: 'Access violation' (2)

 

我的 u-boot 默认的环境:

=> env print
arch=arm
baudrate=38400
board=vexpress
board_name=vexpress
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootarm.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}extlinux/extlinux.conf
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_targets=mmc1 mmc0 pxe dhcp 
bootargs=root=/dev/sda1 rw console=ttyAMA0,38400n8 mem=1024M mtdparts=armflash:1M@0x800000(uboot),7M@0x1000000(kernel),24M@0x2000000(initrd) mmci.fmax=190000 devtmpfs.mount=0 vmalloc=256M
bootcmd=run distro_bootcmd; run bootflash
bootcmd_dhcp=if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00010:UNDI:003000;setenv bootp_arch 0xa;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci;
bootcmd_mmc0=setenv devnum 0; run mmc_boot
bootcmd_mmc1=setenv devnum 1; run mmc_boot
bootcmd_pxe=dhcp; if pxe get; then pxe boot; fi
bootdelay=2
bootfile=boot.scr.uimg
bootflash=run flashargs; cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值