openwrt-sdk-compile

SDK位置

openwrt的项目代码放在GitHub上面,check this: https://github.com/openwrt

openwrt的SDK位置在此:https://github.com/openwrt/openwrt

Branches那里选择需要下载的SDK版本:attitude_adjustmentbarrier_breaker or chaos_calmer

依赖

1
sudo apt -y install xclip curl build-essential binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 flex uglifyjs gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev qemu-utils upx libelf-dev autoconf automake libtool autopoint g++-multilib gperf silversearcher-ag tree python2.7 libpython2.7

SDK编译

下完后执行./scripts/feeds update -a获取feeds.conf/feeds.conf.default里面的包。

并且执行./scripts/feeds install -a来安装。

然后make menuconfig选择型号。

最后make V=s -j 4进行编译。

make menuconfig出错

出错基本上就是linux系统有些依赖没有安装,注意查看执行make menuconfig之后,顶部的checking …… fail。

checking哪个软件包fail就安装哪个软件包。

SDK编译出错

因为第一次编译SDK时需要从网上下载一些软件包到dl目录里(下载的软件包可能需要科学上网方式),所以SDK编译不通过基本上就是无法下载对应的软件包。

解决方法是cd dl目录,ls *.dl列出下载出错的软件包,手动下载对应的软件包,并放至此dl目录。

*.dl*.md5sum是下载过程的一些中间产物,手动下载了软件包之后,记得删掉对应的*.dl*.md5sum,否则重新编译的时候,dl目录还存在那些中间产物时,还会继续下载该软件包。

可以去这里下载软件包:http://dl.openwrtdl.com/ https://mirror.sobukus.de/

编译报错时可能找不到出错在哪,可以这样make V=s -j 4 > /tmp/test.log
这样的目的是把正常的打印输出导向/tmp/test.log文件,但是错误信息还是正常输出到STDOUT,这样就很方便看到哪个地方出错了。

root编译

barrier_breaker版本默认不允许root用户编译

include/prereq-build.mk
1
2
3
define Require/non-root
# [ "$$(shell whoami)" != "root" ]
endef

出错记录

出错提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
make[5]: Entering directory '/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal/gcc'
build/genchecksum c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o tree-mudflap.o glibc-c.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a ../libbacktrace/.libs/libbacktrace.a \
checksum-options > cc1-checksum.c.tmp && \
/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../move-if-change cc1-checksum.c.tmp cc1-checksum.c
x86_64-linux-gnu-g++ -c -DIN_GCC_FRONTEND -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/. -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../include -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../libcpp/include -I/home/qlliu/mtk_openwrt.git/staging_dir/host/include -I/home/qlliu/mtk_openwrt.git/staging_dir/host/include -I/home/qlliu/mtk_openwrt.git/staging_dir/host/include -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../libdecnumber -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../libdecnumber/dpd -I../libdecnumber -I/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/../libbacktrace cc1-checksum.c -o cc1-checksum.o
x86_64-linux-gnu-gcc -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o tree-mudflap.o glibc-c.o \
cc1-checksum.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a -lstdc++ -L/home/qlliu/mtk_openwrt.git/staging_dir/host/lib -L/home/qlliu/mtk_openwrt.git/staging_dir/host/lib -L/home/qlliu/mtk_openwrt.git/staging_dir/host/lib -lmpc -lmpfr -lgmp -rdynamic -ldl -lstdc++ -L../zlib -lz
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/c/Make-lang.in:78: recipe for target 'cc1' failed
make[5]: *** [cc1] Error 1
make[5]: Leaving directory '/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal/gcc'
Makefile:3892: recipe for target 'all-gcc' failed
make[4]: *** [all-gcc] Error 2
make[4]: Leaving directory '/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal'
Makefile:45: recipe for target '/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal/.built' failed
make[3]: *** [/home/qlliu/mtk_openwrt.git/build_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal/.built] Error 2
make[3]: Leaving directory '/home/qlliu/mtk_openwrt.git/toolchain/gcc/minimal'
toolchain/Makefile:86: recipe for target 'toolchain/gcc/minimal/compile' failed
make[2]: *** [toolchain/gcc/minimal/compile] Error 2
make[2]: Leaving directory '/home/qlliu/mtk_openwrt.git'
toolchain/Makefile:85: recipe for target '/home/qlliu/mtk_openwrt.git/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/stamp/.toolchain_install' failed
make[1]: *** [/home/qlliu/mtk_openwrt.git/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/stamp/.toolchain_install] Error 2
make[1]: Leaving directory '/home/qlliu/mtk_openwrt.git'
/home/qlliu/mtk_openwrt.git/include/toplevel.mk:171: recipe for target 'world' failed
make: *** [world] Error 2

解决方法
ls -l /usr/bin/x86_64-linux-gnu-gcc 查看实际连接的是哪个gcc版本。
这里是通过sudo ln -s /usr/bin/x86_64-linux-gnu-gcc /usr/bin/gcc-6,修改x86_64-linux-gnu-gcc指向第6版解决的。
该错误是之前指向了gcc-7,估计是升级过gcc版本导致的。

出错提示

1
2
3
4
5
6
7
...
[edimax_fw_header] *** error: 'OpenWrtunknown' is too long, max firware version length is 13
[edimax_fw_header] *** error: 'OpenWrtunknown' is too long, max firware version length is 13
dd: failed to open '....../build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/tmp/f9k1115v2-rootfs': No such file or directory
dd: failed to open '....../build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/tmp/f9k1115v2-uImage': No such file or directory
Makefile:2195: recipe for target 'install' failed
...

解决方法

diff --git a/scripts/getver.sh b/scripts/getver.sh
index 4643ca6..093754c 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -30,5 +30,5 @@ try_hg() {
        [ -n "$REV" ]
 }

-try_version || try_svn || try_git || try_hg || REV="unknown"
+try_version || try_svn || try_git || try_hg || REV="Dev"
 echo "$REV"