使用的是lean的源:

https://github.com/coolsnowwolf/lede.git

大体步骤与文档中描述的基本一致,但是因为是在arm64的主机上。因此有几个点与x86机器编译不同,这里记录一下。

编译的系统是Ubuntu 20.04 aarch64。
首先安装编译环境的包就与x86不太一样。具体是:

sudo apt update -y
sudo apt full-upgrade -y
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext  gcc-multilib-arm-linux-gnueabihf \
g++-multilib-arm-linux-gnueabihf git golang gperf haveged help2man intltool libelf-dev libglib2.0-dev \
libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \
mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip qemu-utils \
rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev

2025年更新,最新的lede分支已经包含了以下两个源的绝大多数重点内容,没有特别需求可以不用添加了。
用git拉回代码后,还需要加入特别需要的包。
feeds.conf.default 文件中添加几行:

src-git passwall_packages https://github.com/xiaorouji/openwrt-passwall-packages.git;main
src-git passwall_luci https://github.com/xiaorouji/openwrt-passwall.git;main
src-git passwall2_luci https://github.com/xiaorouji/openwrt-passwall2.git;main

因为本人需要集成加强版geodata文件,要添加一个本地feeds:

src-link custom /home/ubuntu/openwrt/feeds

更新 feeds 什么的跟官方文档一样。

./scripts/feeds update -a
./scripts/feeds install -a

接下来,重点来了。必须多做一件与x86系统不同的配置,否则会报这个错误。

Makefile:366: * go-bootstrap cannot be installed on linux/arm64. Stop.

看报错信息,是编译过程无法安装go到arm64系统上。所以需要手动安装golang,并把路径设置到编译配置中。
在配置编译参数时:

make menuconfig

要加入以下设置:

Languages > Go > Configuration > External bootstrap Go root directory

按上面的环境安装后,go应该默认在 /usr/lib/go 目录下。将 /usr/lib/go 写入这项配置。

(/usr/lib/go) External bootstrap Go root directory

选好其它需要的配置后,开始编译:

make download -j8
make V=s -j1

慢慢等待编译完成吧。编译完成后输出路径:bin/targets

需要更新代码再次编译的话:

cd lede
git pull
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make download -j8
make V=s -j$(nproc)

如果需要重新配置:

rm -rf ./tmp && rm -rf .config
make menuconfig
make V=s -j$(nproc)

PS:第一次编译有概率会出现一个错误。

bash: po2lmo: command not found

这个是因为包依赖关系没有处理好,被依赖的luci-base包没有先编译出来。所以只要先编译好就可以了。
用以下命令指定编译luci-base

make package/feeds/luci/luci-base/compile V=99

给编译的固件加个自己的签名……

cd lede
vim package/lean/default-settings/files/zzz-default-settings

找到DISTRIB_REVISION或者DISTRIB_DESCRIPTION,加上想要添加的内容。比如:

(Compiled by winger. On $(date +%F))

标签: openwrt, arm64, 编译, 路由器

已有 8 条评论

  1. soapman soapman

    install安装不上
    gcc-multilib-arm-linux-gnueabihf
    g++-multilib-arm-linux-gnueabihf

    换成
    gcc-arm-linux-gnueabihf
    g++-arm-linux-gnueabihf

    可以install

    1. 估计是因为系统的版本不太一样。

      当时是Ubuntu 20.04的版本,现在已经比较老了。

      现在最新是24.04,可能一部分包名有变化。

      这里没有办法一一验证,谢谢提醒。

  2. xie xie

    编译过不了,出现了一点错误,大家能看看么?
    checking whether make supports nested variables... yes
    checking whether make supports nested variables... (cached) yes
    checking for aarch64-unknown-linux-gnu-gcc... /home/xzc/lede/staging_dir/host/bin/gcc
    checking whether the C compiler works... no
    configure: error: in `/home/xzc/lede/build_dir/host/m4-1.4.19': configure: error: C compiler cannot create executables
    See `config.log' for more details Makefile:28: recipe for target '/home/xzc/lede/build_dir/host/m4-1.4.19/.configured' failed make[3]: *** [/home/xzc/lede/build_dir/host/m4-1.4.19/.configured] Error 77 make[3]: Leaving directory '/home/xzc/lede/tools/m4' time: tools/m4/compile#0.51#0.51#1.02 ERROR: tools/m4 failed to build.
    tools/Makefile:233: recipe for target 'tools/m4/compile' failed
    make[2]: *** [tools/m4/compile] Error 1
    make[2]: Leaving directory '/home/xzc/lede'
    tools/Makefile:231: recipe for target '/home/xzc/lede/staging_dir/host/stamp/.tools_compile_nyyynyynnnmake[1]: *** [/home/xzc/lede/staging_dir/host/stamp/.tools_compile_nyyynyynnnyyynynyyyyyyyynyyynynyynnmake[1]: Leaving directory '/home/xzc/lede'
    /home/xzc/lede/include/toplevel.mk:229: recipe for target 'world' failed
    make: *** [world] Error 2

    1. checking for aarch64-unknown-linux-gnu-gcc... /home/xzc/lede/staging_dir/host/bin/gcc
      checking whether the C compiler works... no

      看起来似乎没有找到gcc的交叉编译器。
      gcc-arm-linux-gnueabihf
      g++-arm-linux-gnueabihf
      这个两个包安装一下看看。所有的依赖包,最好都检查一下。

      1. xie xie

        sudo apt install g++-arm-linux-gnueabihf
        Reading package lists... Done
        Building dependency tree
        Reading state information... Done
        g++-arm-linux-gnueabihf is already the newest version (4:7.3.0-3ubuntu2).
        g++-arm-linux-gnueabihf set to manually installed.
        0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
        $ sudo apt install gcc-arm-linux-gnueabihf
        Reading package lists... Done
        Building dependency tree
        Reading state information... Done
        gcc-arm-linux-gnueabihf is already the newest version (4:7.3.0-3ubuntu2).
        gcc-arm-linux-gnueabihf set to manually installed.
        0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
        $
        已经安装了

        1. 运行
          /home/xzc/lede/staging_dir/host/bin/gcc --version
          看看输出是否正常。如果提示不存在,就安装一下gcc。
          sudo apt install gcc

          如果能正常输出版本号,那就看一下日志中具体是什么错误。
          日志应该是在:
          /home/xzc/lede/build_dir/host/m4-1.4.19/config.log

      2. xie xie

        如果可以的话可以加个联系方式么?线上交流慢了点

        1. 您先看一下上面的方法。如果还有不行,再想想其它办法联系。

添加新评论