macos m1下编译linux内核

2022/7/11 5:20:07

本文主要是介绍macos m1下编译linux内核,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

说明

结合网上一些资源并折腾了一段时间后才成功的。因为完全参考无法正常编译,记录一下供有需要的,希望能对其有所帮助

uboot也可以参考编译通过

macos版本

uname -a
Darwin finnmac-mini.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64

安装环境

brew install make
brew install aarch64-elf-gcc
brew install openssl@1.1

依赖环境

elf.h

个人在内核源码同级新建include目录,拷贝其中

编译步骤

  • 下载内核
    linux-5.18.9
  • 配置内核
/opt/homebrew/opt/make/libexec/gnubin/make ARCH=arm64 CROSS_COMPILE=aarch64-elf- defconfig

# 去掉CONFIG_KVM选项避免不必要的报错
# [ ] Virtualization  ----
/opt/homebrew/opt/make/libexec/gnubin/make ARCH=arm64 CROSS_COMPILE=aarch64-elf- menuconfig
  • 修改内核
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 1c451d5..0d66689 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -43,6 +43,10 @@ typedef struct {
        __u8 b[16];
 } uuid_le;

+#ifdef __APPLE__
+#define uuid_t compat_uuid_t
+#endif
+
 typedef struct {
        __u8 b[16];
 } uuid_t;
  • 编译内核
/opt/homebrew/opt/make/libexec/gnubin/make ARCH=arm64 CROSS_COMPILE=aarch64-elf- HOSTCFLAGS="-I../include -I/opt/homebrew/opt/openssl@1.1/include/" HOSTLDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib/" -j8

效果展示

(master) ~/WorkSpace/github/linux-5.18.9 ✘ ls
1.txt                   Kconfig                 README                  compile_commands.json   init                    modules-only.symvers    samples                 usr
COPYING                 LICENSES                System.map              crypto                  ipc                     modules.builtin         scripts                 virt
CREDITS                 MAINTAINERS             arch                    drivers                 kernel                  modules.builtin.modinfo security                vmlinux
Documentation           Makefile                block                   fs                      lib                     modules.order           sound                   vmlinux.o
Kbuild                  Module.symvers          certs                   include                 mm                      net                     tools                   vmlinux.symvers
(master) ~/WorkSpace/github/linux-5.18.9 ✘ file vmlinux
vmlinux: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=3cfb7eb4d00450fdddde0bf6f1c1dcef63b7ad4a, not stripped
(master) ~/WorkSpace/github/linux-5.18.9 ✘


这篇关于macos m1下编译linux内核的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程