Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

리눅스 커널 포팅 테스트

u-boot, Linux, busybox로 aarch64리눅스 이미지를 만들어봅시다. 연습삼아 해본거라 챗GPT를 좀 쓰긴했어요.

사용한 명령어들

크로스 컴파일러 구축

sudo apt search aarch64
sudo apt install binutils-aarch64-linux-gnu
sudo apt install gcc-aarch64-linux-gnu
sudo apt install g++-aarch64-linux-gnu
sudo apt install build-essential bison flex libssl-dev libncurses5-dev libelf-dev
aarch64-linux-gnu-gcc --version
sudo apt install qemu-system-arm qemu-system-aarch64
qemu-system-aarch64 --version
sudo apt install cpio

U-boot

git clone https://source.denx.de/u-boot/u-boot.git
cd u-boot
git checkout v2024.01
make qemu_arm64_defconfig
make -j$(nproc) CROSS_COMPILE=aarch64-linux-gnu-
qemu-system-aarch64   -M virt   -cpu cortex-a53   -nographic   -bios u-boot.bin

cd .. # 메인 디렉토리로

Linux 커널 빌드

git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
git checkout v6.6
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image
qemu-system-aarch64 -M virt -cpu cortex-a53 -nographic -kernel arch/arm64/boot/Image -append "console=ttyAMA0" -no-reboot

cd .. # 메인 디렉토리로

BusyBox 빌드

git clone git://busybox.net/busybox.git
cd busybox
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make menuconfig 
#(여기서 
#   Settings  --->
#       [*] Build static binary (no shared libs)
#   Networking Utilities    --->
#       [ ] tc
# 로 지정)
make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

mkdir -p rootfs/{bin,sbin,etc,proc,sys,usr/bin,usr/sbin,dev}
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install CONFIG_PREFIX=./rootfs
cat > rootfs/init << EOF
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "\n\nMy first AARCH64 porting!!"
exec /bin/sh

EOF

chmod +x rootfs/init
cd rootfs
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz
cd ..

cd .. # 메인 디렉토리로

파일을 복사할까요?

u-boot/u-boot.bin을 binarys/u-boot.bin으로, linux/arch/arm64/boot/Image를 binarys/Image로, busybox/initramfs.cpio.gz를 binarys/initramfs.cpio.gz로.

최소한의 리눅스 환경에서 돌려봅시다.

qemu-system-aarch64 \
  -M virt \
  -cpu cortex-a53 \
  -nographic \
  -kernel binarys/Image \
  -initrd binarys/initramfs.cpio.gz \
  -append "console=ttyAMA0"

