dts
[root@centos7 images]# qemu-system-riscv64 -machine virt -machine dumpdtb=riscv64-virt.dtb -bios fw_jump.elf [root@centos7 images]# dtc -I dtb -O dts -o riscv64-virt.dts riscv64-virt.dtb -bash: dtc: command not found [root@centos7 images]# yum install dtc
# To convert dts file into dtb <kernel-source>/scripts/dtc/dtc -I dts -O dtb <dts_file> -o <dtb_file> # To convert dtb to dts <kernel-source>/scripts/dtc/dtc -I dtb -O dts <dtb_file> -o <dts_file> # Both of above commands are using dtc built with linux kernel source. # However you can also use dtc binary comes with ubuntu packages. For this you # need to install following package: sudo apt-get install -y device-tree-compiler # Ubuntu device-tree-compiler package comes with another utility known as fdtdump. # fdtdump can also be used to convert dtb file into dts. fdtdump <dtb_file> > <dts_dump>
fdtdump riscv64-virt.dtb **** fdtdump is a low-level debugging tool, not meant for general use. **** If you want to decompile a dtb, you probably want **** dtc -I dtb -O dts <filename> /dts-v1/; // magic: 0xd00dfeed // totalsize: 0xd1a (3354) // off_dt_struct: 0x38 // off_dt_strings: 0xbc4 // off_mem_rsvmap: 0x28 // version: 17 // last_comp_version: 2 // boot_cpuid_phys: 0x0 // size_dt_strings: 0x156 // size_dt_struct: 0xb8c / { #address-cells = <0x00000002>; #size-cells = <0x00000002>; compatible = "riscv-virtio"; model = "riscv-virtio,qemu"; flash@20000000 { bank-width = <0x00000004>; reg = <0x00000000 0x20000000 0x00000000 0x02000000 0x00000000 0x22000000 0x00000000 0x02000000>; compatible = "cfi-flash"; }; chosen { bootargs = [00]; stdout-path = "/uart@10000000"; }; uart@10000000 { interrupts = <0x0000000a>; interrupt-parent = <0x00000003>; clock-frequency = <0x00384000>; reg = <0x00000000 0x10000000 0x00000000 0x00000100>; compatible = "ns16550a"; }; test@100000 { reg = <0x00000000 0x00100000 0x00000000 0x00001000>; compatible = "sifive,test1", "sifive,test0"; };
[root@centos7 images]# cat riscv64-virt.dts /dts-v1/; / { #address-cells = <0x2>; #size-cells = <0x2>; compatible = "riscv-virtio"; model = "riscv-virtio,qemu"; flash@20000000 { bank-width = <0x4>; reg = <0x0 0x20000000 0x0 0x2000000 0x0 0x22000000 0x0 0x2000000>; compatible = "cfi-flash"; }; chosen { bootargs = [00]; stdout-path = "/uart@10000000"; }; uart@10000000 { interrupts = <0xa>; interrupt-parent = <0x3>; clock-frequency = <0x384000>; reg = <0x0 0x10000000 0x0 0x100>; compatible = "ns16550a"; }; test@100000 { reg = <0x0 0x100000 0x0 0x1000>; compatible = "sifive,test1", "sifive,test0"; }; virtio_mmio@10008000 { interrupts = <0x8>; interrupt-parent = <0x3>; reg = <0x0 0x10008000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10007000 { interrupts = <0x7>; interrupt-parent = <0x3>; reg = <0x0 0x10007000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10006000 { interrupts = <0x6>; interrupt-parent = <0x3>; reg = <0x0 0x10006000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10005000 { interrupts = <0x5>; interrupt-parent = <0x3>; reg = <0x0 0x10005000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10004000 { interrupts = <0x4>; interrupt-parent = <0x3>; reg = <0x0 0x10004000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10003000 { interrupts = <0x3>; interrupt-parent = <0x3>; reg = <0x0 0x10003000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10002000 { interrupts = <0x2>; interrupt-parent = <0x3>; reg = <0x0 0x10002000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10001000 { interrupts = <0x1>; interrupt-parent = <0x3>; reg = <0x0 0x10001000 0x0 0x1000>; compatible = "virtio,mmio"; }; cpus { #address-cells = <0x1>; #size-cells = <0x0>; timebase-frequency = <0x989680>; cpu-map { cluster0 { core0 { cpu = <0x1>; }; }; }; cpu@0 { phandle = <0x1>; device_type = "cpu"; reg = <0x0>; status = "okay"; compatible = "riscv"; riscv,isa = "rv64imafdcsu"; mmu-type = "riscv,sv48"; interrupt-controller { #interrupt-cells = <0x1>; interrupt-controller; compatible = "riscv,cpu-intc"; phandle = <0x2>; }; }; }; memory@80000000 { device_type = "memory"; reg = <0x0 0x80000000 0x0 0x8000000>; }; soc { #address-cells = <0x2>; #size-cells = <0x2>; compatible = "simple-bus"; ranges; pci@30000000 { interrupt-map-mask = <0x1800 0x0 0x0 0x7>; interrupt-map = <0x0 0x0 0x0 0x1 0x3 0x20 0x0 0x0 0x0 0x2 0x3 0x21 0x0 0x0 0x0 0x3 0x3 0x22 0x0 0x0 0x0 0x4 0x3 0x23 0x800 0x0 0x0 0x1 0x3 0x21 0x800 0x0 0x0 0x2 0x3 0x22 0x800 0x0 0x0 0x3 0x3 0x23 0x800 0x0 0x0 0x4 0x3 0x20 0x1000 0x0 0x0 0x1 0x3 0x22 0x1000 0x0 0x0 0x2 0x3 0x23 0x1000 0x0 0x0 0x3 0x3 0x20 0x1000 0x0 0x0 0x4 0x3 0x21 0x1800 0x0 0x0 0x1 0x3 0x23 0x1800 0x0 0x0 0x2 0x3 0x20 0x1800 0x0 0x0 0x3 0x3 0x21 0x1800 0x0 0x0 0x4 0x3 0x22>; ranges = <0x1000000 0x0 0x0 0x0 0x3000000 0x0 0x10000 0x2000000 0x0 0x40000000 0x0 0x40000000 0x0 0x40000000>; reg = <0x0 0x30000000 0x0 0x10000000>; dma-coherent; bus-range = <0x0 0xff>; linux,pci-domain = <0x0>; device_type = "pci"; compatible = "pci-host-ecam-generic"; #size-cells = <0x2>; #interrupt-cells = <0x1>; #address-cells = <0x3>; }; interrupt-controller@c000000 { phandle = <0x3>; riscv,ndev = <0x35>; reg = <0x0 0xc000000 0x0 0x4000000>; interrupts-extended = <0x2 0xb 0x2 0x9>; interrupt-controller; compatible = "riscv,plic0"; #interrupt-cells = <0x1>; #address-cells = <0x0>; }; clint@2000000 { interrupts-extended = <0x2 0x3 0x2 0x7>; reg = <0x0 0x2000000 0x0 0x10000>; compatible = "riscv,clint0"; }; }; };
dtb信息转化为device_node结构
http://sourcelink.top/2019/09/10/dts-unflatten_device_tree/
[root@centos7 linux-5.14.g]# [root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b unflatten_dt_node Function "unflatten_dt_node" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (unflatten_dt_node) pending. (gdb) b unflatten_device_tree Breakpoint 2 at 0xffffffff80c2cb42: unflatten_device_tree. (2 locations) (gdb) c Continuing. Breakpoint 2, unflatten_device_tree () at drivers/of/fdt.c:1236 1236 __unflatten_device_tree(initial_boot_params, NULL, &of_root, (gdb) bt #0 unflatten_device_tree () at drivers/of/fdt.c:1236 #1 0xffffffff80c03188 in setup_arch (cmdline_p=0xffffffff81803fa0) at arch/riscv/kernel/setup.c:280 #2 0xffffffff80c0082e in start_kernel () at init/main.c:939 #3 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) list 1231 * pointers of the nodes so the normal device-tree walking functions 1232 * can be used. 1233 */ 1234 void __init unflatten_device_tree(void) 1235 { 1236 __unflatten_device_tree(initial_boot_params, NULL, &of_root, 1237 early_init_dt_alloc_memory_arch, false); 1238 1239 /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ 1240 of_alias_scan(early_init_dt_alloc_memory_arch); (gdb) b __unflatten_device_tree Breakpoint 3 at 0xffffffff809457ec: __unflatten_device_tree. (2 locations) (gdb) c Continuing. Breakpoint 3, 0xffffffff809457ec in __unflatten_device_tree () at drivers/of/fdt.c:129 129 continue; (gdb) bt #0 0xffffffff809457ec in __unflatten_device_tree () at drivers/of/fdt.c:129 #1 0xffffffff80c2cb6e in unflatten_device_tree () at drivers/of/fdt.c:1236 #2 0xffffffff80c03188 in setup_arch (cmdline_p=0xffffffff81803fa0) at arch/riscv/kernel/setup.c:280 #3 0xffffffff80c0082e in start_kernel () at init/main.c:939 #4 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) list 124 u32 sz; 125 126 val = fdt_getprop_by_offset(blob, cur, &pname, &sz); 127 if (!val) { 128 pr_warn("Cannot locate property at 0x%x ", cur); 129 continue; 130 } 131 132 if (!pname) { 133 pr_warn("Cannot find property name at 0x%x ", cur); (gdb) s Breakpoint 3, __unflatten_device_tree (blob=0xffffffe002000000, dad=dad@entry=0x0, mynodes=0xffffffff81a27838 <of_root>, dt_alloc=dt_alloc@entry=0xffffffff80c2b9ce <early_init_dt_alloc_memory_arch>, detached=detached@entry=false) at drivers/of/fdt.c:378 378 if (mynodes) (gdb) n 379 *mynodes = NULL; (gdb) list 374 int size; 375 void *mem; 376 int ret; 377 378 if (mynodes) 379 *mynodes = NULL; 380 381 pr_debug(" -> unflatten_device_tree() "); 382 383 if (!blob) { (gdb) n 383 if (!blob) { (gdb) n 393 if (fdt_check_header(blob)) { (gdb) n 399 size = unflatten_dt_nodes(blob, NULL, dad, NULL); (gdb) p *blob Attempt to dereference a generic pointer. (gdb) p blob $1 = (const void *) 0xffffffe002000000 (gdb) n 400 if (size <= 0) (gdb) c Continuing.
uboot
[root@centos7 riscv_debug]# git clone https://gitlab.denx.de/u-boot/u-boot.git --depth 1 Cloning into 'u-boot'... remote: Enumerating objects: 19347, done. remote: Counting objects: 100% (19347/19347), done. remote: Compressing objects: 100% (17268/17268), done. remote: Total 19347 (delta 3213), reused 6977 (delta 1739), pack-reused 0 Receiving objects: 100% (19347/19347), 25.13 MiB | 7.20 MiB/s, done. Resolving deltas: 100% (3213/3213), done. [root@centos7 riscv_debug]# make qemu-riscv64_smode_defconfig CROSS_COMPILE=iscv64-unknown-linux-gnu- make: *** No rule to make target 'qemu-riscv64_smode_defconfig'. Stop. [root@centos7 riscv_debug]#
[root@centos7 riscv_debug]# cd u-boot/
make CROSS_COMPILE=riscv64-unknown-linux-gnu- -j128
make[1]: *** [scripts/Makefile.host:104: tools/fit_info] Error 1
tools/libtools//ecdsalib//ecdsaecdsa-/libcrypto.oecdsa:- libcrypto.oIn: functionIn `functionprepare_ctx '`:prepare_ctx
'ecdsa:-
libcrypto.cecdsa:-(libcrypto.c.:text(+.0x98text)+:0x98 )undefined: referenceundefined toreference `toOPENSSL_init_ssl '`
OPENSSL_init_sslecdsa'-
libcrypto.cecdsa:-(libcrypto.c.:text(+.0x130text)+:0x130 )undefined: referenceundefined toreference `toEC_GROUP_order_bits '`
EC_GROUP_order_bitstools'/
libtools//ecdsalib//ecdsaecdsa-/libcrypto.oecdsa:- libcrypto.oIn: functionIn `functionecdsa_check_signature.isra.3 '`:
ecdsa_check_signature.isra.3ecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x300.)text:+ 0x300undefined) :reference undefinedto reference` ECDSA_SIG_set0to'
`toolsECDSA_SIG_set0/'lib
/toolsecdsa//libecdsa/-ecdsalibcrypto.o/:ecdsa -Inlibcrypto.o :function In` ecdsa_signfunction' :`
ecdsa_signecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x3ec.)text:+ 0x3ecundefined) :reference undefinedto reference` ECDSA_SIG_get0to'
`ecdsaECDSA_SIG_get0-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x3fc.)text:+ 0x3fcundefined) :reference undefinedto reference` BN_bn2binpadto'
`ecdsaBN_bn2binpad-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x40c.)text:+ 0x40cundefined) :reference undefinedto reference` BN_bn2binpadto'
`toolsBN_bn2binpad/'lib
/toolsecdsa//libecdsa/-ecdsalibcrypto.o/:ecdsa -Inlibcrypto.o :function In` ecdsa_add_verify_datafunction' :`
ecdsa_add_verify_dataecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x5a8.)text:+ 0x5a8undefined) :reference undefinedto reference` EC_GROUP_order_bitsto'
`ecdsaEC_GROUP_order_bits-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x5ec.)text:+ 0x5ecundefined) :reference undefinedto reference` toEC_POINT_get_affine_coordinates '`
toolsEC_POINT_get_affine_coordinates/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_signfunction' :`
rsa_signrsa'-:sign.c
:rsa(-.sign.ctext:+(0x4e8.)text:+ 0x4e8undefined) :reference undefinedto reference` OPENSSL_init_sslto'
`rsaOPENSSL_init_ssl-'sign.c
:rsa(-.sign.ctext:+(0x790.)text:+ 0x790undefined) :reference undefinedto reference` EVP_MD_CTX_resetto'
`toolsEVP_MD_CTX_reset/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_get_paramsfunction' :`
rsa_get_paramsrsa'-:sign.c
:rsa(-.sign.ctext:+(0x874.)text:+ 0x874undefined) :reference undefinedto reference` RSA_get0_keyto'
`rsaRSA_get0_key-'sign.c
:rsa(-.sign.ctext:+(0x8bc.)text:+ 0x8bcundefined) :reference undefinedto reference` RSA_get0_keyto'
`toolsRSA_get0_key/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_add_verify_datafunction' :`
rsa_add_verify_datarsa'-:sign.c
:rsa(-.sign.ctext:+(0xc60.)text:+ 0xc60undefined) :reference undefinedto reference` EVP_PKEY_get0_RSAto'
`EVP_PKEY_get0_RSA'
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:104: tools/mkimage] Error 1
make[1]: *** [scripts/Makefile.host:104: tools/fit_check_sign] Error 1
make: *** [Makefile:1801: tools] Error 2
yum -y install openssl
UBOOT_MAKE_FLAGS += HOSTLOADLIBES_mkimage="-pthread -lcrypto -lssl"
You may also use the following patch, submitted to u-boot: From a48643614cba7703f1ebbf92ecb5be5d73389f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= <bam@icognize.de> Date: Tue, 3 Dec 2019 09:52:34 +0100 Subject: [PATCH] Add -pthread to HOSTLOADLIBES_mkimage On some unix distributions, pthread is not automatically linked. This results in unresolved symbols when e.g. building u-boot via OpenWRT (using LibreSSL) in dumpimage and other host tools when i.E. CONFIG_FIT_SIGNATURE is set. Using -pthread to link pthread should be portable across all distributions and OS X. CHANGELOG: * Added -pthread to HOSTLOADLIBES_mkimage --- tools/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/Makefile b/tools/Makefile index 24581adccd..2f122bed8e 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -150,7 +150,8 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CON HOSTCFLAGS_kwbimage.o += $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "") HOSTLOADLIBES_mkimage += - $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") + $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") + -pthread # OS X deprecate openssl in favour of CommonCrypto, supress deprecation # warnings on those systems -- 2.20.1
Booting with qemu
Prerequisites:
- apt install qemu-system-misc opensbi u-boot-qemu qemu-utils
Hirsute's version of u-boot-qemu is required at the moment to boot hirsute images.
After installing the above prerequisites, one can use any of the above images to boot virtual machine.
First unpack the image
xz -dk focal-preinstalled-server-riscv64.img.xz
Optionally, if you want larger disk, you can expand the disk (filesystem will be automatically resized too).
qemu-img resize -f raw focal-preinstalled-server-riscv64.img +5G
Next use OpenSBI bootloader & u-boot-qemu to boot the virtual machine
Working example with all the options is:
qemu-system-riscv64
-machine virt -nographic -m 2048 -smp 4
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0
-drive file=focal-preinstalled-server-riscv64.img,format=raw,if=virtio
The important options to use are:
-
Machine type virt aka -machine virt
-
Bios is OpenSBI -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
-
"kernel" is qemu smode uboot -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf
One can use pass through networking, adjust memory (-m) & cpu counts (-smp) as needed.
Switch to the serial console, wait for cloud-init to complete, then login using ubuntu:ubuntu. See the cloud-init section below to further customise the first boot behaviour with cloud-init.
_start_kernel () at arch/riscv/kernel/head.S:327
[root@centos7 linux-5.14]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote :1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b sbi_console_write Breakpoint 1 at 0xffffffff80193634: file drivers/tty/serial/earlycon-riscv-sbi.c, line 24. (gdb) b early_sbi_setup Breakpoint 2 at 0xffffffff8021407c: file drivers/tty/serial/earlycon-riscv-sbi.c, line 31. (gdb) c Continuing. Breakpoint 2, early_sbi_setup (device=0xffffffff80a91658 <early_console_dev>, opt=0x0) at drivers/tty/serial/earlycon-riscv-sbi.c:31 31 device->con->write = sbi_console_write; (gdb) bt #0 early_sbi_setup (device=0xffffffff80a91658 <early_console_dev>, opt=0x0) at drivers/tty/serial/earlycon-riscv-sbi.c:31 #1 0xffffffff80213c08 in register_earlycon (match=<optimized out>, buf=0x0) at drivers/tty/serial/earlycon.c:147 #2 setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:205 #3 0xffffffff80213cc4 in param_setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:237 #4 0xffffffff802001c4 in do_early_param (param=0xffffffff80400218 <tmp_cmdline> "earlycon", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", unused=<optimized out>, arg=<optimized out>) at init/main.c:735 #5 0xffffffff8002867c in parse_one (handle_unknown=0xffffffff80200124 <do_early_param>, arg=0x0, max_level=<optimized out>, min_level=<optimized out>, num_params=0, params=0x0, doing=0xffffffff80648e48 "early options", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", param=0xffffffff80400218 <tmp_cmdline> "earlycon") at kernel/params.c:153 #6 parse_args (doing=doing@entry=0xffffffff80648e48 "early options", args=0xffffffff80400224 <tmp_cmdline+12> "", args@entry=0xffffffff80400218 <tmp_cmdline> "earlycon", params=params@entry=0x0, num=num@entry=0, min_level=min_level@entry=0, max_level=max_level@entry=0, arg=arg@entry=0x0, unknown=unknown@entry=0xffffffff80200124 <do_early_param>) at kernel/params.c:188 #7 0xffffffff80200940 in parse_early_options (cmdline=cmdline@entry=0xffffffff80400218 <tmp_cmdline> "earlycon") at init/main.c:745 #8 0xffffffff802009a0 in parse_early_param () at init/main.c:760 #9 0xffffffff80202400 in setup_arch (cmdline_p=cmdline_p@entry=0xffffffff80a03f98) at arch/riscv/kernel/setup.c:272 #10 0xffffffff80200b00 in start_kernel () at init/main.c:939 #11 0xffffffff8000016c in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 1, sbi_console_write (con=0xffffffff80a91860 <early_con>, s=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021 ", n=150) at drivers/tty/serial/earlycon-riscv-sbi.c:24 24 for ( i= 0; i < n; ++i) (gdb) bt #0 sbi_console_write (con=0xffffffff80a91860 <early_con>, s=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021 ", n=150) at drivers/tty/serial/earlycon-riscv-sbi.c:24 #1 0xffffffff80042094 in call_console_drivers (ext_text=0xffffffff80aaaec8 <ext_text> "", text=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021 ", len=<optimized out>, ext_len=<optimized out>) at kernel/printk/printk.c:1938 #2 console_unlock () at kernel/printk/printk.c:2643 #3 0xffffffff80042af4 in register_console (newcon=0xffffffff80a91860 <early_con>) at kernel/printk/printk.c:2981 #4 0xffffffff80213c30 in register_earlycon (match=<optimized out>, buf=0x0) at drivers/tty/serial/earlycon.c:154 #5 setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:205 #6 0xffffffff80213cc4 in param_setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:237 #7 0xffffffff802001c4 in do_early_param (param=0xffffffff80400218 <tmp_cmdline> "earlycon", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", unused=<optimized out>, arg=<optimized out>) at init/main.c:735 #8 0xffffffff8002867c in parse_one (handle_unknown=0xffffffff80200124 <do_early_param>, arg=0x0, max_level=<optimized out>, min_level=<optimized out>, num_params=0, params=0x0, doing=0xffffffff80648e48 "early options", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", param=0xffffffff80400218 <tmp_cmdline> "earlycon") at kernel/params.c:153 #9 parse_args (doing=doing@entry=0xffffffff80648e48 "early options", args=0xffffffff80400224 <tmp_cmdline+12> "", args@entry=0xffffffff80400218 <tmp_cmdline> "earlycon", params=params@entry=0x0, num=num@entry=0, min_level=min_level@entry=0, max_level=max_level@entry=0, arg=arg@entry=0x0, unknown=unknown@entry=0xffffffff80200124 <do_early_param>) at kernel/params.c:188 #10 0xffffffff80200940 in parse_early_options (cmdline=cmdline@entry=0xffffffff80400218 <tmp_cmdline> "earlycon") at init/main.c:745 #11 0xffffffff802009a0 in parse_early_param () at init/main.c:760 #12 0xffffffff80202400 in setup_arch (cmdline_p=cmdline_p@entry=0xffffffff80a03f98)
Boot HART ID : 0 Boot HART Domain : root Boot HART ISA : rv64imafdcsu Boot HART Features : scounteren,mcounteren Boot HART PMP Count : 16 Boot HART PMP Granularity : 4 Boot HART PMP Address Bits: 54 Boot HART MHPM Count : 0 Boot HART MHPM Count : 0 Boot HART MIDELEG : 0x0000000000000222 Boot HART MEDELEG : 0x000000000000b109 [ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021
riscv Kernel panic - not syncing: No working init found
[root@centos7 images]# file rootfs.ext2 rootfs.ext2: Linux rev 1.0 ext2 filesystem data, UUID=f782840d-9251-495d-b646-32800af3ca12 (large files) [root@centos7 images]# ls /data data/ data1/ data2/ data3/ [root@centos7 images]# ls /data3/ boot lost+found [root@centos7 images]# mkdir /data4 [root@centos7 images]# mount rootfs.ext2 /data4 [root@centos7 images]# ls /data4/ bin dev etc lib lib64 linuxrc lost+found media mnt opt proc root run sbin sys tmp usr var [root@centos7 images]# ls /data4/bin/ arch chgrp df fdflush kill lsattr mt pipe_progress run-parts stty uname ash chmod dmesg fgrep link mkdir mv printenv sed su usleep base32 chown dnsdomainname getopt linux32 mknod netstat ps setarch sync vi base64 cp dumpkmap grep linux64 mktemp nice pwd setpriv tar watch busybox cpio echo gunzip ln more nuke resume setserial touch zcat cat date egrep gzip login mount pidof rm sh true chattr dd false hostname ls mountpoint ping rmdir sleep umount [root@centos7 images]#
[root@centos7 linux-5.14.g]# gdb vmlinux GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "aarch64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /root/riscv_debug/linux-5.14.g/vmlinux...Dwarf Error: wrong version in compilation unit header (is 5, should be 2, 3, or 4) [in module /root/riscv_debug/linux-5.14.g/vmlinux] (no debugging symbols found)...done. (gdb) target remote:1234 Remote debugging using :1234 warning: Architecture rejected target-supplied description 0x0000000000001000 in ?? () (gdb) b try_to_run_init_process Breakpoint 1 at 0xffffffff8016276e (gdb) b print_trace_address Breakpoint 2 at 0xffffffff80162984 (gdb) c Continuing. Breakpoint 1, 0xffffffff8016276e in try_to_run_init_process () (gdb) bt #0 0xffffffff8016276e in try_to_run_init_process () #1 0x000000000000003d in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) info f Stack level 0, frame at 0xffffffd00400bec0: pc = 0xffffffff8016276e in try_to_run_init_process; saved pc 0x3d called by frame at 0xffffffd00400bec0 Arglist at unknown address. Locals at unknown address, Previous frame's sp is 0xffffffd00400bec0 Could not fetch register "v31"; remote failure reply 'E14' (gdb) info registers x0 0x0 0 x1 0xffffffff8016517a -2146020998 x2 0xffffffd00400bec0 -206091272512 x3 0xffffffff80aa1b80 -2136335488 x4 0xffffffe000ef0000 -137423290368 x5 0x40 64 x6 0x0 0 x7 0xd 13 x8 0xffffffd00400bee0 -206091272480 x9 0xffffffff80aa2028 -2136334296 x10 0xffffffff806520b8 -2140856136 x11 0x13d 317 x12 0xffffffe000e3db60 -137424020640 x13 0xffffffe03eff0060 -136382054304 x14 0x13c 316 x15 0x2 2 x16 0xffffffe000e3daf0 -137424020752 x17 0x9 9 x18 0x0 0 x19 0x0 0 x20 0x0 0 x21 0x0 0 ---Type <return> to continue, or q <return> to quit--- x22 0x0 0 x23 0x0 0 x24 0x0 0 x25 0x0 0 x26 0x0 0 x27 0x0 0 x28 0xffffffff8061fde8 -2141061656 x29 0x22 34 x30 0x3d 61 sp 0x0 0x0 pc 0xffffffff8016276e 0xffffffff8016276e <try_to_run_init_process> cpsr 0x0 0 fpsr 0x0 0 fpcr 0x0 0 (gdb) (gdb) (gdb) c Continuing. Breakpoint 1, 0xffffffff8016276e in try_to_run_init_process () (gdb) bt #0 0xffffffff8016276e in try_to_run_init_process () #1 0x000000000000003d in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) c
gdb 错了[root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinuxGNU gdb (GDB) 1Copyright (C) 2021 Free Software Foundation, InLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) b try_to_run_init_process Breakpoint 1 at 0xffffffff8016276e: file init/main.c, line 1437. (gdb) b print_trace_address Breakpoint 2 at 0xffffffff80162984: file arch/riscv/kernel/stacktrace.c, line 104. (gdb) c The program is not being run. (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b try_to_run_init_process Note: breakpoint 1 also set at pc 0xffffffff8016276e. Breakpoint 3 at 0xffffffff8016276e: file init/main.c, line 1437. (gdb) b print_trace_address Note: breakpoint 2 also set at pc 0xffffffff80162984. Breakpoint 4 at 0xffffffff80162984: file arch/riscv/kernel/stacktrace.c, line 104. (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520b8 "/sbin/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) bt #0 try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520b8 "/sbin/init") at init/main.c:1437 #1 0xffffffff8016517a in kernel_init (unused=<optimized out>) at init/main.c:1554 #2 0xffffffff8000299c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) p 0xffffffff806520b8 $1 = 18446744071568695480 (gdb) info registers ra 0xffffffff8016517a 0xffffffff8016517a <kernel_init+200> sp 0xffffffd00400bec0 0xffffffd00400bec0 gp 0xffffffff80aa1b80 0xffffffff80aa1b80 tp 0xffffffe000ef0000 0xffffffe000ef0000 t0 0x40 64 t1 0x0 0 t2 0xd 13 fp 0xffffffd00400bee0 0xffffffd00400bee0 s1 0xffffffff80aa2028 -2136334296 a0 0xffffffff806520b8 -2140856136 a1 0x13d 317 a2 0xffffffe000e3db60 -137424020640 a3 0xffffffe03eff0060 -136382054304 a4 0x13c 316 a5 0x2 2 a6 0xffffffe000e3daf0 -137424020752 a7 0x9 9 s2 0x0 0 s3 0x0 0 s4 0x0 0 s5 0x0 0 s6 0x0 0 --Type <RET> for more, q to quit, c to continue without paging-- s7 0x0 0 s8 0x0 0 s9 0x0 0 s10 0x0 0 s11 0x0 0 t3 0xffffffff8061fde8 -2141061656 t4 0x22 34 t5 0x3d 61 t6 0x0 0 pc 0xffffffff8016276e 0xffffffff8016276e <try_to_run_init_process> (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520c8 "/etc/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520d8 "/bin/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520e8 "/bin/sh") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 2, print_trace_address (arg=0xffffffff80663448, pc=18446744071563520692) at arch/riscv/kernel/stacktrace.c:104 104 { (gdb) bt #0 print_trace_address (arg=0xffffffff80663448, pc=18446744071563520692) at arch/riscv/kernel/stacktrace.c:104 #1 0xffffffff80162a30 in walk_stackframe (task=task@entry=0x0, regs=regs@entry=0x0, fn=fn@entry=0xffffffff80162984 <print_trace_address>, arg=arg@entry=0xffffffff80663448) at arch/riscv/kernel/stacktrace.c:46 #2 0xffffffff80162ab4 in dump_backtrace (regs=regs@entry=0x0, task=task@entry=0x0, loglvl=loglvl@entry=0xffffffff80663448 "") at arch/riscv/kernel/stacktrace.c:114 #3 0xffffffff80162ae4 in show_stack (task=task@entry=0x0, sp=sp@entry=0x0, loglvl=loglvl@entry=0xffffffff80663448 "") at arch/riscv/kernel/stacktrace.c:120 #4 0xffffffff80164f04 in __dump_stack (log_lvl=0xffffffff80663448 "") at lib/dump_stack.c:88 #5 dump_stack_lvl (log_lvl=0xffffffff80663448 "") at lib/dump_stack.c:105 #6 dump_stack () at lib/dump_stack.c:112 #7 0xffffffff80162c1e in panic ( fmt=fmt@entry=0xffffffff806520f0 "No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.") at kernel/panic.c:232 #8 0xffffffff801651b2 in kernel_init (unused=<optimized out>) at init/main.c:1560 #9 0xffffffff8000299c in handle_exception () at arch/riscv/kernel/entry.S:232 ----调用
handle_syscall_trace_exit
Backtrace stopped: frame did not save the PC (gdb) n 105 const char *loglvl = arg; (gdb) p *arg Attempt to dereference a generic pointer. (gdb) p *loglvl value has been optimized out (gdb) n 106 pr_cont("yuncong************* %s[<%px>] %pS ", loglvl, (void *) pc, (void *) pc); (gdb) n 107 print_ip_sym(loglvl, pc); (gdb) p loglvl $2 = 0xffffffff80663448 "" (gdb) p *loglvl $3 = 0 '