├── tools ├── rescue │ ├── .gitignore │ └── emmc-install.sh ├── boot │ ├── uEnv.txt │ └── boot.cmd ├── qemu │ └── qemu-aarch64-static ├── alpine │ ├── resizemmc.sh │ ├── resizemmc │ └── init.sh ├── systemd │ ├── resizemmc.sh │ ├── resizemmc.service │ └── sshdgenkeys.service ├── archlinux │ └── init.sh ├── debian │ └── init.sh └── ubuntu │ └── init.sh ├── .gitignore ├── .travis.yml ├── Makefile └── common.sh /tools/rescue/.gitignore: -------------------------------------------------------------------------------- 1 | *.xz 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dl 2 | tmp 3 | output 4 | -------------------------------------------------------------------------------- /tools/boot/uEnv.txt: -------------------------------------------------------------------------------- 1 | verbosity=7 2 | rootfstype=ext4 3 | extraargs=audit=0 4 | -------------------------------------------------------------------------------- /tools/qemu/qemu-aarch64-static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanwckf/build-catdrive/HEAD/tools/qemu/qemu-aarch64-static -------------------------------------------------------------------------------- /tools/alpine/resizemmc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | parted /dev/mmcblk0 resizepart 1 Yes 100% && resize2fs /dev/mmcblk0p1 && echo "resize done, please reboot" || echo "resize failed!" 4 | -------------------------------------------------------------------------------- /tools/systemd/resizemmc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -e /root/.need_resize ]; then 4 | parted -s /dev/mmcblk0 -- resizepart 1 100% && resize2fs /dev/mmcblk0p1 && echo "resize done, please reboot" || echo "resize failed!" 5 | rm -f /root/.need_resize 6 | fi 7 | -------------------------------------------------------------------------------- /tools/alpine/resizemmc: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | description="Resize rootfs partition." 4 | 5 | start() { 6 | if [ -e /root/.need_resize ] ; then 7 | ebegin "Resize rootfs, please reboot after finish" 8 | /sbin/resizemmc.sh > /dev/null 2>&1 9 | eend $? 10 | rm -f /root/.need_resize 11 | fi 12 | } 13 | -------------------------------------------------------------------------------- /tools/systemd/resizemmc.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=filesystem resize 3 | Before=basic.target 4 | After=sysinit.target local-fs.target 5 | DefaultDependencies=no 6 | 7 | [Service] 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | ExecStart=/sbin/resizemmc.sh 11 | TimeoutStartSec=1min 12 | 13 | [Install] 14 | WantedBy=basic.target 15 | -------------------------------------------------------------------------------- /tools/rescue/emmc-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | img="/root/rootfs.img" 4 | disk="/dev/mmcblk0" 5 | 6 | [ ! -f $img ] && echo "$img not found!" && exit 1 7 | [ ! -e $disk ] && echo "emmc not found!" && exit 1 8 | 9 | echo "flash emmc..." 10 | echo 2 > /sys/class/leds/red/blink 11 | 12 | pv -pterb $img | dd of=$disk conv=fsync bs=2M 13 | 14 | [ "$?" = "0" ] && echo "flash done, please poweroff now then unplug USB drive!" || echo "flash fail!" 15 | echo 0 > /sys/class/leds/red/blink 16 | 17 | -------------------------------------------------------------------------------- /tools/systemd/sshdgenkeys.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SSH Key Generation 3 | ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key 4 | ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub 5 | ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key 6 | ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub 7 | ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key 8 | ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub 9 | ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key 10 | ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub 11 | 12 | [Service] 13 | ExecStart=/usr/bin/ssh-keygen -A 14 | Type=oneshot 15 | RemainAfterExit=yes 16 | 17 | -------------------------------------------------------------------------------- /tools/boot/boot.cmd: -------------------------------------------------------------------------------- 1 | setenv rootdev "/dev/mmcblk0p1" 2 | setenv verbosity "1" 3 | setenv rootfstype "ext4" 4 | 5 | load ${boot_interface} ${devnum}:1 ${scriptaddr} ${prefix}uEnv.txt 6 | env import -t ${scriptaddr} ${filesize} 7 | 8 | setenv bootargs "$console root=${rootdev} rootfstype=${rootfstype} rootwait loglevel=${verbosity} usb-storage.quirks=${usbstoragequirks} ${extraargs}" 9 | 10 | setenv fdt_name_a armada-3720-catdrive.dtb 11 | 12 | ext4load $boot_interface 0:1 $kernel_addr ${prefix}$image_name 13 | ext4load $boot_interface 0:1 $fdt_addr ${prefix}$fdt_name_a 14 | 15 | booti $kernel_addr - $fdt_addr 16 | # mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: bionic 2 | language: minimal 3 | sudo: required 4 | addons: 5 | apt: 6 | packages: 7 | - bsdtar 8 | - tree 9 | - debootstrap 10 | - jq 11 | - binfmt-support 12 | - u-boot-tools 13 | script: 14 | - make build_archlinux=y build_ubuntu=y build_debian=y build 15 | - tree -hn output 16 | deploy: 17 | provider: releases 18 | skip_cleanup: true 19 | overwrite: true 20 | file_glob: true 21 | file: output/release/*.xz 22 | api_key: 23 | secure: jz9VEWr4bRTHCq2aC08J/dyHTBaW7HvN0un907MA/biGAr+wbte5TZwFHzWWl4IPmp92nLMNYLOPOP54vW/zQm8l8lTtq8Z2QNIHc7M3YpZ6T66wjI6DGnNOCnXVKuwc8PGzLkDf4dAQtVkLaSX6aoeVYmRHPHCmKM8s8ibYQRloXwSNfd9esUm+jSUDCsLrCqokKD/Fd1PE2KdcZ5uHiif0oOne737uZpRjl2WrbCFEi+8D5BF2zKc7+S9HQ3WiALEP7TVfayAN4DatY6O6BLIzodtTj1EwVxEMHvYlhZilYro4RrZzi2bHYFUe3WKY6ULkcxpergvXTGlRal3JGg7c79X35Ck9XVQ3UIULhmKuJ+77RXjgf/mjNyYao07a1/j2V2VAUYqR7xEB3C77fVfjo5txaCfPMFoK7JIX3xjLH3TjVjqMU8pXwD9M9tk2ljHZzszUp1rLE+XY0OD2z2sgjBrx+v9V9ZICsGPBPw799JFR7kG1hUVr0nblxdy0k+auJOFZfsq4xGC+3GLVP/5SH69PJ2amHcvLXMUQ+yeejrywukVX6D3u1lrYDrK12BzlDMt2Nagm+nAudxxW/r8jirC4vk7ce26Ihf23/USUJrswLBymWat8kSMwuwFFU4x2ZZ5gynhIg0j9dhMuBRfI7XaMrQtHHFVJI0s5C4c= 24 | on: 25 | repo: hanwckf/build-catdrive 26 | tags: true 27 | -------------------------------------------------------------------------------- /tools/alpine/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 4 | 5 | add_svc(){ 6 | runlevel="$1" 7 | svcs="$2" 8 | for svc in ${svcs}; do 9 | if [ -f ./etc/init.d/${svc} ]; then 10 | ln -sf /etc/init.d/${svc} ./etc/runlevels/${runlevel}/${svc} 11 | fi 12 | done 13 | } 14 | 15 | apk update --no-progress && \ 16 | apk add --no-progress alpine-base haveged parted \ 17 | e2fsprogs-extra coreutils uboot-tools pv tzdata 18 | 19 | echo "root:admin" | chpasswd 20 | 21 | add_svc "sysinit" "sysfs procfs devfs mdev" 22 | 23 | add_svc "boot" "urandom swclock sysctl modules hostname bootmisc syslog" 24 | 25 | add_svc "default" "crond haveged ntpd" 26 | 27 | add_svc "shutdown" "killprocs mount-ro savecache" 28 | 29 | if [ "$BUILD_RESCUE" != "y" ]; then 30 | apk add --no-progress dropbear dropbear-scp 31 | add_svc "boot" "networking" 32 | add_svc "default" "dropbear" 33 | fi 34 | 35 | sed -i '/^tty[2-6]/d' ./etc/inittab 36 | 37 | echo "ttyMV0::respawn:/sbin/getty -L ttyMV0 115200 vt100" >> ./etc/inittab 38 | echo "ttyMV0" >> ./etc/securetty 39 | echo "/dev/mtd1 0x0000 0x10000 0x10000" > /etc/fw_env.config 40 | 41 | sed -i 's/pool.ntp.org/time1.aliyun.com/' ./etc/conf.d/ntpd 42 | ln -sf /usr/share/zoneinfo/Asia/Shanghai ./etc/localtime 43 | 44 | echo "alpine" > ./etc/hostname 45 | 46 | cat > ./etc/network/interfaces <> ./etc/securetty 15 | 16 | echo "/dev/root / ext4 defaults,noatime,nodiratime,errors=remount-ro 0 1" >> ./etc/fstab 17 | 18 | # set ntp server 19 | sed -i '/^#NTP/cNTP=time1.aliyun.com 2001:470:0:50::2' ./etc/systemd/timesyncd.conf 20 | 21 | # set sshd_config to allow root login 22 | sed -i '/^#PermitRootLogin/cPermitRootLogin yes' ./etc/ssh/sshd_config 23 | 24 | # set locale 25 | echo 'en_US.UTF8 UTF-8' > ./etc/locale.gen 26 | locale-gen 27 | echo 'LANG=en_US.utf8' > ./etc/locale.conf 28 | echo 'KEYMAP=us' > ./etc/vconsole.conf 29 | ln -sf ../usr/share/zoneinfo/Asia/Shanghai ./etc/localtime 30 | echo "vm.zone_reclaim_mode=1" > /etc/sysctl.d/99-vm-reclaim.conf 31 | echo "root:admin" |chpasswd 32 | 33 | pacman-key --init 34 | pacman-key --populate archlinuxarm 35 | 36 | sed -i 's/CheckSpace/#CheckSpace/' ./etc/pacman.conf 37 | pacman -Sy --noconfirm hdparm parted uboot-tools 38 | sed -i 's/#CheckSpace/CheckSpace/' ./etc/pacman.conf 39 | 40 | cat < ./etc/udev/rules.d/99-hdparm.rules 41 | ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*",ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", RUN+="/usr/bin/hdparm -S 120 \$env{DEVNAME}" 42 | 43 | EOF 44 | 45 | echo "/dev/mtd1 0x0000 0x10000 0x10000" > ./etc/fw_env.config 46 | 47 | # clean 48 | pacman -Sc --noconfirm 49 | rm -rf ./etc/pacman.d/gnupg 50 | killall -9 gpg-agent 51 | 52 | rm -rf ./var/log/journal 53 | rm -f ./var/lib/dbus/machine-id 54 | : > ./etc/machine-id 55 | 56 | umount /dev 57 | umount /sys 58 | umount /proc 59 | -------------------------------------------------------------------------------- /tools/debian/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 4 | 5 | export DEBIAN_FRONTEND=noninteractive 6 | apt_arg='-q -y -o Dpkg::Progress-Fancy="0"' 7 | 8 | cat < ./usr/sbin/policy-rc.d 9 | #!/bin/sh 10 | exit 101 11 | 12 | EOF 13 | chmod +x ./usr/sbin/policy-rc.d 14 | 15 | /debootstrap/debootstrap --second-stage 16 | apt clean 17 | 18 | mount -t proc none /proc 19 | mount -t sysfs none /sys 20 | mount -t devtmpfs none /dev 21 | mount -t devpts none /dev/pts 22 | 23 | apt $apt_arg update && \ 24 | apt $apt_arg install aptitude openssh-server haveged net-tools network-manager parted u-boot-tools 25 | apt clean 26 | 27 | aptitude search ~pstandard ~prequired ~pimportant -F "%p" |xargs apt $apt_arg install 28 | apt clean 29 | 30 | apt $apt_arg purge exim4-base exim4-config && apt $apt_arg autoremove 31 | apt clean 32 | 33 | systemctl set-default multi-user.target 34 | systemctl disable networking 35 | systemctl enable network-manager 36 | 37 | cat < ./etc/udev/rules.d/99-hdparm.rules 38 | ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*",ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", RUN+="/sbin/hdparm -S 120 \$env{DEVNAME}" 39 | 40 | EOF 41 | 42 | echo "en_US.UTF-8 UTF-8" > ./etc/locale.gen 43 | locale-gen 44 | echo "LANG=en_US.UTF-8" > ./etc/default/locale 45 | ln -sf /usr/share/zoneinfo/Asia/Shanghai ./etc/localtime 46 | sed -i '/^#PermitRootLogin/cPermitRootLogin yes' ./etc/ssh/sshd_config 47 | sed -i '/^#NTP/cNTP=time1.aliyun.com 2001:470:0:50::2' ./etc/systemd/timesyncd.conf 48 | echo "ttyMV0" >> ./etc/securetty 49 | echo "/dev/root / ext4 defaults,noatime,nodiratime,errors=remount-ro 0 1" >> ./etc/fstab 50 | echo "vm.zone_reclaim_mode=1" > ./etc/sysctl.d/99-vm-reclaim.conf 51 | echo "/dev/mtd1 0x0000 0x10000 0x10000" > ./etc/fw_env.config 52 | echo "catdrive" > ./etc/hostname 53 | echo "root:admin" |chpasswd 54 | 55 | rm -f ./etc/ssh/ssh_host_* 56 | rm -rf ./var/log/journal 57 | rm -rf ./var/cache 58 | rm -rf ./var/lib/apt/* 59 | rm -f ./usr/sbin/policy-rc.d 60 | rm -f ./var/lib/dbus/machine-id 61 | : > ./etc/machine-id 62 | 63 | umount /dev/pts 64 | umount /dev 65 | umount /sys 66 | umount /proc 67 | 68 | -------------------------------------------------------------------------------- /tools/ubuntu/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 4 | 5 | mount -t proc none /proc 6 | mount -t sysfs none /sys 7 | mount -t devtmpfs none /dev 8 | mount -t devpts none /dev/pts 9 | 10 | export DEBIAN_FRONTEND=noninteractive 11 | apt_arg='-qq -y -o Dpkg::Progress-Fancy="0"' 12 | 13 | cat < ./usr/sbin/policy-rc.d 14 | #!/bin/sh 15 | exit 101 16 | 17 | EOF 18 | 19 | chmod +x ./usr/sbin/policy-rc.d 20 | 21 | apt $apt_arg update && apt $apt_arg upgrade 22 | 23 | if [ "$BUILD_MINIMAL" = "y" ]; then 24 | echo "Build minimal ubuntu" 25 | apt $apt_arg install ubuntu-minimal ubuntu-standard 26 | else 27 | yes | unminimize 28 | fi 29 | 30 | apt $apt_arg install net-tools openssh-server dialog cpufrequtils haveged parted u-boot-tools 31 | apt -f $apt_arg install 32 | apt $apt_arg purge irqbalance ureadahead unattended-upgrades && apt $apt_arg autoremove 33 | apt clean 34 | 35 | systemctl enable systemd-networkd 36 | systemctl disable ondemand 37 | systemctl set-default multi-user.target 38 | 39 | cat < ./etc/default/cpufrequtils 40 | ENABLE=true 41 | GOVERNOR=ondemand 42 | 43 | EOF 44 | 45 | cat < ./etc/netplan/default.yaml 46 | network: 47 | version: 2 48 | renderer: networkd 49 | ethernets: 50 | eth0: 51 | dhcp4: yes 52 | dhcp6: yes 53 | 54 | EOF 55 | 56 | cat < ./etc/udev/rules.d/99-hdparm.rules 57 | ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*",ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", RUN+="/sbin/hdparm -S 120 \$env{DEVNAME}" 58 | 59 | EOF 60 | 61 | echo "en_US.UTF-8 UTF-8" > ./etc/locale.gen 62 | locale-gen 63 | echo "LANG=en_US.UTF-8" > ./etc/default/locale 64 | ln -sf /usr/share/zoneinfo/Asia/Shanghai ./etc/localtime 65 | sed -i '/^#PermitRootLogin/cPermitRootLogin yes' ./etc/ssh/sshd_config 66 | sed -i '/^#NTP/cNTP=time1.aliyun.com 2001:470:0:50::2' ./etc/systemd/timesyncd.conf 67 | sed -i 's/ENABLED=1/ENABLED=0/' ./etc/default/motd-news 68 | echo "ttyMV0" >> ./etc/securetty 69 | echo "/dev/root / ext4 defaults,noatime,nodiratime,errors=remount-ro 0 1" >> ./etc/fstab 70 | echo "vm.zone_reclaim_mode=1" > ./etc/sysctl.d/99-vm-reclaim.conf 71 | echo "/dev/mtd1 0x0000 0x10000 0x10000" > ./etc/fw_env.config 72 | echo "catdrive" > ./etc/hostname 73 | echo "root:admin" |chpasswd 74 | 75 | rm -f ./etc/ssh/ssh_host_* 76 | rm -rf ./var/log/journal 77 | rm -rf ./var/cache 78 | rm -rf ./var/lib/apt/* 79 | rm -f ./usr/sbin/policy-rc.d 80 | rm -f ./var/lib/dbus/machine-id 81 | : > ./etc/machine-id 82 | 83 | umount /dev/pts 84 | umount /dev 85 | umount /sys 86 | umount /proc 87 | 88 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | KERNEL_BSP := https://github.com/hanwckf/linux-marvell/releases/download 2 | RELEASE_TAG = v2019-9-16-1 3 | DTB := armada-3720-catdrive.dtb 4 | 5 | DTB_URL := $(KERNEL_BSP)/$(RELEASE_TAG)/$(DTB) 6 | KERNEL_URL := $(KERNEL_BSP)/$(RELEASE_TAG)/Image 7 | KMOD_URL := $(KERNEL_BSP)/$(RELEASE_TAG)/modules.tar.xz 8 | 9 | TARGETS := debian archlinux alpine ubuntu 10 | 11 | DL := dl 12 | DL_KERNEL := $(DL)/kernel/$(RELEASE_TAG) 13 | OUTPUT := output 14 | 15 | CURL := curl -O -L 16 | download = ( mkdir -p $(1) && cd $(1) ; $(CURL) $(2) ) 17 | 18 | help: 19 | @echo "Usage: make build_[system1]=y build_[system2]=y build" 20 | @echo "available system: $(TARGETS)" 21 | 22 | build: $(TARGETS) 23 | 24 | clean: $(TARGETS:%=%_clean) 25 | rm -f $(RESCUE_ROOTFS) 26 | 27 | dl_kernel: $(DL_KERNEL)/$(DTB) $(DL_KERNEL)/Image $(DL_KERNEL)/modules.tar.xz 28 | 29 | $(DL_KERNEL)/$(DTB): 30 | $(call download,$(DL_KERNEL),$(DTB_URL)) 31 | 32 | $(DL_KERNEL)/Image: 33 | $(call download,$(DL_KERNEL),$(KERNEL_URL)) 34 | 35 | $(DL_KERNEL)/modules.tar.xz: 36 | $(call download,$(DL_KERNEL),$(KMOD_URL)) 37 | 38 | ALPINE_BRANCH := v3.10 39 | ALPINE_VERSION := 3.10.4 40 | ALPINE_PKG := alpine-minirootfs-$(ALPINE_VERSION)-aarch64.tar.gz 41 | RESCUE_ROOTFS := tools/rescue/rescue-alpine-catdrive-$(ALPINE_VERSION)-aarch64.tar.xz 42 | 43 | ifneq ($(TRAVIS),) 44 | ALPINE_URL_BASE := http://dl-cdn.alpinelinux.org/alpine/$(ALPINE_BRANCH)/releases/aarch64 45 | else 46 | ALPINE_URL_BASE := https://mirrors.huaweicloud.com/alpine/$(ALPINE_BRANCH)/releases/aarch64 47 | endif 48 | 49 | alpine_dl: dl_kernel $(DL)/$(ALPINE_PKG) 50 | 51 | $(DL)/$(ALPINE_PKG): 52 | $(call download,$(DL),$(ALPINE_URL_BASE)/$(ALPINE_PKG)) 53 | 54 | alpine_clean: 55 | 56 | $(RESCUE_ROOTFS): 57 | @[ ! -f $(RESCUE_ROOTFS) ] && make rescue 58 | 59 | rescue: alpine_dl 60 | sudo BUILD_RESCUE=y ./build-alpine.sh release $(DL)/$(ALPINE_PKG) $(DL_KERNEL) - 61 | 62 | ifeq ($(build_alpine),y) 63 | alpine: alpine_dl $(RESCUE_ROOTFS) 64 | sudo ./build-alpine.sh release $(DL)/$(ALPINE_PKG) $(DL_KERNEL) $(RESCUE_ROOTFS) 65 | 66 | else 67 | alpine: 68 | endif 69 | 70 | ARCHLINUX_PKG := ArchLinuxARM-aarch64-latest.tar.gz 71 | ifneq ($(TRAVIS),) 72 | ARCHLINUX_URL_BASE := http://os.archlinuxarm.org/os 73 | else 74 | ARCHLINUX_URL_BASE := https://mirrors.163.com/archlinuxarm/os 75 | endif 76 | 77 | archlinux_dl: dl_kernel $(DL)/$(ARCHLINUX_PKG) 78 | 79 | $(DL)/$(ARCHLINUX_PKG): 80 | $(call download,$(DL),$(ARCHLINUX_URL_BASE)/$(ARCHLINUX_PKG)) 81 | 82 | archlinux_clean: 83 | rm -f $(DL)/$(ARCHLINUX_PKG) 84 | 85 | ifeq ($(build_archlinux),y) 86 | archlinux: archlinux_dl $(RESCUE_ROOTFS) 87 | sudo ./build-archlinux.sh release $(DL)/$(ARCHLINUX_PKG) $(DL_KERNEL) $(RESCUE_ROOTFS) 88 | else 89 | archlinux: 90 | endif 91 | 92 | UBUNTU_PKG := ubuntu-base-18.04.4-base-arm64.tar.gz 93 | ifneq ($(TRAVIS),) 94 | UBUNTU_URL_BASE := http://cdimage.ubuntu.com/ubuntu-base/releases/bionic/release 95 | else 96 | UBUNTU_URL_BASE := https://mirrors.huaweicloud.com/ubuntu-cdimage/ubuntu-base/releases/bionic/release 97 | endif 98 | 99 | ubuntu_dl: dl_kernel $(DL)/$(UBUNTU_PKG) 100 | 101 | $(DL)/$(UBUNTU_PKG): 102 | $(call download,$(DL),$(UBUNTU_URL_BASE)/$(UBUNTU_PKG)) 103 | 104 | ubuntu_clean: 105 | 106 | ifeq ($(build_ubuntu),y) 107 | ubuntu: ubuntu_dl $(RESCUE_ROOTFS) 108 | sudo ./build-ubuntu.sh release $(DL)/$(UBUNTU_PKG) $(DL_KERNEL) $(RESCUE_ROOTFS) 109 | else 110 | ubuntu: 111 | endif 112 | 113 | ifeq ($(build_debian),y) 114 | debian: dl_kernel $(RESCUE_ROOTFS) 115 | sudo ./build-debian.sh release - $(DL_KERNEL) $(RESCUE_ROOTFS) 116 | 117 | else 118 | debian: 119 | endif 120 | debian_clean: 121 | -------------------------------------------------------------------------------- /common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DISK="rootfs.img" 4 | 5 | func_generate() { 6 | local rootfs=$1 7 | local kdir=$2 8 | 9 | [ "$os" != "debian" ] && [ ! -f "$rootfs" ] && echo "${os} rootfs file not found!" && return 1 10 | [ ! -d "$kdir" ] && echo "kernel dir not found!" && return 1 11 | 12 | # create rootfs mbr img 13 | mkdir -p ${tmpdir} 14 | echo "create mbr rootfs, size: ${rootsize}M" 15 | dd if=/dev/zero bs=1M status=none conv=fsync count=$rootsize of=$tmpdir/$DISK 16 | parted -s $tmpdir/$DISK -- mktable msdos 17 | parted -s $tmpdir/$DISK -- mkpart p ext4 8192s -1s 18 | 19 | # get PTUUID 20 | eval `blkid -o export -s PTUUID $tmpdir/$DISK` 21 | 22 | # mkfs.ext4 23 | echo "mount loopdev to format ext4 rootfs" 24 | modprobe loop 25 | lodev=$(losetup -f) 26 | losetup -P $lodev $tmpdir/$DISK 27 | mkfs.ext4 -q -m 2 ${lodev}"p1" 28 | 29 | # mount rootfs 30 | echo "mount rootfs" 31 | mkdir -p $rootfs_mount_point 32 | mount ${lodev}"p1" $rootfs_mount_point 33 | 34 | # extract rootfs 35 | if [ "$os" = "debian" ]; then 36 | generate_rootfs $rootfs_mount_point 37 | else 38 | echo "extract ${os} rootfs($rootfs) to $rootfs_mount_point" 39 | if [ "$os" = "archlinux" ]; then 40 | tarbin="bsdtar" 41 | else 42 | tarbin="tar" 43 | fi 44 | $tarbin -xpf $rootfs -C $rootfs_mount_point 45 | fi 46 | 47 | # configure binfmt 48 | echo "configure binfmt to chroot" 49 | modprobe binfmt_misc 50 | if [ -e /proc/sys/fs/binfmt_misc/register ]; then 51 | echo -1 > /proc/sys/fs/binfmt_misc/status 52 | echo ":arm64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:OC" > /proc/sys/fs/binfmt_misc/register 53 | echo "copy $qemu_static to $rootfs_mount_point/usr/bin/" 54 | cp $qemu_static $rootfs_mount_point/usr/bin/qemu-aarch64-static 55 | else 56 | echo "Could not configure binfmt for qemu!" && exit 1 57 | fi 58 | 59 | cp ./tools/${os}/init.sh $rootfs_mount_point/init.sh 60 | 61 | # prepare for chroot 62 | chroot_prepare 63 | 64 | # chroot 65 | echo "chroot to ${os} rootfs" 66 | eval $(ext_init_param) LANG=C LC_ALL=C chroot $rootfs_mount_point /init.sh 67 | 68 | # clean rootfs 69 | rm -f $rootfs_mount_point/init.sh 70 | [ -n "$qemu" ] && rm -f $rootfs_mount_point/$qemu || rm -f $rootfs_mount_point/usr/bin/qemu-aarch64-static 71 | 72 | # add services 73 | add_services 74 | 75 | # add /boot 76 | echo "add /boot" 77 | mkdir -p $rootfs_mount_point/boot 78 | cp -f $kdir/Image $rootfs_mount_point/boot 79 | cp -f $kdir/$DTB $rootfs_mount_point/boot 80 | cp -f ./tools/boot/uEnv.txt $rootfs_mount_point/boot 81 | if [ "$BUILD_RESCUE" != "y" ]; then 82 | echo "rootdev=PARTUUID=${PTUUID}-01" >> $rootfs_mount_point/boot/uEnv.txt 83 | fi 84 | cp -f ./tools/boot/boot.cmd $rootfs_mount_point/boot 85 | mkimage -C none -A arm -T script -d $rootfs_mount_point/boot/boot.cmd $rootfs_mount_point/boot/boot.scr 86 | 87 | # add /lib/modules 88 | echo "add /lib/modules" 89 | tar --no-same-owner -xf $kdir/modules.tar.xz --strip-components 1 -C $rootfs_mount_point/lib 90 | 91 | # chroot post 92 | chroot_post 93 | 94 | umount -l $rootfs_mount_point 95 | losetup -d $lodev 96 | 97 | echo "generate ${os} rootfs done" 98 | 99 | } 100 | 101 | func_release() { 102 | local rootfs=$1 103 | local kdir=$2 104 | local rootfs_rescue=$3 105 | 106 | # generate tmp/rootfs.img 107 | func_generate $rootfs $kdir 108 | 109 | img_name=$(gen_new_name $rootfs) 110 | 111 | if [ "$BUILD_RESCUE" = "y" ]; then 112 | offset=$(sfdisk -J $tmpdir/$DISK |jq .partitiontable.partitions[0].start) 113 | mkdir -p $rootfs_mount_point 114 | mount -o loop,offset=$((offset*512)) $tmpdir/$DISK $rootfs_mount_point 115 | tar -cJpf ./tools/rescue/rescue-${img_name}.tar.xz -C $rootfs_mount_point . 116 | umount -l $rootfs_mount_point 117 | else 118 | [ ! -f $rootfs_rescue ] && echo "rescue rootfs not found!" && return 1 119 | 120 | # calc size 121 | img_size=$((`stat $tmpdir/$DISK -c %s`/1024/1024)) 122 | img_size=$((img_size+300)) 123 | 124 | echo "create mbr rescue img, size: ${img_size}M" 125 | dd if=/dev/zero bs=1M status=none conv=fsync count=$img_size of=$tmpdir/${img_name}.img 126 | parted -s $tmpdir/${img_name}.img -- mktable msdos 127 | parted -s $tmpdir/${img_name}.img -- mkpart p ext4 8192s -1s 128 | 129 | # get PTUUID 130 | eval `blkid -o export -s PTUUID $tmpdir/${img_name}.img` 131 | 132 | # mkfs.ext4 133 | echo "mount loopdev to format ext4 rescue img" 134 | modprobe loop 135 | lodev=$(losetup -f) 136 | losetup -P $lodev $tmpdir/${img_name}.img 137 | mkfs.ext4 -q -m 2 ${lodev}"p1" 138 | 139 | # mount rescue rootfs 140 | echo "mount rescue rootfs" 141 | mkdir -p $rootfs_mount_point 142 | mount ${lodev}"p1" $rootfs_mount_point 143 | 144 | # extract rescue rootfs 145 | echo "extract rescue rootfs($rootfs_rescue) to $rootfs_mount_point" 146 | tar -xpf $rootfs_rescue -C $rootfs_mount_point 147 | cp -f ./tools/rescue/emmc-install.sh $rootfs_mount_point/sbin 148 | echo "rootdev=PARTUUID=${PTUUID}-01" >> $rootfs_mount_point/boot/uEnv.txt 149 | 150 | echo "add ${os} img to rescue rootfs" 151 | mv -f $tmpdir/$DISK $rootfs_mount_point/root 152 | 153 | umount -l $rootfs_mount_point 154 | losetup -d $lodev 155 | 156 | mkdir -p $output/${os} 157 | mv -f $tmpdir/${img_name}.img $output/$os 158 | 159 | if [ -n "$TRAVIS_TAG" ]; then 160 | mkdir -p $output/release 161 | xz -T0 -v -f $output/$os/${img_name}.img 162 | mv $output/$os/${img_name}.img.xz $output/release 163 | fi 164 | fi 165 | 166 | rm -rf $tmpdir 167 | 168 | echo "release ${os} image done" 169 | } 170 | 171 | case "$1" in 172 | generate) 173 | func_generate "$2" "$3" 174 | ;; 175 | release) 176 | func_release "$2" "$3" "$4" 177 | ;; 178 | *) 179 | echo "Usage: $0 { generate [rootfs] [KDIR] | release [rootfs] [KDIR] [RESCUE_ROOTFS] }" 180 | exit 1 181 | ;; 182 | esac 183 | --------------------------------------------------------------------------------