Try   HackMD

使用 Sourcery G++ Lite 2011.03-42 編譯 Linux Kernel for QEMU ARM Version

tags: toolchain linux kernel ARM QEMU

Authors: WhoAmI, CrazyMonkey
Date: 2023-11-24
E-mail: kccddb@gmail.com
Copyright: CC BY-NC-SA

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

toolchain (gcc, make, lib…) for ARM version and build Linux kernel

Copyright © 2018 GNU Free Documentation License
Author: WhoAmI

使用 putty 連線至 Ubuntu (做 embedded system 不能依賴 Xwindow 等 有 GUI 的 環境)

  1. kernel source: linux-2.6.33.tar.bz2

    http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.tar.bz2

  2. toolchain: Sourcery G++ Lite 2011.03-42

    https://sourcery.mentor.com/GNUToolchain/package8734/public/arm-none-eabi/arm-2011.03-42-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

laikc@laikc-virtual-machine:~/arm$ tar jxvf linux-2.6.33.tar.bz2

安裝Sourcery G++ Lite 2011.03-42 出問題了

laikc@laikc-virtual-machine:~/arm$ ls
arm-2011.03-42-arm-none-eabi.bin linux-2.6.33 linux-2.6.33.tar.bz2

./arm-2011.03-42-arm-none-eabi.bin
Checking for required programs: awk grep sed bzip2 gunzip
Preparing to install
Extracting the JRE from the installer archive
Unpacking the JRE
Extracting the installation resources from the installer archive
Configuring the installer for this system's environment
strings: '/lib/libc.so.6': No such file

Launching installer

Graphical installers are not supported by the VM. The console mode will be used instead

Preparing CONSOLE Mode Installation

Sourcery G++ Lite for ARM EABI (created with InstallAnywhere)

Introduction

InstallAnywhere will guide you through the installation of Sourcery G++ Lite
for ARM EABI.

It is strongly recommended that you quit all programs before continuing with
this installation.

Respond to each prompt to proceed to the next step in the installation. If you
want to change something on a previous step, type 'back'.

You may cancel this installation at any time by typing 'quit'.

PRESS TO CONTINUE:

接下來一堆版權自己慢慢看吧

Installation Complete

Congratulations! Sourcery G++ Lite for ARM EABI has been successfully installed
to:

/home/laikc/CodeSourcery/Sourcery_G++_Lite

PRESS TO EXIT THE INSTALLER:


安裝內定 path 是 $HOME/CodeSourcery

laikc@laikc-virtual-machine:~/CodeSourcery$ pwd
/home/laikc/CodeSourcery
laikc@laikc-virtual-machine:~/CodeSourcery$

我使用的 linux kernel source

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ pwd
/home/laikc/arm/linux-2.6.33
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

"make defconfig"
Create a ./.config file by using the default
symbol values from either arch/$ARCH/defconfig

​​​​ or 
​​​​               arch/$ARCH/configs/${PLATFORM}_defconfig,
​​​​               depending on the architecture.

設定 default arm config 要做, 否則哭哭喔
https://lxr.linux.no/linux+v2.6.33/arch/arm/configs/
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ make ARCH=arm versatile_defconfig

HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function ‘conf_sym’:
scripts/kconfig/conf.c:159:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c: In function ‘conf_choice’:
scripts/kconfig/conf.c:231:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c:307:9: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
scripts/kconfig/conf.c: In function ‘conf_askvalue’:
scripts/kconfig/conf.c:105:8: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
HOSTCC scripts/kconfig/kxgettext.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf

configuration written to .config

想重新 config

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ make ARCH=arm menuconfig

*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.


*** Install ncurses (ncurses-devel) and try again.


make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

想重新 config 又錯了, 缺ncurse


http://packages.ubuntu.com/

查一下 ncurses 找到, 我的是32 bits, 別亂裝

套件 lib32ncurses5-dev

