交叉编译内核
#!/bin/bash
# LINUXSRC=/root/linux
export LINUXSRC=/keystone/linux
export OUTPUT=/keystone/build/linux.build
#export CONFIG=/keystone/conf/linux64-defconfig
export CONFIG=/keystone/build/config-5.19.0-1012-generic
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
export ARCH=riscv
mkdir -p $OUTPUT/_install
touch $OUTPUT/.exists
cp $CONFIG /keystone/build/linux.build/.config
make -C $LINUXSRC O=$OUTPUT CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv olddefconfig
make -C $LINUXSRC O=$OUTPUT CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv modules -j16
make -C $LINUXSRC O=$OUTPUT CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv -j16
# https://blog.csdn.net/Mculover666/article/details/126164289
# Linux内核编译安装模块并打包
mkdir -p ${OUTPUT}/_install
make INSTALL_MOD_PATH=${OUTPUT}/_install modules_install O=${OUTPUT}
STRIP=${CROSS_COMPILE}strip
find ${OUTPUT}/_install/ -name "*.ko" | xargs $STRIP --strip-debug \
--remove-section=.comment --remove-section=.note --preserve-dates
mod_dir=`ls ${OUTPUT}/_install/lib/modules | awk '{ print $1 }'`
rm ${OUTPUT}/_install/lib/modules/${mod_dir}/build
rm ${OUTPUT}/_install/lib/modules/${mod_dir}/source
tar -zcf ${OUTPUT}/install_${mod_dir}.tar.gz -C ${OUTPUT} _install
目前为止我们有${OUTPUT}/install_${mod_dir}.tar.gz
, ${OUTPUT}/arch/riscv/boot/Image.gz
, ${OUTPUT}/System.map
, ${OUTPUT}/.config
内核替换
假设我们编译出的内核的版本号为$VERSION
, 也就是上文中的${mod_dir}
。那么,我们将需要的文件传输到RISC v的板子上(或者qemu模拟器中),开始对内核进行替换:
sudo cp .config /boot/config-$VERSION
sudo cp Image.gz /boot/vmlinuz-$VERSION
sudo cp System.map /boot/System.map-$VERSION
tar -zxf install_${VERSION}.tar.gz -C /tmp
sudo cp -r /tmp/_install/lib/modules/${VERSION} /lib/modules
sudo update-initramfs -c -k ${VERSION}
sudo u-boot-update
sudo reboot
标签:sudo,Linux,RISCV,Ubuntu,modules,VERSION,install,linux,OUTPUT
From: https://www.cnblogs.com/harrypotterjackson/p/17473414.html