출력이 아래와 같이 되는군요!

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 6.6.0 (varzero@VARZeroDesk) (aarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #1 SMP PREEMPT Sat Apr 19 10:38:03 KST 2025
[    0.000000] KASLR enabled
[    0.000000] random: crng init done
[    0.000000] Machine model: linux,dummy-virt
[    0.000000] efi: UEFI not found.
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x0000000047ffffff]
[    0.000000] NUMA: NODE_DATA [mem 0x47fb29c0-0x47fb4fff]
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000040000000-0x0000000047ffffff]
[    0.000000]   DMA32    empty
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040000000-0x0000000047ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x0000000047ffffff]
[    0.000000] cma: Reserved 32 MiB at 0x0000000045c00000 on node -1
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv1.1 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
[    0.000000] psci: SMC Calling Convention v1.0
[    0.000000] percpu: Embedded 22 pages/cpu s50728 r8192 d31192 u90112
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: kernel page table isolation forced ON by KASLR
[    0.000000] CPU features: detected: Kernel page table isolation (KPTI)
[    0.000000] CPU features: detected: ARM erratum 843419
[    0.000000] CPU features: detected: ARM erratum 845719
[    0.000000] alternatives: applying boot alternatives
[    0.000000] Kernel command line: console=ttyAMA0
[    0.000000] Dentry cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.000000] Inode-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.000000] Fallback order for Node 0: 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32256
[    0.000000] Policy zone: DMA
[    0.000000] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.000000] software IO TLB: area num 1.
[    0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 67108864 bytes tlb structure
[    0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 33554432 bytes tlb structure
[    0.000000] software IO TLB: SWIOTLB bounce buffer size adjusted 32768 -> 8192 slabs
[    0.000000] software IO TLB: mapped [mem 0x0000000044c00000-0x0000000045c00000] (16MB)
[    0.000000] Memory: 35560K/131072K available (16576K kernel code, 4264K rwdata, 10556K rodata, 9152K init, 605K bss, 62744K reserved, 32768K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU event tracing is enabled.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=1.
[    0.000000]  Trampoline variant of Tasks RCU enabled.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] Root IRQ handler: gic_handle_irq
[    0.000000] GICv2m: range[mem 0x08020000-0x08020fff], SPI[80:143]
[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.000000] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
[    0.000000] clocksource: arch_sys_counter: mask: 0x1ffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[    0.000059] sched_clock: 57 bits at 63MHz, resolution 16ns, wraps every 4398046511096ns
[    0.004900] Console: colour dummy device 80x25
[    0.006021] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=250000)
[    0.006104] pid_max: default: 32768 minimum: 301
[    0.006822] LSM: initializing lsm=capability,integrity
[    0.007847] Mount-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.007867] Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.022115] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.026358] RCU Tasks: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1.
[    0.026640] RCU Tasks Trace: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1.
[    0.027371] rcu: Hierarchical SRCU implementation.
[    0.027393] rcu:     Max phase no-delay instances is 1000.
[    0.030070] EFI services will not be available.
[    0.031045] smp: Bringing up secondary CPUs ...
[    0.031462] smp: Brought up 1 node, 1 CPU
[    0.031479] SMP: Total of 1 processors activated.
[    0.031519] CPU features: detected: 32-bit EL0 Support
[    0.031527] CPU features: detected: 32-bit EL1 Support
[    0.031558] CPU features: detected: CRC32 instructions
[    0.032463] CPU: All CPU(s) started at EL1
[    0.032572] alternatives: applying system-wide alternatives
[    0.040523] devtmpfs: initialized
[    0.047730] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.047833] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[    0.049873] pinctrl core: initialized pinctrl subsystem
[    0.055110] DMI not present or invalid.
[    0.060866] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.066228] DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations
[    0.066475] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations
[    0.066631] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
[    0.066853] audit: initializing netlink subsys (disabled)
[    0.067950] audit: type=2000 audit(0.064:1): state=initialized audit_enabled=0 res=1
[    0.071122] thermal_sys: Registered thermal governor 'step_wise'
[    0.071154] thermal_sys: Registered thermal governor 'power_allocator'
[    0.071492] cpuidle: using governor menu
[    0.072315] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[    0.072622] ASID allocator initialised with 32768 entries
[    0.076814] Serial: AMBA PL011 UART driver
[    0.098457] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 13, base_baud = 0) is a PL011 rev1
[    0.099103] printk: console [ttyAMA0] enabled
[    0.131362] Modules: 2G module region forced by RANDOMIZE_MODULE_REGION_FULL
[    0.131623] Modules: 0 pages in range for non-PLT usage
[    0.131643] Modules: 513952 pages in range for PLT usage
[    0.134364] HugeTLB: registered 1.00 GiB page size, pre-allocated 0 pages
[    0.134713] HugeTLB: 0 KiB vmemmap can be freed for a 1.00 GiB page
[    0.135175] HugeTLB: registered 32.0 MiB page size, pre-allocated 0 pages
[    0.135437] HugeTLB: 0 KiB vmemmap can be freed for a 32.0 MiB page
[    0.135675] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages
[    0.136063] HugeTLB: 0 KiB vmemmap can be freed for a 2.00 MiB page
[    0.136496] HugeTLB: registered 64.0 KiB page size, pre-allocated 0 pages
[    0.136832] HugeTLB: 0 KiB vmemmap can be freed for a 64.0 KiB page
[    0.143024] ACPI: Interpreter disabled.
[    0.146850] iommu: Default domain type: Translated
[    0.147152] iommu: DMA domain TLB invalidation policy: strict mode
[    0.148378] SCSI subsystem initialized
[    0.149891] usbcore: registered new interface driver usbfs
[    0.150273] usbcore: registered new interface driver hub
[    0.150628] usbcore: registered new device driver usb
[    0.152505] pps_core: LinuxPPS API ver. 1 registered
[    0.152760] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.153254] PTP clock support registered
[    0.153854] EDAC MC: Ver: 3.0.0
[    0.155399] scmi_core: SCMI protocol bus registered
[    0.157552] FPGA manager framework
[    0.158264] Advanced Linux Sound Architecture Driver Initialized.
[    0.164947] vgaarb: loaded
[    0.167780] clocksource: Switched to clocksource arch_sys_counter
[    0.168773] VFS: Disk quotas dquot_6.6.0
[    0.169038] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.171320] pnp: PnP ACPI: disabled
[    0.181461] NET: Registered PF_INET protocol family
[    0.182728] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.185952] tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.186403] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.186676] TCP established hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.186972] TCP bind hash table entries: 1024 (order: 3, 32768 bytes, linear)
[    0.187235] TCP: Hash tables configured (established 1024 bind 1024)
[    0.189216] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.189535] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.190300] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.191885] RPC: Registered named UNIX socket transport module.
[    0.192129] RPC: Registered udp transport module.
[    0.192302] RPC: Registered tcp transport module.
[    0.192438] RPC: Registered tcp-with-tls transport module.
[    0.192635] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.192911] PCI: CLS 0 bytes, default 64
[    0.195389] Unpacking initramfs...
[    0.196098] kvm [1]: HYP mode not available
[    0.198118] Initialise system trusted keyrings
[    0.204147] workingset: timestamp_bits=42 max_order=15 bucket_order=0
[    0.205458] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.207021] NFS: Registering the id_resolver key type
[    0.207422] Key type id_resolver registered
[    0.207602] Key type id_legacy registered
[    0.212303] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.212571] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.213479] 9p: Installing v9fs 9p2000 file system support
[    0.258834] Key type asymmetric registered
[    0.259040] Asymmetric key parser 'x509' registered
[    0.259376] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 245)
[    0.263778] io scheduler mq-deadline registered
[    0.263974] io scheduler kyber registered
[    0.264284] io scheduler bfq registered
[    0.288190] Freeing initrd memory: 1160K
[    0.288999] pl061_gpio 9030000.pl061: PL061 GPIO chip registered
[    0.292479] pci-host-generic 4010000000.pcie: host bridge /pcie@10000000 ranges:
[    0.293038] pci-host-generic 4010000000.pcie:       IO 0x003eff0000..0x003effffff -> 0x0000000000
[    0.293528] pci-host-generic 4010000000.pcie:      MEM 0x0010000000..0x003efeffff -> 0x0010000000
[    0.293865] pci-host-generic 4010000000.pcie:      MEM 0x8000000000..0xffffffffff -> 0x8000000000
[    0.294391] pci-host-generic 4010000000.pcie: Memory resource size exceeds max for 32 bits
[    0.294922] pci-host-generic 4010000000.pcie: ECAM at [mem 0x4010000000-0x401fffffff] for [bus 00-ff]
[    0.296067] pci-host-generic 4010000000.pcie: PCI host bridge to bus 0000:00
[    0.296474] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.296747] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[    0.297077] pci_bus 0000:00: root bus resource [mem 0x10000000-0x3efeffff]
[    0.297415] pci_bus 0000:00: root bus resource [mem 0x8000000000-0xffffffffff]
[    0.298571] pci 0000:00:00.0: [1b36:0008] type 00 class 0x060000
[    0.300970] pci 0000:00:01.0: [1af4:1000] type 00 class 0x020000
[    0.301438] pci 0000:00:01.0: reg 0x10: [io  0x0000-0x001f]
[    0.301719] pci 0000:00:01.0: reg 0x14: [mem 0x00000000-0x00000fff]
[    0.301973] pci 0000:00:01.0: reg 0x20: [mem 0x00000000-0x00003fff 64bit pref]
[    0.302246] pci 0000:00:01.0: reg 0x30: [mem 0x00000000-0x0007ffff pref]
[    0.303869] pci 0000:00:01.0: BAR 6: assigned [mem 0x10000000-0x1007ffff pref]
[    0.304251] pci 0000:00:01.0: BAR 4: assigned [mem 0x8000000000-0x8000003fff 64bit pref]
[    0.304633] pci 0000:00:01.0: BAR 1: assigned [mem 0x10080000-0x10080fff]
[    0.304860] pci 0000:00:01.0: BAR 0: assigned [io  0x1000-0x101f]
[    0.310497] EINJ: ACPI disabled.
[    0.338621] virtio-pci 0000:00:01.0: enabling device (0000 -> 0003)
[    0.347555] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.352400] SuperH (H)SCI(F) driver initialized
[    0.353109] msm_serial: driver initialized
[    0.353945] STM32 USART driver initialized
[    0.366170] loop: module loaded
[    0.368074] megasas: 07.725.01.00-rc1
[    0.370831] physmap-flash 0.flash: physmap platform flash device: [mem 0x00000000-0x03ffffff]
[    0.372075] 0.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
[    0.372689] Intel/Sharp Extended Query Table at 0x0031
[    0.373301] Using buffer write method
[    0.373737] physmap-flash 0.flash: physmap platform flash device: [mem 0x04000000-0x07ffffff]
[    0.374414] 0.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
[    0.374705] Intel/Sharp Extended Query Table at 0x0031
[    0.375377] Using buffer write method
[    0.375609] Concatenating MTD devices:
[    0.375874] (0): "0.flash"
[    0.375978] (1): "0.flash"
[    0.376069] into device "0.flash"
[    0.419047] tun: Universal TUN/TAP device driver, 1.6
[    0.427965] thunder_xcv, ver 1.0
[    0.428190] thunder_bgx, ver 1.0
[    0.428375] nicpf, ver 1.0
[    0.429897] hns3: Hisilicon Ethernet Network Driver for Hip08 Family - version
[    0.430186] hns3: Copyright (c) 2017 Huawei Corporation.
[    0.430567] hclge is initializing
[    0.430772] e1000: Intel(R) PRO/1000 Network Driver
[    0.430932] e1000: Copyright (c) 1999-2006 Intel Corporation.
[    0.431176] e1000e: Intel(R) PRO/1000 Network Driver
[    0.431374] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    0.431594] igb: Intel(R) Gigabit Ethernet Network Driver
[    0.431914] igb: Copyright (c) 2007-2014 Intel Corporation.
[    0.432098] igbvf: Intel(R) Gigabit Virtual Function Network Driver
[    0.432550] igbvf: Copyright (c) 2009 - 2012 Intel Corporation.
[    0.433232] sky2: driver version 1.30
[    0.435206] VFIO - User Level meta-driver version: 0.3
[    0.439561] usbcore: registered new interface driver usb-storage
[    0.445782] rtc-pl031 9010000.pl031: registered as rtc0
[    0.446339] rtc-pl031 9010000.pl031: setting system clock to 2025-04-19T02:26:28 UTC (1745029588)
[    0.448184] i2c_dev: i2c /dev entries driver
[    0.457164] sdhci: Secure Digital Host Controller Interface driver
[    0.457399] sdhci: Copyright(c) Pierre Ossman
[    0.458953] Synopsys Designware Multimedia Card Interface Driver
[    0.460266] sdhci-pltfm: SDHCI platform and OF driver helper
[    0.462918] ledtrig-cpu: registered to indicate activity on CPUs
[    0.465624] usbcore: registered new interface driver usbhid
[    0.465820] usbhid: USB HID core driver
[    0.471011] hw perfevents: enabled with armv8_pmuv3 PMU driver, 7 counters available
[    0.477959] NET: Registered PF_PACKET protocol family
[    0.478811] 9pnet: Installing 9P2000 support
[    0.479149] Key type dns_resolver registered
[    0.492406] registered taskstats version 1
[    0.493362] Loading compiled-in X.509 certificates
[    0.509294] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    0.514556] clk: Disabling unused clocks
[    0.515023] ALSA device list:
[    0.515239]   No soundcards found.
[    0.518038] uart-pl011 9000000.pl011: no DMA platform data
[    0.547146] Freeing unused kernel memory: 9152K
[    0.547998] Run /init as init process


My first AARCH64 porting!!
/bin/sh: can't access tty; job control turned off
~ # 

히히 원하는대로 출력이 잘 되는군요

간단하게 Hello world 출력하는 프로그램을 넣어볼까요?

C 파일은 단순해요

#include <stdio.h>

int main(){
    printf("Hello World in My AARCH64 Kernel~\n");
    return 0;
}

반드시 정적링크로 컴파일하세요!

aarch64-linux-gnu-gcc -static HelloWorld.c -o HelloWorld.out

rootfs에 넣어주고 다시 압축할까요?

cd busybox/rootfs
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz
cd ..
# 바이너리스 폴더 옮기시고

이제 부팅해서 실행하면

My first AARCH64 porting!!
/bin/sh: can't access tty; job control turned off
~ # ls my
HelloWorld.out
~ # cd my
/my # ./HelloWorld.out 
Hello World in My AARCH64 Kernel~
/my # 

굿~

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages