【命令中的home路径是你自己的账号下载文件路径,有几个错误不知道正确的处理方法,自己瞎改的】
[我的机器Ubuntu版本]
uname -a
Linux ubuntu 5.0.0-38-generic #41-Ubuntu SMP Tue Dec 3 00:27:35 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[交叉编译工具版本]
aarch64-linux-gcc --version
aarch64-linux-gcc (ctng-1.23.0-150g-FA) 6.4.0
Copyright © 2017 Free Software Foundation, Inc.
libcap、ncurses、libuuid、util-linux最好下载2017或者以前的版本,不要太旧。
[配置交叉编译工具]
设置非root用户交叉编译工具路径
vim ~/.bashrc
连续按大写GG到最后一行,添加下面命令
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
更新环境变量
source ~/.bashrc
设置root用户交叉编译工具路径
sudo su
vim /root/.bashrc
连续按大写GG到最后一行,添加下面命令
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
更新环境变量
source /root/.bashrc
[查看库文件路径]
aarch64-linux-gcc -print-file-name=libc.so
/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/lib/…/lib64/libc.so
把lib/…/lib64/libc.so去掉作为–prefix=/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr
[编译libcap]libcap下载地址
wget https://mirrors.edge.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.25.tar.xz
tar xf libcap-2.25.tar.xz
cd libcap-2.25/
make prefix=/home/systemd/usr \
exec_prefix=/home/systemd/usr \
BUILD_CC=gcc \
CC=aarch64-linux-gcc \
AR=aarch64-linux-ar \
RANLIB=aarch64-linux-ranlib
sudo su
make prefix=/home/systemd/usr \
exec_prefix=/home/systemd/usr \
BUILD_CC=gcc \
CC=aarch64-linux-gcc \
AR=aarch64-linux-ar \
RANLIB=aarch64-linux-ranlib \
RAISE_SETFCAP=no install
切换新目录
[编译ncurses宽字符]ncurses下载地址
wget https://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz
tar xf ncurses-6.0.tar.gz
cd ncurses-6.0/
./configure --host=aarch64-linux \
--prefix=/home/systemd/usr \
--exec-prefix=/home/systemd/usr \
--with-termlib \
--enable-widec \
--disable-stripping \
--with-shared \
--with-cxx-shared \
--without-manpages
报错:在./include/curses.tail中删除掉 /* generated */这个注释
make -j8
sudo su
make install
[编译ncurses非宽字符]
./configure --host=aarch64-linux \
--prefix=/home/systemd/usr \
--exec-prefix=/home/systemd/usr \
--with-termlib \
--disable-stripping \
--with-shared \
--with-cxx-shared \
--without-manpages
make -j8
sudo su
make install
[编译libuuid]libuuid下载地址
tar xf libuuid-1.0.3.tar.gz
cd libuuid-1.0.3/
./configure --host=aarch64-linux \
--prefix=/home/systemd/usr \
--exec-prefix=/home/systemd/usr
make -j8
sudo su
make install
[编译util-linux]util-linux下载地址
sudo apt-get install gperf autopoint pkg-config automake autoconf libtool intltool
git clone --depth=1 --branch=v2.29 https://github.com/util-linux/util-linux.git
cd util-linux/
./autogen.sh
./configure --host=aarch64-linux \
--prefix=/home/systemd/usr \
--exec-prefix=/home/systemd/usr \
CFLAGS="-I/home/systemd/usr/include/ -I/home/systemd/usr/include/ncurses" \
LDFLAGS="-L/home/systemd/usr/lib/ -luuid"
make -j8
/opt/FriendlyARM/toolchain/6.4-aarch64/lib/gcc/aarch64-cortexa53-linux-gnu/6.4.0/../../../../aarch64-cortexa53-linux-gnu/bin/ld.bfd: warning: libblkid.so.1, needed by ./.libs/libmount.so, not found (try using -rpath or -rpath-link)
./.libs/libmount.so: undefined reference to `blkid_evaluate_tag@BLKID_2.15'
./.libs/libmount.so: undefined reference to `blkid_known_fstype@BLKID_1.0'
报错了之后执行下面命令,/home/systemd/util-linux/是你自己的git clone路径
sudo ln -sf /home/systemd/util-linux/.libs/* /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/lib/
make -j8
sudo su
make install
[编译systemd]systemd下载地址
git clone --depth=1 --branch=v234 https://github.com/systemd/systemd.git
cd systemd/
./autogen.sh
vim ./configure
把
$as_echo "#define HAVE_LIBMOUNT 1" >>confdefs.h
have_libmount=yes
fi
改成
$as_echo "#define HAVE_LIBMOUNT 1" >>confdefs.h
have_libmount=yes
fi
have_libmount=yes #添加这个
把
ac_res=$ac_cv_search_cap_init
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
else
as_fn_error $? "*** POSIX caps library not found" "$LINENO" 5
fi
改成
ac_res=$ac_cv_search_cap_init
ac_res=yes #添加这个
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
else
as_fn_error $? "*** POSIX caps library not found" "$LINENO" 5
fi
./configure --host=aarch64-linux \
CFLAGS="-I/home/systemd/usr/include/ -I/home/systemd/usr/include/libmount/ -I/home/systemd/usr/include/sys/" \
LIBS="-L/home/systemd/usr/lib64 -lmount -lcap" \
--prefix=/usr \
--sysconfdir=/etc \
--libdir=/usr/lib \
--libexecdir=/usr/lib \
--localstatedir=/var \
--runstatedir=/run \
--with-rootprefix=/usr \
--with-rootlibdir=/usr/lib \
--disable-manpages \
--disable-tests
make -j8
sudo su
make DESTDIR=/home/systemd/_install install
[编译libexpat]libexpat下载地址
git clone --depth=1 --branch=R_2_2_5 https://github.com/libexpat/libexpat.git
cd libexpat/expat/
./buildconf.sh
./configure --host=aarch64-linux \
--prefix=/home/systemd/usr \
--exec-prefix=/home/systemd/usr \
--without-xmlwf \
--without-docbook
make -j8
sudo su
make install
[编译dbus]dbus下载地址
wget https://dbus.freedesktop.org/releases/dbus/dbus-1.10.24.tar.gz
tar xf dbus-1.10.24.tar.gz
cd dbus-1.10.24
vim ./configure
把
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
have_systemd=yes
fi
改成
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
have_systemd=yes
fi
have_systemd=yes #增加这个
./configure --host=aarch64-linux \
--prefix= \
--exec-prefix= \
--with-systemdsystemunitdir=/etc/systemd/system/ \
--with-systemduserunitdir=/etc/systemd/user/ \
CFLAGS="-I/home/systemd/usr/include -I/home/systemd/_install/usr/include/" \
LDFLAGS="-L/home/systemd/usr/lib -lexpat -luuid -lmount -lblkid -L/home/systemd/usr/lib64/ -lcap -L/home/systemd/_install/usr/lib/ -lsystemd"
make -j8
sudo su
make DESTDIR=/home/systemd/_install install
复制到根文件系统前(用sudo cp -rip命令复制),需要把systemd中需要的so文件复制到根文件系统lib64
aarch64-linux-readelf -a systemd | grep ‘Shared’
Type: DYN (Shared object file)
0x0000000000000001 (NEEDED) Shared library: [libsystemd-shared-234.so]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libmount.so.1]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1]
libcap.so.2
libblkid.so.1
libuuid.so.1
libcrypt.so.1
libexpat.so.1
libnss_files.so.2
在/home/systemd/usr和/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/查找.so文件,复制到目标目录 destination_dir=“/path/to/destination”
#!/bin/bash
# 定义库文件的名称数组
libraries=(
"libsystemd-shared-234.so"
"librt.so.1"
"libmount.so.1"
"libpthread.so.0"
"libc.so.6"
"ld-linux-aarch64.so.1"
"libcap.so.2"
"libblkid.so.1"
"libuuid.so.1"
"libcrypt.so.1"
"libexpat.so.1"
"libnss_files.so.2"
)
# 定义目标目录
destination_dir="/path/to/destination"
# 确保目标目录存在
mkdir -p "$destination_dir"
# 查找并复制库文件
for lib in "${libraries[@]}"; do
# 查找库文件所在路径
lib_path=$(find . -name "$lib" 2>/dev/null)
if [ -n "$lib_path" ]; then
echo "Found $lib at $lib_path, copying to $destination_dir"
cp "$lib_path" "$destination_dir"
else
echo "Library $lib not found."
fi
done
echo "All specified libraries have been processed."
在根文件系统根目录下执行下面命令
cp /home/systemd/usr/sbin/agetty /home/rootfs/sbin
cp /home/systemd/usr/sbin/sulogin /home/rootfs/usr/sbin/
cp /home/systemd/usr/bin/mount /home/rootfs/usr/bin
cd /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot
sudo cp sbin/ldconfig /home/rootfs/sbin/
设置时间同步
vim ./etc/systemd/timesyncd.conf
添加
NTP=ntp.ntsc.ac.cn cn.ntp.org.cn
-/sbin/agetty -o ‘-p – \u’ 把 -o '-p – \u’改成–autologin root自动登录
grep -R "agetty -o"
./usr/lib/systemd/system/console-getty.service:ExecStart=-/sbin/agetty -o '-p -- \\u' --noclear --keep-baud console 115200,38400,9600 $TERM
./usr/lib/systemd/system/serial-getty@.service:ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,38400,9600 %I $TERM
./usr/lib/systemd/system/container-getty@.service:ExecStart=-/sbin/agetty -o '-p -- \\u' --noclear --keep-baud pts/%I 115200,38400,9600 $TERM
uboot的bootargs变量填写
把
init=/linuxrc
改成
init=/usr/lib/systemd/systemd
开发板执行
adduser -H -D messagebus
可以不用编译,strace是跟踪进程执行时的系统调用和所接收的信号(即它跟踪到一个进程产生的系统调用,包括参数、返回值、执行消耗的时间)。
wget https://strace.io/files/6.4/strace-6.4.tar.xz
tar xf strace-6.4.tar.xz
cd strace-6.4/
./configure --host=aarch64-linux \
--prefix= \
--exec-prefix= \
--enable-mpers=no
make -j8
make DESTDIR=/home/rootfs/ install
[报错]
1、/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/sbin/setcap: 1: /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/sbin/setcap: Syntax error: word unexpected (expecting “)”)
make[1]: *** [Makefile:27: install] Error 2
添加RAISE_SETFCAP=no
make prefix=/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr \
BUILD_CC=gcc \
CC=aarch64-linux-gcc \
AR=aarch64-linux-ar \
RANLIB=aarch64-linux-ranlib \
RAISE_SETFCAP=no install
2、strip: Unable to recognise the format of the input file `/r/ncurses-6.3/install/bin/
编译选择加上 --disable-stripping 这个即可。
参考 strip: Unable to recognise the format of the input file
3、In file included from ./curses.priv.h:325:0,
from …/ncurses/lib_gen.c:19:
_9487.c:1372:15: error: expected ‘)’ before ‘int’
…/include/curses.h:1943:56: note: in definition of macro ‘mouse_trafo’
#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen)
^
make[1]: *** [Makefile:2210: …/obj_s/lib_gen.o] Error 1
extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated /
在./include/curses.tail中删除掉 / generated */这个注释
参考 解决从源码编译ncurses6.0编译lib_gen.c报错的问题
4、text-utils/ul.c:46:41: fatal error: term.h: No such file or directory
#include <term.h> /* for setupterm() */
创建include/ncurses/下的文件到include目录的软链接
sudo ln -s /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/ncurses/* /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/
5、misc-utils/cal.c: In function ‘setup_terminal’:
misc-utils/cal.c: 100:46: error: ‘OK’ undeclared (first use in this function)
if (setupterm(term, STDOUT_FILENO, &ret) != OK || ret != 1)
^~
misc-utils/cal.c: 100:46: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [Makefile:9216: misc-utils/cal-cal.o] Error 1
创建include/ncurses/下的文件到include目录的软链接
sudo ln -s /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/ncurses/* /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/
然后make clean重新./configure
6、disk-utils/cfdisk.c:119:28: error: ‘COLOR_RED’ undeclared here (not in a function)
[CFDISK_CL_WARNING] = { COLOR_RED, -1 },
make clean重新./configure
7、configure: error: *** libmount support required but libraries not found
报错之后
把
$as_echo “#define HAVE_LIBMOUNT 1” >>confdefs.h
have_libmount=yes
fi
改成
$as_echo “#define HAVE_LIBMOUNT 1” >>confdefs.h
have_libmount=yes
fi
have_libmount=yes
8、In file included from src/core/emergency-action.h:36:0,
from src/core/unit.h:32,
from src/core/dbus-unit.h:24,
from src/core/unit.c:33:
src/core/manager.h:22:22: fatal error: libmount.h: No such file or directory
#include <libmount.h>
执行下面命令
sudo ln -s /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/libmount/* /opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot/usr/include/
9、参考 setfacl 设置单用户权限时报错的处理
setfacl -nm g:adm:rx,d:g:adm:rx /home/linux/systemd/_install/var/log/journal/
setfacl -nm g:wheel:rx,d:g:wheel:rx /home/linux/systemd/_install/var/log/journal/
setfacl: Option -m: Invalid argument near character 3
make[2]: [Makefile:30336: journal-install-hook] Error 2 (ignored)
执行下面命令
groupadd wheel
10、参考 configure: error: Cannot enable m32 personality support
checking for m32 personality compile support (using gcc -I./bundled/linux/arch/x86/include/uapi -I./bundled/linux/include/uapi -Isrc -m32)… no
checking whether to enable m32 personality support… no
configure: error: Cannot enable m32 personality support
增加编译参数–enable-mpers=no