-
Notifications
You must be signed in to change notification settings - Fork 6
/
linux-image.sh
executable file
·128 lines (118 loc) · 3.93 KB
/
linux-image.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -x
export PATH=$PWD/gcc-linaro-6.4.1-2017.08-x86_64_aarch64-linux-gnu/bin:$PATH
#RAM=1
RAM=0
#PROXY="http://127.0.0.1:3142"
PROXY=""
IMAGE_FOLDER="img/"
IMAGE_VERSION="linux-libretech"
IMAGE_DEVICE_TREE="amlogic/meson-gxl-s905x-libretech-cc"
if [ ! -z "$1" ]; then
IMAGE_VERSION="$1"
fi
if [ ! -z "$2" ]; then
IMAGE_DEVICE_TREE="$2"
fi
if [ ! -f "$IMAGE_VERSION/arch/arm64/boot/dts/$IMAGE_DEVICE_TREE.dts" ]; then
echo "Missing Device Tree"
exit 1
fi
set -eux -o pipefail
IMAGE_LINUX_LOADADDR="0x1080000"
IMAGE_LINUX_VERSION=`head -n 1 $IMAGE_VERSION/include/config/kernel.release | xargs echo -n`
IMAGE_FILE_SUFFIX="$(date +%F)"
IMAGE_FILE_NAME="aml-s905x-cc-ubuntu-xenial-${IMAGE_VERSION}-${IMAGE_LINUX_VERSION}-${IMAGE_FILE_SUFFIX}.img"
if [ $RAM -ne 0 ]; then
IMAGE_FOLDER="ram/"
fi
mkdir -p "$IMAGE_FOLDER"
if [ $RAM -ne 0 ]; then
mount -t tmpfs -o size=1G tmpfs $IMAGE_FOLDER
fi
truncate -s 4G "${IMAGE_FOLDER}${IMAGE_FILE_NAME}"
fdisk "${IMAGE_FOLDER}${IMAGE_FILE_NAME}" <<EOF
o
n
p
1
2048
524287
a
t
b
n
p
2
524288
p
w
EOF
IMAGE_LOOP_DEV="$(losetup --show -f ${IMAGE_FOLDER}${IMAGE_FILE_NAME})"
IMAGE_LOOP_DEV_BOOT="${IMAGE_LOOP_DEV}p1"
IMAGE_LOOP_DEV_ROOT="${IMAGE_LOOP_DEV}p2"
partprobe "${IMAGE_LOOP_DEV}"
mkfs.vfat -n BOOT "${IMAGE_LOOP_DEV_BOOT}"
mkfs.btrfs -f -L ROOT "${IMAGE_LOOP_DEV_ROOT}"
mkdir -p p1 p2
mount "${IMAGE_LOOP_DEV_BOOT}" p1
mount "${IMAGE_LOOP_DEV_ROOT}" p2
btrfs subvolume create p2/@
sync
umount p2
mount -o compress=lzo,noatime,subvol=@ "${IMAGE_LOOP_DEV_ROOT}" p2
PATH=$PWD/gcc/bin:$PATH make -C ${IMAGE_VERSION} ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- install INSTALL_PATH=$PWD/p1/
cp ${IMAGE_VERSION}/arch/arm64/boot/Image p1/Image
mkdir -p p1/$(dirname $IMAGE_DEVICE_TREE)
cp ${IMAGE_VERSION}/arch/arm64/boot/dts/$IMAGE_DEVICE_TREE.dtb p1/$(dirname $IMAGE_DEVICE_TREE)
PATH=$PWD/gcc/bin:$PATH make -C ${IMAGE_VERSION} ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- headers_install INSTALL_HDR_PATH=$PWD/p2/usr/
PATH=$PWD/gcc/bin:$PATH make -C ${IMAGE_VERSION} ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=$PWD/p2/
#PATH=$PWD/gcc/bin:$PATH make -C ${IMAGE_VERSION} ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- firmware_install INSTALL_FW_PATH=$PWD/p2/
mkdir -p p2/etc/apt/apt.conf.d p2/etc/dpkg/dpkg.cfg.d
echo "force-unsafe-io" > "p2/etc/dpkg/dpkg.cfg.d/dpkg-unsafe-io"
mkdir -p p2/usr/bin
cp $(which "qemu-aarch64-static") p2/usr/bin
if [ -n "$PROXY" ] ; then
http_proxy="$PROXY" debootstrap --arch arm64 --foreign xenial p2
http_proxy="$PROXY" chroot p2 /debootstrap/debootstrap --second-stage
else
debootstrap --arch arm64 --foreign xenial p2
chroot p2 /debootstrap/debootstrap --second-stage
fi
tee p2/etc/apt/sources.list.d/ubuntu-ports.list <<EOF
deb http://ports.ubuntu.com/ubuntu-ports/ xenial universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main universe multiverse restricted
EOF
tee p2/etc/fstab <<EOF
/dev/root / btrfs defaults,compress=lzo,noatime,subvol=@ 0 1
EOF
if [ -n "$PROXY" ] ; then
tee "p2/etc/apt/apt.conf.d/30proxy" <<EOF
Acquire::http::proxy "http://127.0.0.1:3142";
EOF
fi
cp stage2.sh p2/root
mount -o bind /dev p2/dev
mount -o bind /dev/pts p2/dev/pts
chroot p2 /root/stage2.sh
umount p2/dev/pts
umount p2/dev
rm p2/root/stage2.sh
if [ -n "$PROXY" ] ; then
rm p2/etc/apt/apt.conf.d/30proxy
fi
rm p2/etc/dpkg/dpkg.cfg.d/dpkg-unsafe-io
binary-amlogic/mkimage -C none -A arm -T script -d binary-amlogic/boot.cmd p1/boot.scr
btrfs filesystem defragment -f -r p2
umount p2
umount p1
dd if=binary-amlogic/u-boot.bin.sd.bin of="${IMAGE_LOOP_DEV}" conv=fsync bs=1 count=442
dd if=binary-amlogic/u-boot.bin.sd.bin of="${IMAGE_LOOP_DEV}" conv=fsync bs=512 skip=1 seek=1
losetup -d "${IMAGE_LOOP_DEV}"
mv "${IMAGE_FOLDER}${IMAGE_FILE_NAME}" "${IMAGE_FILE_NAME}"
if [ $RAM -ne 0 ]; then
umount "${IMAGE_FOLDER}"
fi
rmdir "${IMAGE_FOLDER}"
rmdir p1 p2