我正在尝试构建一个 tftp 可以工作的最小内核。
我使用 busybox 作为 initramfs,并且将在 arm64 虚拟机上运行内核。获取文件的命令是tftp -g -r axpu_ldd_kc.ko my_ip_addr
(当然我的tftp服务器正在工作)。但响应是:
tftp: sendto: Network is unreachable
所以我在内核配置(linux-5.10.0-rc5)中添加了一些网络内容,但仍然不起作用。
我不知道还需要添加什么才能使 tftp 工作有人能告诉我下面的 defconfig 中缺少什么吗? (在qemu虚拟机中使用e1000)。 (如您所见,我添加了 CONFIG_NF_CONNTRACK_TFTP,menuconfig 表示它支持 TFTP。并且 .config 文件将 CONFIG_NF_NAT_TFTP 设置为 =y。我显示了 defconfig,因为 .config 太长)
# CONFIG_SWAP is not set
# CONFIG_CROSS_MEMORY_ATTACH is not set
CONFIG_PREEMPT=y
# CONFIG_CPU_ISOLATION is not set
CONFIG_LOG_BUF_SHIFT=12
CONFIG_LOG_CPU_MAX_BUF_SHIFT=10
CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=10
CONFIG_USER_NS=y
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="../../../../ab21sim/ab21tsim/busybox-1.32.1/initramfs.cpio.gz"
# CONFIG_RD_BZIP2 is not set
# CONFIG_RD_LZMA is not set
# CONFIG_RD_XZ is not set
# CONFIG_RD_LZO is not set
# CONFIG_RD_LZ4 is not set
# CONFIG_RD_ZSTD is not set
CONFIG_PERF_EVENTS=y
CONFIG_SLAB=y
CONFIG_NR_CPUS=2
# CONFIG_RODATA_FULL_DEFAULT_ENABLED is not set
# CONFIG_ARM64_TAGGED_ADDR_ABI is not set
# CONFIG_ARM64_UAO is not set
# CONFIG_ARM64_RAS_EXTN is not set
# CONFIG_ARM64_CNP is not set
# CONFIG_ARM64_PTR_AUTH is not set
# CONFIG_ARM64_AMU_EXTN is not set
# CONFIG_ARM64_TLB_RANGE is not set
# CONFIG_ARM64_BTI is not set
# CONFIG_ARM64_E0PD is not set
# CONFIG_ARCH_RANDOM is not set
# CONFIG_ARM64_SVE is not set
# CONFIG_EFI is not set
# CONFIG_SECCOMP is not set
# CONFIG_BLK_DEV_BSG is not set
# CONFIG_MQ_IOSCHED_DEADLINE is not set
# CONFIG_MQ_IOSCHED_KYBER is not set
CONFIG_BINFMT_MISC=y
CONFIG_FLATMEM_MANUAL=y
# CONFIG_COMPACTION is not set
CONFIG_NET=y
CONFIG_INET=y
CONFIG_NETFILTER=y
CONFIG_NF_CONNTRACK=y
CONFIG_NF_CONNTRACK_TFTP=y
CONFIG_NF_NAT=y
CONFIG_DEVTMPFS=y
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=65536
CONFIG_NETDEVICES=y
# CONFIG_KEYBOARD_ATKBD is not set
# CONFIG_INPUT_MOUSE is not set
CONFIG_SERIO_LIBPS2=y
CONFIG_VT_HW_CONSOLE_BINDING=y
# CONFIG_LEGACY_PTYS is not set
CONFIG_SERIAL_AMBA_PL011=y
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
# CONFIG_HWMON is not set
# CONFIG_USB_SUPPORT is not set
CONFIG_RTC_CLASS=y
# CONFIG_RTC_HCTOSYS is not set
# CONFIG_RTC_INTF_SYSFS is not set
# CONFIG_RTC_INTF_PROC is not set
# CONFIG_RTC_INTF_DEV is not set
CONFIG_RTC_DRV_M48T59=y
# CONFIG_VHOST_MENU is not set
# CONFIG_IOMMU_SUPPORT is not set
# CONFIG_NVMEM_SYSFS is not set
CONFIG_EXT2_FS=y
CONFIG_EXT2_FS_XATTR=y
CONFIG_EXT2_FS_POSIX_ACL=y
CONFIG_EXT2_FS_SECURITY=y
# CONFIG_DNOTIFY is not set
# CONFIG_INOTIFY_USER is not set
CONFIG_AUTOFS4_FS=y
CONFIG_ISO9660_FS=y
CONFIG_PROC_KCORE=y
# CONFIG_MISC_FILESYSTEMS is not set
CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity"
CONFIG_DEBUG_INFO=y
CONFIG_FRAME_WARN=1024
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_FS=y
CONFIG_DEBUG_KERNEL=y
CONFIG_DETECT_HUNG_TASK=y
# CONFIG_SCHED_DEBUG is not set
# CONFIG_RCU_TRACE is not set
顺便说一下,qemu 命令是这样的:
/home/ckim/ProjX/QEMU/qemu-6.2.0/build-baremetal/aarch64-softmmu/qemu-system-aarch64 -machine ab21q,gic-version = max,secure = off,virtualization = true -cpu max -kernel /home/ckim/ProjX/LinuxDevDrv/kernel-release-RD-INFRA-2020.11.30/arch/arm64/boot/Image -m 2048M -ngraphic -netdev user,id=net0,tftp=/opt/tftp -device e1000 ,netdev=net0 -machine iommu=smmuv3 --append "root=/dev/ram init=/init nokaslr Earlycon ip=dhcp Hugepages=16"
通过-netdev
和-device e1000
选项,user mode
网络后端在 qemu 中实现,使我们能够与外界进行通信。虚拟机的 IP 地址为 10.0.2.15。我以前多次使用过这种用户组网模式。 (使用完整的内核默认配置,这个 tftp 运行正常。但我想将内核映像大小从几乎 36MB 减少到大约 6MB,以便快速运行测试)。请在此处查看 qemu 网络模式:https://wiki.qemu.org/Documentation/Networking
ADD :(根据 dirkt 的要求)我的 VM 内有 DHCP 服务器(请参阅上面的网络文档),我的 VM 有静态 IP 地址。还有我的主人。我相信虚拟机上的 DHCP 客户端可以工作,并且 DHCP 服务器由 qemu 程序运行(因此 qemu 程序为虚拟机提供了网络环境)。我可以登录虚拟机并进行调试。 (但我今天正在做其他任务)。这是ip addr
命令响应。
/ # tftp -g -r axpu_ldd_kc.ko 129.254.32.30
tftp: sendto: Network is unreachable
/ # ip addr
1: lo: <LOOPBACK> mtu 65536 qdisc noop qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
ADD2 :(对于 dirkt 的评论)
我添加了 PCI 和 PCIE 以及 e1000(英特尔以太网卡),希望这就是它。但事实并非如此。下面是 shell 中的结果。
ifconfig: SIOCSIFADDR: No such device
route: SIOCADDRT: Network is unreachable
/bin/sh: can't access tty; job control turned off
/ # tftp -g -r axpu_ldd_kc.ko 129.254.32.30
tftp: sendto: Network is unreachable