1、从主机向qemu中的arm架构的linux系统传输文件
(1)创建rootfs文件夹,将其与rootfs.img放在同一文件夹下。
(2)挂载rootfs于rootfs.img:
sudo mount rootfs.img rootfs
(3)创建driver文件夹:
sudo mkdir rootfs/driver
(4) 复制目标文件:
sudo cp /home/h34/consolve_driver/consolve_driver.ko rootfs/driver
(5)停止挂载:
sudo umount rootfs
(6)进入虚拟机,模块在driver文件夹下,如果是内核模块:
insmod console_driver.ko
2、编写内核模块后make报错
(1)错误:
make[1]: 进入目录“/home/h34/linux-6.2”
warning: the compiler differs from the one used to build the kernel
The kernel was built by: aarch64-linux-gnu-gcc (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0
You are using: gcc (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0
CC [M] /home/h34/my_device/my_device_app.o
gcc: error: unrecognized argument in option ‘-mstack-protector-guard=sysreg’
gcc: note: valid arguments to ‘-mstack-protector-guard=’ are: global tls
gcc: error: unrecognized command-line option ‘-mlittle-endian’
gcc: error: unrecognized command-line option ‘-mbranch-protection=pac-ret+leaf’
make[2]: *** [scripts/Makefile.build:252:/home/h34/my_device/my_device_app.o] 错误 1
make[1]: *** [Makefile:2021:/home/h34/my_device] 错误 2
make[1]: 离开目录“/home/h34/linux-6.2”
make: *** [Makefile:7:all] 错误 2
(2)解决办法:
a、进入linux-6.2内核文件,清理过往编译信息:
make clean //只清理编译所有产生的文件
make mrproper //清理编译所有产生的文件与config配置文件
make distclean //清理编译所有产生的文件与config配置文件,并且编辑过的补丁文件
b、设置编译变量
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
c、生成.config文件和make
make defconfig
make
d、回到内核模块,清理过往编译信息,重新make
make clean
make