-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-archlinux-img-for-helios4.sh
executable file
·173 lines (137 loc) · 6.31 KB
/
build-archlinux-img-for-helios4.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Bash script creating an Arch Linux ARM image for the Helios4 NAS.
#
# Author: Gontran Baerts
# Repository: https://github.com/gbcreation/linux-helios4
# License: MIT
#
set -e
# Configuration
DOWNLOADER="aria2c --continue=true -x 4"
IMG_DIR="./"
IMG_DIR=`readlink -f "${IMG_DIR}"`
IMG_FILE="ArchLinuxARM-helios4-$(date +%Y-%m-%d).img"
IMG_SIZE="2G"
MOUNT_DIR="./img"
ALARM_ROOTFS="http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz"
LINUX_HELIOS4_VERSION=`wget -q -O - https://api.github.com/repos/gbcreation/linux-helios4/releases/latest | sed -En '/tag_name/{s/.*"([^"]+)".*/\1/;p}'`
sources=("${ALARM_ROOTFS}"
'https://raw.githubusercontent.com/armbian/build/master/packages/bsp/helios4/90-helios4-hwmon.rules'
'https://raw.githubusercontent.com/armbian/build/master/packages/bsp/helios4/fancontrol_pwm-fan-mvebu-next.conf'
'https://raw.githubusercontent.com/armbian/build/master/packages/bsp/helios4/mdadm-fault-led.sh'
'https://raw.githubusercontent.com/armbian/build/master/packages/bsp/helios4/helios4-wol.service'
"https://github.com/gbcreation/linux-helios4/releases/download/${LINUX_HELIOS4_VERSION}/linux-helios4-${LINUX_HELIOS4_VERSION}-armv7h.pkg.tar.xz")
md5sums=('1ac50e1b58271e2789215c526cf1b9b9'
'f0162acfa70e2d981c11ec4b0242d5bd'
'7e1423c3e3b8c3c8df599a54881b5036'
'0a5bfbea2f1d65b936da6df4085ee5f2'
'2fb1b8a9e8193ac8ff945c6b9e4706e5'
`wget -q -O - https://github.com/gbcreation/linux-helios4/releases/download/${LINUX_HELIOS4_VERSION}/md5sums.txt | sed -En "/linux-helios4-${LINUX_HELIOS4_VERSION}/{s/^([0-9a-f]{32}).*$/\1/;p}"`)
echo_step () {
echo -e "\e[1;32m ${@} \e[0m\n"
}
echo_step "\nArchLinux ARM image builder for Helios4 NAS"
which qemu-arm-static >/dev/null 2>&1 || {
echo 'This script needs qemu-arm-static to work. Install qemu-user-static or qemu-user-static-bin from the AUR.'
exit 1
}
if [[ $EUID != 0 ]]; then
echo This script requires root privileges, trying to use sudo
sudo "$0"
exit $?
fi
echo_step Install script dependencies...
pacman -Sy --needed --noconfirm arch-install-scripts arm-none-eabi-gcc uboot-tools
for i in ${!sources[*]}; do
echo_step Download ${sources[i]}...
${DOWNLOADER} "${sources[i]}"
if [ "`md5sum ${sources[i]##*/} | cut -d ' ' -f1`" != "${md5sums[i]}" ]; then
echo Wrong MD5 sum for ${sources[i]}.
exit 1
fi
done
echo_step Create ${IMG_DIR}/${IMG_FILE} image file...
dd if=/dev/zero of="${IMG_DIR}/${IMG_FILE}" bs=1 count=0 seek=${IMG_SIZE}
echo_step Create partition...
fdisk "${IMG_DIR}/${IMG_FILE}" <<EOF
o
n
p
1
w
EOF
echo_step Mount loop image...
LOOP_MOUNT=`losetup --partscan --show --find "${IMG_DIR}/${IMG_FILE}"`
echo_step Format partition ${LOOP_MOUNT}p1...
# mkfs.ext4 -F -L alarm-helios4 "${LOOP_MOUNT}p1"
mkfs.ext4 -qF -L alarm-helios4 "${LOOP_MOUNT}p1"
echo_step Mount image partition ${LOOP_MOUNT}p1 to ${MOUNT_DIR}...
mkdir -p "${MOUNT_DIR}"
mount "${LOOP_MOUNT}p1" "${MOUNT_DIR}"
echo_step Extract ${ALARM_ROOTFS##*/} to ${MOUNT_DIR}...
bsdtar -xpf "${ALARM_ROOTFS##*/}" -C "${MOUNT_DIR}"
echo_step Copy hwmon to fix device mapping...
sed -e 's/armada_thermal/f10e4078.thermal/' 90-helios4-hwmon.rules > ${MOUNT_DIR}/etc/udev/rules.d/90-helios4-hwmon.rules
echo_step Copy linux-helios4 packages to ${MOUNT_DIR}/root...
cp linux-helios4-*-armv7h.pkg.tar.xz ${MOUNT_DIR}/root
echo_step Copy helios4-wol.service to ${MOUNT_DIR}/usr/lib/systemd/system/...
cp helios4-wol.service ${MOUNT_DIR}/usr/lib/systemd/system/
echo_step Copy `which qemu-arm-static` to ${MOUNT_DIR}/usr/bin...
cp `which qemu-arm-static` ${MOUNT_DIR}/usr/bin
echo_step Register qemu-arm-static as ARM interpreter in the kernel...
[ ! -f /proc/sys/fs/binfmt_misc/register ] && echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:CF' > /proc/sys/fs/binfmt_misc/register
echo_step Initialize pacman-key, update ARM system and install lm_sensors...
arch-chroot ${MOUNT_DIR} bash -c "
pacman-key --init &&
pacman-key --populate archlinuxarm &&
pacman -Syu --noconfirm --ignore linux-armv7 &&
(yes | pacman -U /root/linux-helios4-${LINUX_HELIOS4_VERSION}-armv7h.pkg.tar.xz) &&
pacman -S --noconfirm lm_sensors ethtool &&
systemctl enable fancontrol.service &&
systemctl --no-reload enable helios4-wol.service &&
echo helios4 > /etc/hostname
"
echo_step Remove linux-helios4 packages to ${MOUNT_DIR}/root...
rm -f ${MOUNT_DIR}/root/linux-helios4-*-armv7h.pkg.tar.xz
echo_step Remove qemu-arm-static from ${MOUNT_DIR}/usr/bin...
rm -f ${MOUNT_DIR}/usr/bin/qemu-arm-static
echo_step Copy fancontrol config...
cp fancontrol_pwm-fan-mvebu-next.conf ${MOUNT_DIR}/etc/fancontrol
echo_step Configure loading of lm75 kernel module on boot...
echo "lm75" > ${MOUNT_DIR}/etc/modules-load.d/lm75.conf
echo_step Copy mdadm-fault-led script and modify mdadm configuration...
cp mdadm-fault-led.sh ${MOUNT_DIR}/usr/sbin
echo "PROGRAM /usr/sbin/mdadm-fault-led.sh" >> ${MOUNT_DIR}/etc/mdadm.conf
echo_step Copy u-boot boot.cmd to ${MOUNT_DIR}/boot...
cat << 'EOF' > "${MOUNT_DIR}/boot/boot.cmd"
setenv eth1addr "00:50:43:25:fb:84"
part uuid ${devtype} ${devnum}:${bootpart} uuid
setenv bootargs console=${console} root=PARTUUID=${uuid} rw rootwait loglevel=1
load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} /boot/zImage
load ${devtype} ${devnum}:${bootpart} ${fdt_addr_r} /boot/dtbs/${fdtfile}
load ${devtype} ${devnum}:${bootpart} ${ramdisk_addr_r} /boot/initramfs-linux.img
bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
EOF
echo_step Compile boot.cmd...
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Helios4 boot script" -d "${MOUNT_DIR}/boot/boot.cmd" "${MOUNT_DIR}/boot/boot.scr"
echo_step Unmount image partition...
sync
umount "${MOUNT_DIR}"
echo_step Build U-Boot...
[ ! -d "u-boot" ] && git clone --depth=1 https://github.com/helios-4/u-boot.git -b helios4
cd u-boot
[ ! -f u-boot-spl.kwb ] && {
export ARCH=arm
export CROSS_COMPILE=arm-none-eabi-
make mrproper
make helios4_defconfig
make -j${nproc}
}
echo_step Copy u-boot to ${LOOP_MOUNT}...
dd if=u-boot-spl.kwb of="${LOOP_MOUNT}" bs=512 seek=1
cd -
echo_step Unmount loop partition...
sync
losetup -d "${LOOP_MOUNT}"
echo_step done