-
下载内核和文件系统
内核
https://github.com/raspberrypi/linux.git文件系统
https://downloads.raspberrypi.org/raspbian_lite_latestlinaro工具链
https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/
-
编译内核
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4
-
制作文件系统
stor@debian:~/raspberry$ sudo fdisk -l 2018-06-27-raspbian-stretch-lite.img Disk 2018-06-27-raspbian-stretch-lite.img: 1.8 GiB, 1862270976 bytes, 3637248 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4d3ee428 Device Boot Start End Sectors Size Id Type 2018-06-27-raspbian-stretch-lite.img1 8192 96663 88472 43.2M c W95 FAT32 (LBA) 2018-06-27-raspbian-stretch-lite.img2 98304 3637247 3538944 1.7G 83 Linux
从中可以看出以下信息:
boot:
offset = 8192*512 = 4194304
sizelimit = 88472*512 = 45297664
rootfs:
offset = 98304*512=50331648sudo mount -o loop,offset=50331648 2018-06-27-raspbian-stretch-lite.img /mnt sudo mount -o loop,offset=4194304,sizelimit=45297664 2018-06-27-raspbian-stretch-lite.img /mnt/boot
查看文件系统
stor@debian:~/raspberry$ ls /mnt bin debootstrap etc lib media opt root sbin sys usr boot dev home lost+found mnt proc run srv tmp var stor@debian:~/raspberry$ ls /mnt/boot bcm2708-rpi-0-w.dtb bcm2710-rpi-cm3.dtb fixup_db.dat overlays bcm2708-rpi-b.dtb bootcode.bin fixup_x.dat start_cd.elf bcm2708-rpi-b-plus.dtb cmdline.txt issue.txt start_db.elf bcm2708-rpi-cm.dtb config.txt kernel7.img start.elf bcm2709-rpi-2-b.dtb COPYING.linux kernel.img start_x.elf bcm2710-rpi-3-b.dtb fixup_cd.dat LICENCE.broadcom bcm2710-rpi-3-b-plus.dtb fixup.dat LICENSE.oracle
复制内核文件到文件系统:
sudo cp linux/arch/arm64/boot/Image /mnt/boot/kernel8.img sudo cp linux/arch/arm65/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot/ sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt modules_install
修改启动配置
echo kernel=kernel8.img >> /mnt/boot/config.txt
-
添加64位libc
现在内核是64位的,但是文件系统里的文件都是32位的,不能直接运行动态链接的64位的程序,需要添加64位的libc库。
复制库文件到/lib/aarch64-linux-gnu
sudo cp -r /home/stor/tools/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/lib /mnt/lib/aarch64-linux-gnu
添加库文件到系统路径
# add *.conf for aarch64-linux-gnu echo "/lib/aarch64-linux-gnu" > /mnt/etc/ld.so.conf.d/aarch64-linux-gnu.conf
添加aarch64的ld软链接
# make soft link for ld-linux-aarch64.so.1 at /lib ln -s aarch64-linux-gnu/ld-linux-aarch64.so.1 ld-linux-aarch64.so.1
动态链接的程序,可以通过file或者readelf来看使用的链接器名,下面两种方式,查到的都是 /lib/ld-linux-aarch64.so.1:
file方式:
stor@debian:~/code_arm64$ file a.out a.out: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=50648f691b80b656557874266b5b7e02de16b603, not stripped
readelf方式:
stor@debian:~/code_arm64$ aarch64-linux-gnu-readelf a.out -l Elf file type is EXEC (Executable file) Entry point 0x400460 There are 8 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 0x00000000000001c0 0x00000000000001c0 R E 0x8 INTERP 0x0000000000000200 0x0000000000400200 0x0000000000400200 0x000000000000001b 0x000000000000001b R 0x1 #这里可以看到链接器的名字 [Requesting program interpreter: /lib/ld-linux-aarch64.so.1] LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x0000000000000644 0x0000000000000644 R E 0x10000 LOAD 0x0000000000000df8 0x0000000000410df8 0x0000000000410df8 ...
删除preload,否则会产生警告
sudo rm /etc/ld.so.preload
umount
sudo umount /mnt/boot sudo umount /mnt
文件系统修改好了,下面把文件系统烧到SD卡中,并启动树莓派
运行树莓派之后,在树莓派的shell中重新生成ld.so.cache
sudo ldconfig
也可以把这个生成的ld.so.cache放到制作好的文件系统中,以后用这个文件系统就不用再生成了
sudo scp pi@192.168.0.101:/etc/ld.so.cache /mnt/etc/ld.so.cache