请选择 进入手机版 | 继续访问电脑版

risc-v中文社区

 找回密码
 立即注册
查看: 1111|回复: 0

移植 Kdump 至嵌入式 ARM64 环境

[复制链接]

347

主题

564

帖子

2237

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2237
发表于 2022-8-2 11:01:11 | 显示全部楼层 |阅读模式
工欲善其事,必先利其器。操作系统崩溃是高级 Linux 运维工程师很头疼的事情,但也不要害怕,前辈们已经给我们磨了好多把刀,其中有一把叫做 Kdump。目前在主流的 Linux 发行版如 Ubuntu、Centos 等已经默认安装或者仓库中含有工具包,但是经过裁剪的嵌入式 Linux 里面没有包含 Kdump。本文章使用 busybox 建立最小文件系统,讲述移植 Kdump 至嵌入式 ARM64 的环境中。
一、使用 busybox 建立最小文件系统
这个我就不讲了,度娘上一大堆文章。建立 rootfs 文件夹,将 busybox 下的 _install 内容全部拷贝至 rootfs 中。
二、编译 Kdump 工具
(1)从下面的网站下载最新的 kexec-tools 源码包。
http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz
(2)解压源码包。
tar xvpzf kexec-tools.tar.gz
(3)进入到 kexec-tools 中,并进行配置。
LDFLAGS=-static ./configure ARCH=arm64 --build=x86_64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --without-xen
这里使用静态编译。
(4)然后使用 make 进行编译。
Make
(5)将 build 目录下生成文件拷贝至 rootfs 文件夹中。
三、内核配置
(1)在 "Processor type and features.“下使能"kexec system call”。
CONFIG_KEXEC=y
(2)在 "Filesystem" -> “Pseudo filesystems.“下使能 "sysfs file system support”。
CONFIG_SYSFS=y
(3)在 "Kernel hacking.“下使能"Compile the kernel with debug info” 。
CONFIG_DEBUG_INFO=y
(4)在 "Processor type and features" 下使能 "kernel crash dumps”。
CONFIG_CRASH_DUMP=y
(5)在 "Filesystems" -> “Pseudo filesystems"下使能”/proc/vmcore support"。
CONFIG_PROC_VMCORE=y
然后重新编译内核,生成 Image。
四、建立文件系统镜像
(1)建立 IMG 文件。
dd if=/dev/zero of=rootfs.img bs=1M count=4k oflag=direct
(2)将 IMG 格式化为 ext4 格式。
mkfs.ext4 rootfs.img
(3)建立 ubuntu-mount 文件夹。
mkdir ubuntu-mount
(4)将 IMG 与文件夹进行挂载。
mount rootfs.img ubuntu-mount
(5)将 rootfs 里面的内容复制到 IMG 中。
cp -rfp rootfs/* ubuntu-mount/
(6)取消 IMG 和文件夹的挂载。
umount ubuntu-mount
(7)检查文件系统的正确性。
e2fsck -p -f rootfs.img
五、实验操作
(1)当我们做完以上的工作后,就可以通过 QEMU 启动 ARM64 的最小系统了。命令如下:
qemu-system-aarch64 -machine virt -M virt,gic_version=3 -cpu cortex-a57 -machine type=virt -nographic -smp 2 -m 1024 -kernel ./Image -hda ./rootfs.img -append “console=ttyAMA0 root=/dev/vda rw crashkernel=128M nr_cpus=2”
以下是我实验的启动流程:
root@ubuntu:/home/alvin/share/busybox_arm64# qemu-system-aarch64 -machine virt -M virt,gic_version=3 -cpu cortex-a57 -machine type=virt -nographic -smp 2 -m 1024 -kernel ./Image -hda ./rootfs.img -append “console=ttyAMA0 root=/dev/vda rw crashkernel=128M nr_cpus=2”
WARNING: Image format was not specified for ‘./rootfs.img’ and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the ‘raw’ format explicitly to remove the restrictions.
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[ 0.000000] Linux version 5.0.7 (root@ubuntu) (gcc version 7.3.0 (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04)) #12 SMP PREEMPT Sat May 11 15:14:29 PDT 2019
[ 0.000000] Machine model: linux,dummy-virt
[ 0.000000] efi: Getting EFI parameters from FDT:
[ 0.000000] efi: UEFI not found.
[ 0.000000] crashkernel reserved: 0x0000000077e00000 - 0x000000007fe00000 (128 MB)
[ 0.000000] cma: Reserved 32 MiB at 0x0000000075c00000
[ 0.000000] NUMA: No NUMA configuration found
[ 0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] NUMA: NODE_DATA [mem 0x77df4840-0x77df5fff]
[ 0.000000] Zone ranges:
[ 0.000000] DMA32 [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] Normal empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: PSCIv0.2 detected in firmware.
[ 0.000000] psci: Using standard PSCI v0.2 function IDs
[ 0.000000] psci: Trusted OS migration not required
[ 0.000000] random: get_random_bytes called from start_kernel+0xa8/0x40c with crng_init=0
[ 0.000000] percpu: Embedded 23 pages/cpu @(ptrval) s56024 r8192 d29992 u94208
[ 0.000000] Detected PIPT I-cache on CPU0
[ 0.000000] CPU features: detected: ARM erratum 832075
[ 0.000000] CPU features: detected: ARM erratum 834220
[ 0.000000] CPU features: detected: EL2 vector hardening
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 258048
[ 0.000000] Policy zone: DMA32
[ 0.000000] Kernel command line: console=ttyAMA0 root=/dev/vda rw crashkernel=128M nr_cpus=2
[ 0.000000] Memory: 845240K/1048576K available (11004K kernel code, 1604K rwdata, 5332K rodata, 1408K init, 384K bss, 170568K reserved, 32768K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
[ 0.000000] rcu: Preemptible hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=2.
[ 0.000000] 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=2
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] GICv3: Distributor has no Range Selector support
[ 0.000000] GICv3: no VLPI support, no direct LPI support
[ 0.000000] GICv3: CPU0: found redistributor 0 region 0:0x00000000080a0000
[ 0.000000] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[ 0.000174] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 4398046511096ns
[ 0.008201] Console: colour dummy device 80x25
[ 0.010926] Calibrating delay loop (skipped), value calculated using timer frequency… 125.00 BogoMIPS (lpj=250000)
[ 0.011187] pid_max: default: 32768 minimum: 301
[ 0.012558] LSM: Security Framework initializing
[ 0.014434] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
[ 0.015704] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes)
[ 0.015999] Mount-cache hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.016112] Mountpoint-cache hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.082658] ASID allocator initialised with 32768 entries
[ 0.091943] rcu: Hierarchical SRCU implementation.
[ 0.107577] EFI services will not be available.
[ 0.116690] smp: Bringing up secondary CPUs …
[ 0.158098] Detected PIPT I-cache on CPU1
[ 0.158751] GICv3: CPU1: found redistributor 1 region 0:0x00000000080c0000
[ 0.159082] CPU1: Booted secondary processor 0x0000000001 [0x411fd070]
[ 0.163232] smp: Brought up 1 node, 2 CPUs
[ 0.163311] SMP: Total of 2 processors activated.
[ 0.163389] CPU features: detected: GIC system register CPU interface
[ 0.163424] CPU features: detected: 32-bit EL0 Support
[ 0.163520] CPU features: detected: CRC32 instructions
[ 0.171461] CPU: All CPU(s) started at EL1
[ 0.171777] alternatives: patching kernel code
[ 0.200862] devtmpfs: initialized
[ 0.220424] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[ 0.220680] futex hash table entries: 512 (order: 3, 32768 bytes)
[ 0.228215] pinctrl core: initialized pinctrl subsystem
[ 0.251460] DMI not present or invalid.
[ 0.262311] NET: Registered protocol family 16
[ 0.266512] audit: initializing netlink subsys (disabled)
[ 0.269487] audit: type=2000 audit(0.208:1): state=initialized audit_enabled=0 res=1
[ 0.285140] cpuidle: using governor menu
[ 0.287626] vdso: 2 pages (1 code @ (ptrval), 1 data @ (ptrval))
[ 0.287785] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[ 0.297348] DMA: preallocated 256 KiB pool for atomic allocations
[ 0.313825] Serial: AMBA PL011 UART driver
[ 0.381830] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 39, base_baud = 0) is a PL011 rev1
[ 0.490940] printk: console [ttyAMA0] enabled
[ 0.651007] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[ 0.651932] HugeTLB registered 32.0 MiB page size, pre-allocated 0 pages
[ 0.652686] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[ 0.653521] HugeTLB registered 64.0 KiB page size, pre-allocated 0 pages
[ 0.660698] cryptd: max_cpu_qlen set to 1000
[ 0.676782] ACPI: Interpreter disabled.
[ 0.699521] vgaarb: loaded
[ 0.703209] SCSI subsystem initialized
[ 0.718287] usbcore: registered new interface driver usbfs
[ 0.720782] usbcore: registered new interface driver hub
[ 0.723444] usbcore: registered new device driver usb
[ 0.733534] pps_core: LinuxPPS API ver. 1 registered
[ 0.734813] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti giometti@linux.it
[ 0.736854] PTP clock support registered
[ 0.746659] EDAC MC: Ver: 3.0.0
[ 0.757551] Advanced Linux Sound Architecture Driver Initialized.
[ 0.776621] clocksource: Switched to clocksource arch_sys_counter
[ 0.782977] VFS: Disk quotas dquot_6.6.0
[ 0.784515] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[ 0.794319] pnp: PnP ACPI: disabled
[ 0.867760] NET: Registered protocol family 2
[ 0.878383] tcp_listen_portaddr_hash hash table entries: 512 (order: 1, 8192 bytes)
[ 0.879454] TCP established hash table entries: 8192 (order: 4, 65536 bytes)
[ 0.880970] TCP bind hash table entries: 8192 (order: 5, 131072 bytes)
[ 0.881576] TCP: Hash tables configured (established 8192 bind 8192)
[ 0.884265] UDP hash table entries: 512 (order: 2, 16384 bytes)
[ 0.885425] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
[ 0.887818] NET: Registered protocol family 1
[ 0.896387] RPC: Registered named UNIX socket transport module.
[ 0.910707] RPC: Registered udp transport module.
[ 0.911119] RPC: Registered tcp transport module.
[ 0.912991] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.923200] hw perfevents: enabled with armv8_pmuv3 PMU driver, 5 counters available
[ 0.925509] kvm [1]: HYP mode not available
[ 0.992384] Initialise system trusted keyrings
[ 0.997978] workingset: timestamp_bits=44 max_order=18 bucket_order=0
[ 1.060250] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[ 1.069144] NFS: Registering the id_resolver key type
[ 1.069994] Key type id_resolver registered
[ 1.070221] Key type id_legacy registered
[ 1.070831] nfs4filelayout_init: NFSv4 File Layout Driver Registering…
[ 1.073270] 9p: Installing v9fs 9p2000 file system support
[ 1.129431] Key type asymmetric registered
[ 1.129886] Asymmetric key parser ‘x509’ registered
[ 1.130961] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 245)
[ 1.131756] io scheduler mq-deadline registered
[ 1.134068] io scheduler kyber registered
[ 1.193670] pl061_gpio 9030000.pl061: PL061 GPIO chip @0x0000000009030000 registered
[ 1.206992] pci-host-generic 4010000000.pcie: host bridge /pcie@10000000 ranges:
[ 1.208269] pci-host-generic 4010000000.pcie: IO 0x3eff0000…0x3effffff -> 0x00000000
[ 1.210415] pci-host-generic 4010000000.pcie: MEM 0x10000000…0x3efeffff -> 0x10000000
[ 1.211020] pci-host-generic 4010000000.pcie: MEM 0x8000000000…0xffffffffff -> 0x8000000000
[ 1.213354] pci-host-generic 4010000000.pcie: ECAM at [mem 0x4010000000-0x401fffffff] for [bus 00-ff]
[ 1.216257] pci-host-generic 4010000000.pcie: PCI host bridge to bus 0000:00
[ 1.218452] pci_bus 0000:00: root bus resource [bus 00-ff]
[ 1.219166] pci_bus 0000:00: root bus resource [io 0x0000-0xffff]
[ 1.219642] pci_bus 0000:00: root bus resource [mem 0x10000000-0x3efeffff]
[ 1.220051] pci_bus 0000:00: root bus resource [mem 0x8000000000-0xffffffffff]
[ 1.236339] pci 0000:00:01.0: BAR 6: assigned [mem 0x10000000-0x1003ffff pref]
[ 1.238306] pci 0000:00:01.0: BAR 4: assigned [mem 0x8000000000-0x8000003fff 64bit pref]
[ 1.239271] pci 0000:00:02.0: BAR 4: assigned [mem 0x8000004000-0x8000007fff 64bit pref]
[ 1.240016] pci 0000:00:02.0: BAR 0: assigned [io 0x1000-0x107f]
[ 1.241310] pci 0000:00:01.0: BAR 0: assigned [io 0x1080-0x109f]
[ 1.263130] EINJ: ACPI disabled.
[ 1.320069] virtio-pci 0000:00:01.0: enabling device (0000 -> 0003)
[ 1.325531] virtio-pci 0000:00:02.0: enabling device (0000 -> 0003)
[ 1.372240] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[ 1.391891] SuperH (H)SCI(F) driver initialized
[ 1.396244] msm_serial: driver initialized
[ 1.407937] cacheinfo: Unable to detect cache hierarchy for CPU 0
[ 1.466535] loop: module loaded
[ 1.478452] virtio_blk virtio1: [vda] 8388608 512-byte logical blocks (4.29 GB/4.00 GiB)
[ 1.543860] libphy: Fixed MDIO Bus: probed
[ 1.552503] tun: Universal TUN/TAP device driver, 1.6
[ 1.570756] thunder_xcv, ver 1.0
[ 1.571914] thunder_bgx, ver 1.0
[ 1.573689] nicpf, ver 1.0
[ 1.579220] hclge is initializing
[ 1.581401] hns3: Hisilicon Ethernet Network Driver for Hip08 Family - version
[ 1.582293] hns3: Copyright © 2017 Huawei Corporation.
[ 1.583795] e1000e: Intel® PRO/1000 Network Driver - 3.2.6-k
[ 1.585393] e1000e: Copyright© 1999 - 2015 Intel Corporation.
[ 1.587092] igb: Intel® Gigabit Ethernet Network Driver - version 5.4.0-k
[ 1.589120] igb: Copyright © 2007-2014 Intel Corporation.
[ 1.590132] igbvf: Intel® Gigabit Virtual Function Network Driver - version 2.4.0-k
[ 1.591243] igbvf: Copyright © 2009 - 2012 Intel Corporation.
[ 1.596258] sky2: driver version 1.30
[ 1.601774] VFIO - User Level meta-driver version: 0.3
[ 1.617845] ehci_hcd: USB 2.0 ‘Enhanced’ Host Controller (EHCI) Driver
[ 1.619470] ehci-pci: EHCI PCI platform driver
[ 1.621804] ehci-platform: EHCI generic platform driver
[ 1.623722] ehci-orion: EHCI orion driver
[ 1.625425] ehci-exynos: EHCI EXYNOS driver
[ 1.627358] ohci_hcd: USB 1.1 ‘Open’ Host Controller (OHCI) Driver
[ 1.629208] ohci-pci: OHCI PCI platform driver
[ 1.630863] ohci-platform: OHCI generic platform driver
[ 1.634266] ohci-exynos: OHCI EXYNOS driver
[ 1.640986] usbcore: registered new interface driver usb-storage
[ 1.670598] rtc-pl031 9010000.pl031: registered as rtc0
[ 1.677241] i2c /dev entries driver
[ 1.715681] sdhci: Secure Digital Host Controller Interface driver
[ 1.718305] sdhci: Copyright© Pierre Ossman
[ 1.723334] Synopsys Designware Multimedia Card Interface Driver
[ 1.731635] sdhci-pltfm: SDHCI platform and OF driver helper
[ 1.742333] ledtrig-cpu: registered to indicate activity on CPUs
[ 1.767205] usbcore: registered new interface driver usbhid
[ 1.768038] usbhid: USB HID core driver
[ 1.801497] NET: Registered protocol family 17
[ 1.805294] 9pnet: Installing 9P2000 support
[ 1.806524] Key type dns_resolver registered
[ 1.812974] registered taskstats version 1
[ 1.813598] Loading compiled-in X.509 certificates
[ 1.827961] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[ 1.834872] rtc-pl031 9010000.pl031: setting system clock to 2019-05-14T12:07:42 UTC (1557835662)
[ 1.846911] ALSA device list:
[ 1.847890] No soundcards found.
[ 1.857713] uart-pl011 9000000.pl011: no DMA platform data
[ 1.916602] EXT4-fs (vda): mounted filesystem with ordered data mode. Opts: (null)
[ 1.918270] VFS: Mounted root (ext4 filesystem) on device 254:0.
[ 1.923838] devtmpfs: mounted
[ 2.225180] Freeing unused kernel memory: 1408K
[ 2.227492] Run /sbin/init as init process
Please press Enter to activate this console.
Processing /etc/profile… Done
————————————————
版权声明:本文为 CSDN 博主「one_bits」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lsy673908720/article/details/90215501

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



Archiver|手机版|小黑屋|risc-v中文社区

GMT+8, 2024-3-29 00:06 , Processed in 0.016439 second(s), 17 queries .

risc-v中文社区论坛 官方网站

Copyright © 2018-2021, risc-v open source

快速回复 返回顶部 返回列表