trusty (14.04LTS) (libdevel): developer's libraries for ncurses (32-bit)

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ sudo apt-get install libncurses5-dev
Reading package lists Done
Building dependency tree
Reading state information Done
The following extra packages will be installed:
libtinfo-dev
Suggested packages:
ncurses-doc
The following NEW packages will be installed:
libncurses5-dev libtinfo-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 306 kB of archives.
After this operation, 1,146 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://tw.archive.ubuntu.com/ubuntu/ raring/main libtinfo-dev i386 5.9-10ubuntu4 [93.1 kB]
Get:2 http://tw.archive.ubuntu.com/ubuntu/ raring/main libncurses5-dev i386 5.9-10ubuntu4 [213 kB]
Fetched 306 kB in 3s (89.9 kB/s)
Selecting previously unselected package libtinfo-dev:i386.
(Reading database 239355 files and directories currently installed.)
Unpacking libtinfo-dev:i386 (from /libtinfo-dev_5.9-10ubuntu4_i386.deb)
Selecting previously unselected package libncurses5-dev.
Unpacking libncurses5-dev (from /libncurses5-dev_5.9-10ubuntu4_i386.deb)
Setting up libtinfo-dev:i386 (5.9-10ubuntu4)
Setting up libncurses5-dev (5.9-10ubuntu4)
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

終於可以 menuconfig
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ make ARCH=arm menuconfig

.config - Linux Kernel v2.6.33 Configuration
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
lqqqqqqqqqqqqqqqqqqqqqq Linux Kernel Configuration qqqqqqqqqqqqqqqqqqqqqqqk
x Arrow keys navigate the menu. selects submenus ->. x
x Highlighted letters are hotkeys. Pressing includes, excludes, x
x modularizes features. Press to exit, for Help, </> x
x for Search. Legend: [] built-in [ ] excluded module < > x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x General setup -> x x
x x [
] Enable loadable module support -> x x
x x -*- Enable the block layer -> x x
x x System Type -> x x
x x Bus support -> x x
x x Kernel Features -> x x
x x Boot options -> x x
x x CPU Power Management -> x x
x x Floating point emulation -> x x
x x Userspace binary formats -> x x
x mqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x

mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

出來了喔 進入 Kernel Features

