针对OpenHarmony的linux版本提供工具移植,当前支持工具列表如下:
name | 本文档支持 | 脚本 |
---|---|---|
gdb | Y | Y |
strace | Y | Y |
bash | Y | Y |
openssl | Y | Y |
python | Y | Y |
vim | Y | Y |
curl | Y | Y |
elfutils | Y | |
util-linux | Y | Y |
coreutils | Y | Y |
valgrind | Y | Y |
htop | Y | |
jemalloc | Y | Y |
libunwind | Y | Y |
iproute2 | Y | Y |
脚本在scripts目录中,默认通过docker编译,定制run_docker.sh中的BUILD_LIST去修改打包工具集合。BUILD_ARCH可以改为arm或者aarch64.
arm/arm64的编译产物临时归档到(2023.4.19):
链接:https://pan.baidu.com/s/12mVZzbHak94Ky7mI3ge6dg?pwd=ucit 提取码:ucit
注意最近202208月底左右的版本开启了seccomp,gdb等工具被限制了,临时解决方案是:
mount -rw -o remount /
rm -frv /system/{lib,lib64}/libsystem_filter.z.so #名字里有filter的几个so,主要是system_filter
sync
reboot
基于 musl-cross-make,该项目是为linux musl创建的,为了适配ohos需要做一些小修改,我fork了一个仓
https://gitee.com/stesen/musl-cross-make_for_openharmony
里面修改了不少,可以看下git log
git clone https://gitee.com/stesen/musl-cross-make_for_openharmony
pushd musl-cross-make_for_openharmony
如果是arm:
export TOOLCHAIN_TARGET=arm-linux-musleabi
如果是arm64
export TOOLCHAIN_TARGET=aarch64-linux-musleabi
然后创建config:
cat > config.mak << EOF
OHOS_DIR = XXXX/openharmony
TARGET = ${TOOLCHAIN_TARGET}
OUTPUT = /opt/cross
LINUX_FROM = ohos
LINUX_VER = 5.10
MUSL_FROM = ohos
MUSL_VER = ohos
GCC_VER = 10.1.0
EOF
sudo install -m 777 -d /opt/cross
make && make install
popd
## musl 1.2.2需要额外定义个宏:
sed -i '15i#define FNM_EXTMATCH 0' /opt/cross/${TOOLCHAIN_TARGET}/include/fnmatch.h
## 如果要提供给buildroot编译,需要建个链接
mkdir /opt/cross/arm-linux-musleabi/usr
ln -svf ../include /opt/cross/arm-linux-musleabi/usr/
OHOS_DIR是指openharmony代码路径,我们需要用到其中的third_party/musl,因为ohos的musl做了很多修改,官方release的版本跑起来会有很多问题。或者也可以从gitee上直接拉musl这个仓,我懒得改git的下载方式了,大家自便。
注意上面构建的目标是arm eabi的,ohos的linker生成在这个位置 /opt/cross/arm-linux-musleabi/system/lib ,比较下和自己单板上跑的linker是否名字一致。
编译过程应该需要host安装一些autotools,make,gcc之类的基本工具,我环境是manjaro x86_64。其他环境没有试过,但应该没有啥特别的,缺啥装啥。
export PATH=/opt/cross/bin:${PATH}
export DEBUGROOT=/data/debugroot
export TOOLCHAIN_PREFIX=${TOOLCHAIN_TARGET}-
export CC=${TOOLCHAIN_PREFIX}gcc
export STRIP=${TOOLCHAIN_PREFIX}strip
export LD_LIBRARY_PATH=${DEBUGROOT}/lib
export LDFLAGS=-L${DEBUGROOT}/lib
export PKG_CONFIG_PATH=${DEBUGROOT}/pkgconfig
export CONFIGURE_ARGS="--host=${TOOLCHAIN_TARGET} --prefix=$DEBUGROOT"
sudo mkdir -pv $DEBUGROOT/lib
把工具链的库拷到运行时路径下
cp -rav /opt/cross/${TOOLCHAIN_TARGET}/lib/* ${DEBUGROOT}/lib
wget https://strace.io/files/5.14/strace-5.14.tar.xz
tar xf strace-5.14.tar.xz
pushd strace-5.14
./configure $CONFIGURE_ARGS &&
make &&
make install
popd
这里编译openssl是为了下面python,虽然不是强依赖,有总比没有好
wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1l.tar.gz
tar xf OpenSSL_1_1_1l.tar.gz
pushd openssl-OpenSSL_1_1_1l
./Configure linux-armv4 --prefix=$DEBUGROOT \
--openssldir=${DEBUGROOT}/etc/tls \
shared no-ssl no-srp no-tests &&
make && make install
popd
这里做的python工具主要是为了下面gdb用的,本身没有带多少模块和插件,也没有pip,后面再说吧,反正ohos有python-sig去负责这个事
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
tar xf Python-3.9.7.tgz
pushd Python-3.9.7
./configure $CONFIGURE_ARGS --build=arm \
--enable-shared=yes --without-ensurepip \
ac_cv_little_endian_double=yes \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_func_wcsftime=no \
ac_cv_func_ftime=no \
ac_cv_func_faccessat=no \
ac_cv_posix_semaphores_enabled=no \
ac_cv_buggy_getaddrinfo=no \
ac_cv_func_sem_open=no \
ac_cv_func_sem_timedwait=no \
ac_cv_func_sem_getvalue=no \
ac_cv_func_sem_unlink=no \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_func_wcsftime=no &&
make && make install
popd
gdb依赖libgmp
wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz
tar xf gmp-6.2.1.tar.lz
pushd gmp-6.2.1
./configure $CONFIGURE_ARGS &&
make && make install
popd
gdb可以不依赖mpfr,不过我看很多工具链会编译它,我也不知道为啥,反正就编译下,也许能让gdb过得舒服点
wget https://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.gz
tar xf mpfr-4.1.0.tar.gz
pushd mpfr-4.1.0
./configure $CONFIGURE_ARGS \
--with-gmp-include=$DEBUGROOT/include \
--with-gmp-lib=$DEBUGROOT/lib &&
make & make install
popd
gdb可以依赖python,这样就可以搞一些骚脚本,如果不需要,那跳过本步骤,并且下面gdb的configure参数去掉--with-python参数。
先把上面的python编译好,确保在单板上运行python3能跑起来,然后我们需要做个假的python-config去骗下交叉编译时gdb的configure:
cat << EOF | sudo tee /data/my-python-config
#!/bin/sh
case $2 in
--includes)
echo "-I$DEBUGROOT/include/python3.9"
;;
--ldflags)
echo "-L$DEBUGROOT/lib -lpython3.9 -export-dynamic"
;;
--exec-prefix)
echo "$DEBUGROOT"
;;
*)
echo bad args $2; exit 1
esac
exit 0
EOF
sudo chmod +x /data/my-python-config
wget https://ftp.gnu.org/gnu/gdb/gdb-11.1.tar.gz
tar xf gdb-11.1.tar.gz
pushd gdb-11.1
./configure $CONFIGURE_ARGS \
--disable-source-highlight \
--with-mpfr=$DEBUGROOT \
--with-gmp=$DEBUGROOT \
--with-python=/data/my-python-config &&
make && make install
popd
wget https://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz
tar xf bash-5.1.tar.gz
pushd bash-5.1
./configure $CONFIGURE_ARGS \
--without-bash-malloc &&
make && make install
popd
vim依赖tlib,建议用ncurses
wget https://ftp.gnu.org/gnu/ncurses/ncurses-6.3.tar.gz
tar xf ncurses-6.3.tar.gz
pushd ncurses-6.3
./configure $CONFIGURE_ARGS \
--disable-stripping \
--enable-const \
--enable-ext-colors \
--enable-ext-mouse \
--enable-overwrite \
--enable-pc-files \
--enable-termcap \
--enable-widec \
--without-ada \
--without-cxx-binding \
--without-tests \
--without-debug \
--with-normal \
--with-static \
--with-shared \
ac_cv_header_locale_h=no &&
make && make install
popd
ln -svf libncursesw.so ${DEBUGROOT}/lib/libncurses.so
wget ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2
tar xf vim-8.1.tar.bz2
pushd vim81
./configure $CONFIGURE_ARGS \
--enable-gui=no \
vim_cv_toupper_broken=yes \
vim_cv_getcwd_broken=no \
vim_cv_tgetent=zero \
vim_cv_terminfo=yes \
vim_cv_stat_ignores_slash=no \
vim_cv_memmove_handles_overlap=yes \
vim_cv_tty_group=world \
--with-local-dir=${DEBUGROOT} \
--with-tlib=ncurses &&\
make && make install
popd
wget https://curl.se/download/curl-7.80.0.tar.xz
tar xf curl-7.80.0.tar.xz
pushd curl-7.80.0
autoreconf -vfi &&
./configure $CONFIGURE_ARGS \
--with-openssl \
--without-libidn \
--without-libidn2 \
--disable-ldap \
--with-pic \
--without-libssh2 &&
make && make install
popd
wget https://www.zlib.net/fossils/zlib-1.2.11.tar.gz
tar xf zlib-1.2.11.tar.gz
pushd zlib-1.2.11
./configure --prefix=$DEBUGROOT && make && make install
popd
wget https://tukaani.org/xz/xz-5.2.5.tar.gz
tar xf xz-5.2.5.tar.gz
pushd xz-5.2.5
./configure $CONFIGURE_ARGS &&
make && make install
popd
wget https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
tar xf bzip2-1.0.8.tar.gz
pushd bzip2
sed -i "s/CC=gcc/CC=${TOOLCHAIN_PREFIX}gcc/g" Makefile-libbz2_so &&
make &&
install -D -m644 bzlib.h ${DEBUGROOT}/include/bzlib.h \
install -D -m755 libbz2.so.1.0.8 ${DEBUGROOT}/lib/libbz2.so.1.0 &&
ln -svf libbz2.so.1.0 /data/debugroot/lib/libbz2.so
popd
wget https://github.com/facebook/zstd/archive/v1.5.0.tar.gz -O zstd-v1.5.0.tar.gz
tar xf zstd-v1.5.0.tar.gz
pushd zstd-1.5.0
export CC=${TOOLCHAIN_PREFIX}gcc
export CXX=${TOOLCHAIN_PREFIX}g++
make -C lib HAVE_PTHREAD=1 HAVE_ZLIB=0 HAVE_LZMA=0 HAVE_LZ4=0 lib-mt &&
make -C programs HAVE_PTHREAD=1 HAVE_ZLIB=0 HAVE_LZMA=0 HAVE_LZ4=0 &&
make -C contrib/pzstd &&
make PREFIX="" DESTDIR=${DEBUGROOT} install
unset CC
unset CXX
popd
argp是glibc提供的特性,elfutils依赖它,musl自己不带argp,需要使用argp-standalone来补充。
wget http://www.lysator.liu.se/~nisse/misc/argp-standalone-1.3.tar.gz
tar xf argp-standalone-1.3.tar.gz
pushd argp-standalone-1.3
CFLAGS="-fPIC -U__OPTIMIZE__" \
./configure $CONFIGURE_ARGS &&
make && make install &&
install -D -m644 argp.h ${DEBUGROOT}/include/argp.h &&
install -D -m755 libargp.a ${DEBUGROOT}/lib/libargp.a
popd
git clone https://github.com/pullmoll/musl-fts.git
pushd musl-fts
./bootstrap.sh &&
CFLAGS=-fPIC ./configure $CONFIGURE_ARGS &&
make && make install
popd
git clone https://github.com/void-linux/musl-obstack.git
pushd musl-obstack
./bootstrap.sh &&
./configure $CONFIGURE_ARGS &&
make && make install
popd
wget https://sourceware.org/elfutils/ftp/0.186/elfutils-0.186.tar.bz2
tar xf elfutils-0.186.tar.bz2
pushd elfutils-0.186
CFLAGS=-I/data/debugroot/include \
LIBS="-lz -lzstd -lbz2 -llzma -lfts -l obstack" \
./configure $CONFIGURE_ARGS \
--disable-debuginfod \
--disable-libdebuginfod \
--disable-werror &&
make && make install
popd
wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.37/util-linux-2.37.2.tar.gz
tar xf util-linux-2.37.2.tar.gz
pushd util-linux-2.37.2
CFLAGS=-I${DEBUGROOT}/include \
./configure $CONFIGURE_ARGS \
--sbindir=${DEBUGROOT}/bin \
--without-systemd \
--disable-makeinstall-chown \
--disable-bash-completion &&
make && make install
popd
wget https://ftp.gnu.org/gnu/coreutils/coreutils-9.0.tar.xz
tar xf coreutils-9.0.tar.xz
pushd coreutils-9.0/
./configure $CONFIGURE_ARGS && make && make install
popd
wget https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2
tar xf valgrind-3.18.1.tar.bz2
pushd valgrind-3.18.1
sed -i "s/armv7/arm/g" configure
./configure $CONFIGURE_ARGS && make && make install
popd
首先编译上面的ncurses,然后编译libnl
wget https://www.infradead.org/\~tgr/libnl/files/libnl-3.2.25.tar.gz
tar xf libnl-3.2.25.tar.gz
pushd libnl-3.2.25
./configure $CONFIGURE_ARGS && make && make install
popd
wget https://github.com/htop-dev/htop/releases/download/3.2.0/htop-3.2.0.tar.xz
tar xf htop-3.2.0.tar.xz
pushd htop-3.2.0
CFLAGS=-I${DEBUGROOT}/include ./configure $CONFIGURE_ARGS --disable-unicode --includedir=${DEBUGROOT}/include && make && make install
popd
注意htop运行需要保留terminfo信息,我选择的TERM是linux,需要/data/debugroot/share/terminfo/l/linux
OHOS是用musl分配器的,这是个垃圾。后面会切换mimalloc,但是有些jemalloc的调试功能很怀念,因此移植一个来用。
jemalloc的prof功能依赖下面的libunwind,先编译libunwind,不需要此功能的可以不编
wget https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
tar xf jemalloc-5.3.0.tar.bz2
pushd jemalloc-5.3.0
CFLAGS=-I/data/debugroot/include ./configure $CONFIGURE_ARGS \
--enable-stats \
--enable-debug \
--enable-prof \
--enable-uaf-detection \
--enable-prof-libunwind \
--disable-prof-gcc \
--disable-prof-libgcc \
--enable-fill \
--with-static-libunwind=/data/debugroot/lib/libunwind.a --includedir=/data/debugroot/include && \
make && make install
popd
OHOS的libunwind定制过,为了避免兼容性问题,从OHOS拉libunwind编译
git clone https://gitee.com/openharmony/third_party_libunwind.git
pushd third_party_libunwind
./autogen.sh $CONFIGURE_ARGS --disable-coredump && make && make install
popd
wget https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/snapshot/iproute2-6.2.0.tar.gz
tar xf iproute2-6.2.0.tar.gz
pushd iproute2-6.2.0
sed -i "/SUBDIRS=/s/netem //" Makefile
make CC=${TOOLCHAIN_PREFIX}gcc LD=${TOOLCHAIN_PREFIX}ld AR=${TOOLCHAIN_PREFIX}ar PKG_CONFIG_PATH=${DEBUGROOT}/pkgconfig && make install
popd
先建个脚本
cat > ${DEBUGROOT}/init.sh << EOF
export PATH=/data/debugroot/bin:\$PATH
export LD_LIBRARY_PATH=/data/debugroot/lib:\$LD_LIBRARY_PATH
bash
EOF
chmod +x ${DEBUGROOT}/init.sh
通过hdc或者nfs推送到设备/data/debugroot目录下(可以提前删掉里面的manpages、头文件、静态库等,减少体积)
运行/data/debugroot/init.sh,就可以运行其中的工具了
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。