.config - Linux Kernel v2.6.33 Configuration
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
lqqqqqqqqqqqqqqqqqqqqqqqqqqqq Kernel Features qqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Arrow keys navigate the menu. selects submenus ->. x
x Highlighted letters are hotkeys. Pressing includes, excludes, x
x modularizes features. Press to exit, for Help, </> x
x for Search. Legend: [] built-in [ ] excluded module < > x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x [ ] Tickless System (Dynamic Ticks) x x
x x [ ] High Resolution Timer Support x x
x x Memory split (3G/1G user/kernel split) -> x x
x x Preemption Model (No Forced Preemption (Server)) -> x x
x x [
] Use the ARM EABI to compile the kernel x x
x x [*] Allow old ABI binaries to run with this kernel (EXPERIMENTAx x
x x [ ] High Memory Support (EXPERIMENTAL) x x
x x Memory model (Flat Memory) -> x x
x x [ ] Enable KSM for page merging x x
x x (4096) Low address space to protect from user allocation x x
x mqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x

mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ PATH=

HOME/CodeSourcery/SourceryG++Lite/bin:PATH
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ export PATH

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

看一下 toolchain 中 gcc prefix 是甚麼

ls -al ~/CodeSourcery/Sourcery_G++_Lite/bin*
total 17932****
drwxr-xr-x 2 laikc laikc 4096 6月 7 13:23 .
drwxr-xr-x 9 laikc laikc 4096 6月 7 13:22 ..
-rwxr-xr-x 1 laikc laikc 569376 4月 20 2011 arm-none-eabi-addr2line
-rwxrwxr-x 2 laikc laikc 592664 4月 21 2011 arm-none-eabi-ar
-rwxrwxr-x 2 laikc laikc 1054532 4月 21 2011 arm-none-eabi-as
-rwxr-xr-x 2 laikc laikc 223944 4月 20 2011 arm-none-eabi-c++
-rwxr-xr-x 1 laikc laikc 567936 4月 20 2011 arm-none-eabi-cfilt
-rwxr-xr-x 1 laikc laikc 222600 4月 20 2011 arm-none-eabi-cpp
-rwxr-xr-x 1 laikc laikc 18612 4月 20 2011 arm-none-eabi-elfedit
-rwxr-xr-x 2 laikc laikc 223944 4月 20 2011 arm-none-eabi-g

-rwxr-xr-x 2 laikc laikc 221768 4月 20 2011 arm-none-eabi-gcc
-rwxr-xr-x 2 laikc laikc 221768 4月 20 2011 arm-none-eabi-gcc-4.5.2
-rwxr-xr-x 1 laikc laikc 26812 4月 20 2011 arm-none-eabi-gcov
-rwxr-xr-x 1 laikc laikc 3378472 4月 20 2011 arm-none-eabi-gdb
-rwxr-xr-x 1 laikc laikc 3378472 4月 20 2011 arm-none-eabi-gdbtui
-rwxr-xr-x 1 laikc laikc 630916 4月 20 2011 arm-none-eabi-gprof
-rwxrwxr-x 2 laikc laikc 843876 4月 21 2011 arm-none-eabi-ld
-rwxrwxr-x 2 laikc laikc 578656 4月 21 2011 arm-none-eabi-nm
-rwxrwxr-x 2 laikc laikc 726428 4月 21 2011 arm-none-eabi-objcopy
-rwxrwxr-x 2 laikc laikc 869120 4月 21 2011 arm-none-eabi-objdump
-rwxrwxr-x 2 laikc laikc 592728 4月 21 2011 arm-none-eabi-ranlib
-rwxr-xr-x 1 laikc laikc 340780 4月 20 2011 arm-none-eabi-readelf
-rwxr-xr-x 1 laikc laikc 771476 4月 20 2011 arm-none-eabi-run
-rwxr-xr-x 1 laikc laikc 572292 4月 20 2011 arm-none-eabi-size
-rwxr-xr-x 1 laikc laikc 369120 4月 20 2011 arm-none-eabi-sprite
-rwxr-xr-x 1 laikc laikc 572224 4月 20 2011 arm-none-eabi-strings
-rwxrwxr-x 2 laikc laikc 726428 4月 21 2011 arm-none-eabi-strip
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ make ARCH=arm CROSS_COMPILE=arm-none-eabi- all

看看 zImage

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ ls arch/arm/boot/
bootp compressed Image install.sh Makefile zImage
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

準備測一下

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ /usr/local/bin/qemu-system-arm -machine help
Supported machines are:
versatileab ARM Versatile/AB (ARM926EJ-S)
versatilepb ARM Versatile/PB (ARM926EJ-S)
lm3s811evb Stellaris LM3S811EVB
z2 Zipit Z2 (PXA27x)
connex Gumstix Connex (PXA255)
sx1 Siemens SX1 (OMAP310) V2
realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
cubieboard cubietech cubieboard
vexpress-a9 ARM Versatile Express for Cortex-A9
lm3s6965evb Stellaris LM3S6965EVB
realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
mainstone Mainstone II (PXA27x)
terrier Terrier PDA (PXA270)
n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
nuri Samsung NURI board (Exynos4210)
realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
verdex Gumstix Verdex (PXA270)
spitz Spitz PDA (PXA270)
canon-a1100 Canon PowerShot A1100 IS
akita Akita PDA (PXA270)
smdkc210 Samsung SMDKC210 board (Exynos4210)
integratorcp ARM Integrator/CP (ARM926EJ-S)
sx1-v1 Siemens SX1 (OMAP310) V1
kzm ARM KZM Emulation Baseboard (ARM1136)
highbank Calxeda Highbank (ECX-1000)
n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
collie Collie PDA (SA-1110)
realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
vexpress-a15 ARM Versatile Express for Cortex-A15
none empty machine
cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
tosa Tosa PDA (PXA255)
midway Calxeda Midway (ECX-2000)
virt ARM Virtual Machine
borzoi Borzoi PDA (PXA270)
laikc@laikc-virtual-machine:~/arm/linux-2.6.33$

注意 -machine versatileab
測試一下 kernel 注意 -nographic -append "console=ttyAMA0", 否則沒畫面沒畫面 只有 Uncompressing Linux done, booting the kernel.

laikc@laikc-virtual-machine:~/arm/linux-2.6.33$ /usr/local/bin/qemu-system-arm -machine versatileab -kernel arch/arm/boot/zImage -nographic -append "console=ttyAMA0"
audio: Could not init `oss' audio driver
Uncompressing Linux done, booting the kernel.
Linux version 2.6.33 (laikc@laikc-virtual-machine) (gcc version 4.5.2 (Sourcery G++ Lite 2011.03-42) ) #1 Sat Jun 7 14:19:01 CST 2014
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
CPU: VIVT data cache****, VIVT instruction cache
Machine: ARM-Versatile AB
Memory policy: ECC disabled, Data cache writeback
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console=ttyAMA0
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 128MB = 128MB total
Memory: 126776KB available (2572K code, 219K data, 100K init, 0K highmem)
Hierarchical RCU implementation.
RCU-based detection of stalled CPUs is enabled.
NR_IRQS:192
VIC @f1140000: id 0x00041190, vendor 0x41
Console: colour dummy device 80x30
Calibrating delay loop 593.10 BogoMIPS (lpj=2965504)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
Serial: AMBA PL011 UART driver
dev:f1: ttyAMA0 at MMIO 0x101f1000 (irq = 12) is a AMBA/PL011
console [ttyAMA0] enabled
dev:f2: ttyAMA1 at MMIO 0x101f2000 (irq = 13) is a AMBA/PL011
dev:f3: ttyAMA2 at MMIO 0x101f3000 (irq = 14) is a AMBA/PL011
bio: create slab at 0
Switching to clocksource timer3
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (double precision)
Installing knfsd (copyright © 1996 okir@monad.swb.de).
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
ROMFS MTD © 2007 Red Hat, Inc.
msgmni has been set to 247
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
CLCD: Versatile hardware, VGA display
Console: switching to colour frame buffer device 80x60
brd: module loaded
armflash.0: Found 1 x32 devices at 0x0 in 32-bit bank
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
RedBoot partition parsing not available
afs partition parsing not available
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre
eth0: SMC91C11xFD (rev 1) at c88be000 IRQ 25 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
mice: PS/2 mouse device common for all mice
TCP cubic registered
NET: Registered protocol family 17
VFP support v0.3: not present
input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0
input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input1
Root-NFS: No NFS server available, giving up.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "(null)" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[] (unwind_backtrace+0x0/0xcc) from [] (panic+0x3c/0x118)
[] (panic+0x3c/0x118) from [] (mount_block_root+0x1bc/0x1fc)
[] (mount_block_root+0x1bc/0x1fc) from [] (prepare_namespace+0x164/0x1b8)
[] (prepare_namespace+0x164/0x1b8) from [] (kernel_init+0xd8/0x10c)
[] (kernel_init+0xd8/0x10c) from [] (kernel_thread_exit+0x0/0x8)
INFO: RCU detected CPU 0 stall (t=1000 jiffies)

可以開機了, 但是缺 rootfs

有 rootfs 這樣就能進入 shell

Futher reading:

編譯 ARM Busybox 1.22.0 當 Rootfs for QEMU Linux

busybox, linux, cross reference

make mrproper vs make distclean in the Linux kernel

https://unix.stackexchange.com/questions/550483/make-mrproper-vs-make-distclean-in-the-linux-kernel

有真正開發版 還需 device tree
make dtbs

How to compile dts Linux device tree source files to dtb?