##// END OF EJS Templates
massive refactor and bugfes
burnbabyburn -
r310:b38cfe8b34fd
parent child
Show More
@@ -1,68 +1,48
1 1 #
2 2 # Setup APT repositories
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup APT proxy configuration
9 9 if [ -z "$APT_PROXY" ] ; then
10 10 install_readonly files/apt/10proxy "${ETC_DIR}/apt/apt.conf.d/10proxy"
11 11 sed -i "s/\"\"/\"${APT_PROXY}\"/" "${ETC_DIR}/apt/apt.conf.d/10proxy"
12 12 fi
13 13
14 14 if [ "$BUILD_KERNEL" = false ] ; then
15 if [ "$RPI_MODEL" = 2 ] ; then
16 # Install APT pinning configuration for flash-kernel package
17 install_readonly files/apt/flash-kernel "${ETC_DIR}/apt/preferences.d/flash-kernel"
18
19 # Install APT sources.list
20 install_readonly files/apt/sources.list "${ETC_DIR}/apt/sources.list"
21 echo "deb ${COLLABORA_URL} ${RELEASE} rpi2" >> "${ETC_DIR}/apt/sources.list"
22
23 # Upgrade collabora package index and install collabora keyring
24 chroot_exec apt-get -qq -y update
25 chroot_exec apt-get -qq -y --allow-unauthenticated install collabora-obs-archive-keyring
26 # if RPI_MODEL = [0] || [1] || [1P]
27 else
28 echo "error: ATM there is just a precompiled kernel for model 2";
29 # insert apt configuration for precompiled kernel repository for RPI 0,1,1P
30 fi
31
15 echo "Downloading precompiled kernel"
16 echo "error: not configured"
17 exit 1;
32 18 else # BUILD_KERNEL=true
33 19 #autconfigure best apt server to not spam ftp.debian.org
34 rm files/apt/sources.list
20 #rm files/apt/sources.list
35 21 #netselect-apt does not know buster yet
36 22 if [ "$RELEASE" = "buster" ] ; then
37 RLS = "testing"
23 RELEASE=${RELEASE:=testing}
38 24 fi
39
40 if [ "$ENABLE_NONFREE" ] ; then
41 netselect-apt --arch "$RELEASE_ARCH" --sources --nonfree --outfile "${ETC_DIR}/apt/sources.list" -d "$RELEASE"
42 else
43 netselect-apt --arch "$RELEASE_ARCH" --sources --nonfree --outfile "${ETC_DIR}/apt/sources.list" -d "$RELEASE"
44 fi
45 fi
46
47 # Allow the installation of non-free Debian packages
25 netselect_string=${netselect_string:=""}
48 26 if [ "$ENABLE_NONFREE" = true ] ; then
49 sed -i "s/ contrib/ contrib non-free/" "${ETC_DIR}/apt/sources.list"
27 netselect-apt --arch "$RELEASE_ARCH" --sources "$netselect_string" --outfile "${ETC_DIR}/apt/sources.list" -d "$RLS"
28 fi
29 netselect-apt --arch "$RELEASE_ARCH" --sources "$netselect_string" --outfile "${ETC_DIR}/apt/sources.list" -d "$RLS"
50 30 fi
51 31
52 32 # Upgrade package index and update all installed packages and changed dependencies
53 33 chroot_exec apt-get -qq -y update
54 34 chroot_exec apt-get -qq -y -u dist-upgrade
55 35
56 36 if [ "$APT_INCLUDES_LATE" ] ; then
57 chroot_exec apt-get -qq -y install $(echo $APT_INCLUDES_LATE |tr , ' ')
37 chroot_exec apt-get -qq -y install "$(echo "$APT_INCLUDES_LATE" |tr , ' ')"
58 38 fi
59 39
60 40 if [ -d packages ] ; then
61 41 for package in packages/*.deb ; do
62 cp $package ${R}/tmp
63 chroot_exec dpkg --unpack /tmp/$(basename $package)
42 cp "$package" "${R}"/tmp
43 chroot_exec dpkg --unpack /tmp/"$(basename "$package")"
64 44 done
65 45 fi
66 46 chroot_exec apt-get -qq -y -f install
67 47
68 48 chroot_exec apt-get -qq -y check
@@ -1,58 +1,59
1 1 #
2 2 # Setup Locales and keyboard settings
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup timezone
9 echo ${TIMEZONE} > "${ETC_DIR}/timezone"
9 echo "${TIMEZONE}" > "${ETC_DIR}/timezone"
10 10 chroot_exec dpkg-reconfigure -f noninteractive tzdata
11 11
12 12 # Install and setup default locale and keyboard configuration
13 if [ $(echo "$APT_INCLUDES" | grep ",locales") ] ; then
13
14 if [ "$(echo "$APT_INCLUDES" | grep ",locales")" ] ; then
14 15 # Set locale choice in debconf db, even though dpkg-reconfigure ignores and overwrites them due to some bug
15 16 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684134 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685957
16 17 # ... so we have to set locales manually
17 18 if [ "$DEFLOCAL" = "en_US.UTF-8" ] ; then
18 19 chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8" | debconf-set-selections
19 20 else
20 21 # en_US.UTF-8 should be available anyway : https://www.debian.org/doc/manuals/debian-reference/ch08.en.html#_the_reconfiguration_of_the_locale
21 22 chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8" | debconf-set-selections
22 23 sed -i "/en_US.UTF-8/s/^#//" "${ETC_DIR}/locale.gen"
23 24 fi
24 25
25 26 sed -i "/${DEFLOCAL}/s/^#//" "${ETC_DIR}/locale.gen"
26 27 chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections
27 28 chroot_exec locale-gen
28 29 chroot_exec update-locale LANG="${DEFLOCAL}"
29 30
30 31 # Install and setup default keyboard configuration
31 32 if [ "$XKB_MODEL" != "pc105" ] ; then
32 33 sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKB_MODEL}\"/" "${ETC_DIR}/default/keyboard"
33 34 fi
34 35 if [ "$XKB_LAYOUT" != "us" ] ; then
35 36 sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKB_LAYOUT}\"/" "${ETC_DIR}/default/keyboard"
36 37 fi
37 38 if [ "$XKB_VARIANT" != "" ] ; then
38 39 sed -i "s/^XKBVARIANT.*/XKBVARIANT=\"${XKB_VARIANT}\"/" "${ETC_DIR}/default/keyboard"
39 40 fi
40 41 if [ "$XKB_OPTIONS" != "" ] ; then
41 42 sed -i "s/^XKBOPTIONS.*/XKBOPTIONS=\"${XKB_OPTIONS}\"/" "${ETC_DIR}/default/keyboard"
42 43 fi
43 44 chroot_exec dpkg-reconfigure -f noninteractive keyboard-configuration
44 45
45 46 # Install and setup font console
46 47 case "${DEFLOCAL}" in
47 48 *UTF-8)
48 49 sed -i 's/^CHARMAP.*/CHARMAP="UTF-8"/' "${ETC_DIR}/default/console-setup"
49 50 ;;
50 51 *)
51 52 sed -i 's/^CHARMAP.*/CHARMAP="guess"/' "${ETC_DIR}/default/console-setup"
52 53 ;;
53 54 esac
54 55 chroot_exec dpkg-reconfigure -f noninteractive console-setup
55 56 else # (no locales were installed)
56 57 # Install POSIX default locale
57 58 install_readonly files/locales/locale "${ETC_DIR}/default/locale"
58 59 fi
@@ -1,270 +1,257
1 1 #
2 2 # Build and Setup RPi2/3 Kernel
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Fetch and build latest raspberry kernel
9 9 if [ "$BUILD_KERNEL" = true ] ; then
10 10 # Setup source directory
11 11 mkdir -p "${R}/usr/src/linux"
12 12
13 13 # Copy existing kernel sources into chroot directory
14 14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 15 # Copy kernel sources and include hidden files
16 16 cp -r "${KERNELSRC_DIR}/". "${R}/usr/src/linux"
17 17
18 18 # Clean the kernel sources
19 19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 20 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 21 fi
22 22 else # KERNELSRC_DIR=""
23 23 # Create temporary directory for kernel sources
24 24 temp_dir=$(as_nobody mktemp -d)
25 25
26 26 # Fetch current RPi2/3 kernel sources
27 27 if [ -z "${KERNEL_BRANCH}" ] ; then
28 28 as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux
29 29 else
30 30 as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux
31 31 fi
32 32
33 33 # Copy downloaded kernel sources
34 34 cp -r "${temp_dir}/linux/"* "${R}/usr/src/linux/"
35 35
36 36 # Remove temporary directory for kernel sources
37 37 rm -fr "${temp_dir}"
38 38
39 39 # Set permissions of the kernel sources
40 40 chown -R root:root "${R}/usr/src"
41 41 fi
42 42
43 43 # Calculate optimal number of kernel building threads
44 44 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
45 45 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
46 46 fi
47 47
48 48 # Configure and build kernel
49 49 if [ "$KERNELSRC_PREBUILT" = false ] ; then
50 50 # Remove device, network and filesystem drivers from kernel configuration
51 51 if [ "$KERNEL_REDUCE" = true ] ; then
52 52 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
53 53 sed -i\
54 54 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
55 55 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
56 56 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
57 57 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
58 58 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
59 59 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
60 60 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
61 61 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
62 62 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
63 63 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
64 64 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
65 65 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
66 66 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
67 67 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
68 68 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
69 69 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
70 70 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
71 71 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
72 72 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
73 73 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
74 74 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
75 75 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
76 76 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
77 77 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
78 78 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
79 79 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
80 80 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
81 81 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
82 82 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
83 83 "${KERNEL_DIR}/.config"
84 84 fi
85 85
86 86 if [ "$KERNELSRC_CONFIG" = true ] ; then
87 87 # Load default raspberry kernel configuration
88 88 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
89 89
90 90 # Set kernel configuration parameters to enable qemu emulation
91 91 if [ "$ENABLE_QEMU" = true ] ; then
92 echo "CONFIG_FHANDLE=y" >> ${KERNEL_DIR}/.config
93 echo "CONFIG_LBDAF=y" >> ${KERNEL_DIR}/.config
92 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
93 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
94 94
95 95 if [ "$ENABLE_CRYPTFS" = true ] ; then
96 echo "CONFIG_EMBEDDED=y" >> ${KERNEL_DIR}/.config
97 echo "CONFIG_EXPERT=y" >> ${KERNEL_DIR}/.config
98 echo "CONFIG_DAX=y" >> ${KERNEL_DIR}/.config
99 echo "CONFIG_MD=y" >> ${KERNEL_DIR}/.config
100 echo "CONFIG_BLK_DEV_MD=y" >> ${KERNEL_DIR}/.config
101 echo "CONFIG_MD_AUTODETECT=y" >> ${KERNEL_DIR}/.config
102 echo "CONFIG_BLK_DEV_DM=y" >> ${KERNEL_DIR}/.config
103 echo "CONFIG_BLK_DEV_DM_BUILTIN=y" >> ${KERNEL_DIR}/.config
104 echo "CONFIG_DM_CRYPT=y" >> ${KERNEL_DIR}/.config
105 echo "CONFIG_CRYPTO_BLKCIPHER=y" >> ${KERNEL_DIR}/.config
106 echo "CONFIG_CRYPTO_CBC=y" >> ${KERNEL_DIR}/.config
107 echo "CONFIG_CRYPTO_XTS=y" >> ${KERNEL_DIR}/.config
108 echo "CONFIG_CRYPTO_SHA512=y" >> ${KERNEL_DIR}/.config
109 echo "CONFIG_CRYPTO_MANAGER=y" >> ${KERNEL_DIR}/.config
96 echo "CONFIG_EMBEDDED=y" >> "${KERNEL_DIR}"/.config
97 echo "CONFIG_EXPERT=y" >> "${KERNEL_DIR}"/.config
98 echo "CONFIG_DAX=y" >> "${KERNEL_DIR}"/.config
99 echo "CONFIG_MD=y" >> "${KERNEL_DIR}"/.config
100 echo "CONFIG_BLK_DEV_MD=y" >> "${KERNEL_DIR}"/.config
101 echo "CONFIG_MD_AUTODETECT=y" >> "${KERNEL_DIR}"/.config
102 echo "CONFIG_BLK_DEV_DM=y" >> "${KERNEL_DIR}"/.config
103 echo "CONFIG_BLK_DEV_DM_BUILTIN=y" >> "${KERNEL_DIR}"/.config
104 echo "CONFIG_DM_CRYPT=y" >> "${KERNEL_DIR}"/.config
105 echo "CONFIG_CRYPTO_BLKCIPHER=y" >> "${KERNEL_DIR}"/.config
106 echo "CONFIG_CRYPTO_CBC=y" >> "${KERNEL_DIR}"/.config
107 echo "CONFIG_CRYPTO_XTS=y" >> "${KERNEL_DIR}"/.config
108 echo "CONFIG_CRYPTO_SHA512=y" >> "${KERNEL_DIR}"/.config
109 echo "CONFIG_CRYPTO_MANAGER=y" >> "${KERNEL_DIR}"/.config
110 110 fi
111 111 fi
112 112
113 113 # Copy custom kernel configuration file
114 if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then
115 cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config
114 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
115 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
116 116 fi
117 117
118 118 # Set kernel configuration parameters to their default values
119 119 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
120 120 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
121 121 fi
122 122
123 123 # Start menu-driven kernel configuration (interactive)
124 124 if [ "$KERNEL_MENUCONFIG" = true ] ; then
125 125 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
126 126 fi
127 127 fi
128 128
129 129 # Use ccache to cross compile the kernel
130 130 if [ "$KERNEL_CCACHE" = true ] ; then
131 131 cc="ccache ${CROSS_COMPILE}gcc"
132 132 else
133 133 cc="${CROSS_COMPILE}gcc"
134 134 fi
135 135
136 136 # Cross compile kernel and dtbs
137 make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
137 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
138 138
139 139 # Cross compile kernel modules
140 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
141 make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
140 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
141 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
142 142 fi
143 143 fi
144 144
145 145 # Check if kernel compilation was successful
146 146 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
147 147 echo "error: kernel compilation failed! (kernel image not found)"
148 148 cleanup
149 149 exit 1
150 150 fi
151 151
152 152 # Install kernel modules
153 153 if [ "$ENABLE_REDUCE" = true ] ; then
154 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
154 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
155 155 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
156 156 fi
157 157 else
158 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
158 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
159 159 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
160 160 fi
161 161
162 162 # Install kernel firmware
163 if [ $(grep "^firmware_install:" "${KERNEL_DIR}/Makefile") ] ; then
163 if [ "$(grep "^firmware_install:" "${KERNEL_DIR}/Makefile")" ] ; then
164 164 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
165 165 fi
166 166 fi
167 167
168 168 # Install kernel headers
169 169 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
170 170 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
171 171 fi
172 172
173 173 # Prepare boot (firmware) directory
174 174 mkdir "${BOOT_DIR}"
175 175
176 176 # Get kernel release version
177 KERNEL_VERSION=`cat "${KERNEL_DIR}/include/config/kernel.release"`
177 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
178 178
179 179 # Copy kernel configuration file to the boot directory
180 180 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
181 181
182 182 # Prepare device tree directory
183 183 mkdir "${BOOT_DIR}/overlays"
184 184
185 185 # Ensure the proper .dtb is located
186 186 if [ "$KERNEL_ARCH" = "arm" ] ; then
187 187 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
188 188 if [ -f "${dtb}" ] ; then
189 189 install_readonly "${dtb}" "${BOOT_DIR}/"
190 190 fi
191 191 done
192 192 else
193 193 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
194 194 if [ -f "${dtb}" ] ; then
195 195 install_readonly "${dtb}" "${BOOT_DIR}/"
196 196 fi
197 197 done
198 198 fi
199 199
200 200 # Copy compiled dtb device tree files
201 201 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
202 202 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do
203 203 if [ -f "${dtb}" ] ; then
204 204 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
205 205 fi
206 206 done
207 207
208 208 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
209 209 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
210 210 fi
211 211 fi
212 212
213 213 if [ "$ENABLE_UBOOT" = false ] ; then
214 214 # Convert and copy kernel image to the boot directory
215 215 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
216 216 else
217 217 # Copy kernel image to the boot directory
218 218 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
219 219 fi
220 220
221 221 # Remove kernel sources
222 222 if [ "$KERNEL_REMOVESRC" = true ] ; then
223 223 rm -fr "${KERNEL_DIR}"
224 224 else
225 225 # Prepare compiled kernel modules
226 if [ $(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config") ] ; then
227 if [ $(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile") ] ; then
226 if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then
227 if [ "$(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile")" ] ; then
228 228 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
229 229 fi
230 230
231 231 # Create symlinks for kernel modules
232 232 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
233 233 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
234 234 fi
235 235 fi
236 236 elif [ "$BUILD_KERNEL" = false ] ; then
237 # Collabora states this kernel is just for RPI 2 so better implement a check.
238 #From https://repositories.collabora.co.uk/debian/dists/jessie/rpi2/binary-armhf/Packages
239 #"The Linux kernel "${COLLABORA_KERNEL}" and modules for use on ARMv7 kernel for Raspberry pi 2 model B+"
240 # nested if to be easily extended for more precompiled kernels
241 if [ "$SET_ARCH" = 32 ] ; then
242 if [ "$RPI_MODEL" = 2 ] ; then
243 # Kernel installation
244 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
245
246 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
247 chroot_exec apt-get -qq -y install flash-kernel
248
237 echo " Install precompiled kernel..."
238 echo "error: not implemented"
249 239 # Check if kernel installation was successful
250 VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)"
240 VMLINUZ="$(ls -1 "${R}"/boot/vmlinuz-* | sort | tail -n 1)"
251 241 if [ -z "$VMLINUZ" ] ; then
252 242 echo "error: kernel installation failed! (/boot/vmlinuz-* not found)"
253 243 cleanup
254 244 exit 1
255 245 fi
256 246 # Copy vmlinuz kernel to the boot directory
257 247 install_readonly "${VMLINUZ}" "${BOOT_DIR}/${KERNEL_IMAGE}"
258 fi
259 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
260 echo "error: no precompiled kernel found"
261 exit 1
262 # insert precompiled Kernel code here
263 fi
264 #if [ "$SET_ARCH" = 64 ]
248
249 if [ "$SET_ARCH" = 64 ] ; then
250 echo "Using precompiled arm64 kernel"
265 251 else
266 echo "error: no precompiled 64bit kernel found"
252 echo "error: no precompiled arm64 (bcmrpi3) kernel found"
267 253 exit 1
268 254 # inset precompiled 64 bit kernel code here
269 255 fi
256 #fi build_kernel=true
270 257 fi
@@ -1,49 +1,52
1 1 #
2 2 # Setup Firewall
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 if [ "$ENABLE_IPTABLES" = true ] ; then
9 9 # Create iptables configuration directory
10 10 mkdir -p "${ETC_DIR}/iptables"
11 11
12 #In Jessie iptables is old enough
13 if ! [ "$RELEASE" = jessie ] ; then
12 14 # make sure iptables-legacy,iptables-legacy-restore and iptables-legacy-save are the used alternatives
13 15 chroot_exec update-alternatives --verbose --set iptables /usr/sbin/iptables-legacy
14 chroot_exec update-alternatives --verbose --set iptables-save /usr/sbin/iptables-legacy-save
15 chroot_exec update-alternatives --verbose --set iptables-restore /usr/sbin/iptables-legacy-restore
16 #chroot_exec update-alternatives --verbose --set iptables-save /usr/sbin/iptables-legacy-save
17 #chroot_exec update-alternatives --verbose --set iptables-restore /usr/sbin/iptables-legacy-restore
18 fi
16 19
17 20 # Install iptables systemd service
18 21 install_readonly files/iptables/iptables.service "${ETC_DIR}/systemd/system/iptables.service"
19 22
20 23 # Install flush-table script called by iptables service
21 24 install_exec files/iptables/flush-iptables.sh "${ETC_DIR}/iptables/flush-iptables.sh"
22 25
23 26 # Install iptables rule file
24 27 install_readonly files/iptables/iptables.rules "${ETC_DIR}/iptables/iptables.rules"
25 28
26 29 # Reload systemd configuration and enable iptables service
27 30 chroot_exec systemctl daemon-reload
28 31 chroot_exec systemctl enable iptables.service
29 32
30 33 if [ "$ENABLE_IPV6" = true ] ; then
31 34 # Install ip6tables systemd service
32 35 install_readonly files/iptables/ip6tables.service "${ETC_DIR}/systemd/system/ip6tables.service"
33 36
34 37 # Install ip6tables file
35 38 install_exec files/iptables/flush-ip6tables.sh "${ETC_DIR}/iptables/flush-ip6tables.sh"
36 39
37 40 install_readonly files/iptables/ip6tables.rules "${ETC_DIR}/iptables/ip6tables.rules"
38 41
39 42 # Reload systemd configuration and enable iptables service
40 43 chroot_exec systemctl daemon-reload
41 44 chroot_exec systemctl enable ip6tables.service
42 45 fi
43 46
44 47 if [ "$ENABLE_SSHD" = false ] ; then
45 48 # Remove SSHD related iptables rules
46 49 sed -i "/^#/! {/SSH/ s/^/# /}" "${ETC_DIR}/iptables/iptables.rules" 2> /dev/null
47 50 sed -i "/^#/! {/SSH/ s/^/# /}" "${ETC_DIR}/iptables/ip6tables.rules" 2> /dev/null
48 51 fi
49 52 fi
@@ -1,8 +1,9
1 1 deb http://ftp.debian.org/debian jessie main contrib
2 2 #deb-src http://ftp.debian.org/debian jessie main contrib
3 3
4 4 deb http://ftp.debian.org/debian/ jessie-updates main contrib
5 5 #deb-src http://ftp.debian.org/debian/ jessie-updates main contrib
6 6
7 deb http://security.debian.org/ jessie/updates main contrib
7 #deb http://security.debian.org/ jessie/updates main contrib
8 8 #deb-src http://security.debian.org/ jessie/updates main contrib
9
@@ -1,772 +1,790
1 #!/bin/sh
2
1 #!/bin/bash
3 2 ########################################################################
4 3 # rpi23-gen-image.sh 2015-2017
5 4 #
6 # Advanced Debian "jessie", "stretch" and "buster" bootstrap script for RPi2/3
5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
7 6 #
8 7 # This program is free software; you can redistribute it and/or
9 8 # modify it under the terms of the GNU General Public License
10 9 # as published by the Free Software Foundation; either version 2
11 10 # of the License, or (at your option) any later version.
12 11 #
13 12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
14 13 #
15 14 # Big thanks for patches and enhancements by 20+ github contributors!
16 15 ########################################################################
17 16
18 17 # Are we running as root?
19 18 if [ "$(id -u)" -ne "0" ] ; then
20 19 echo "error: this script must be executed with root privileges!"
21 20 exit 1
22 21 fi
23 22
24 23 # Check if ./functions.sh script exists
25 24 if [ ! -r "./functions.sh" ] ; then
26 25 echo "error: './functions.sh' required script not found!"
27 26 exit 1
28 27 fi
29 28
30 29 # Load utility functions
31 30 . ./functions.sh
32 31
33 32 # Load parameters from configuration template file
34 if [ ! -z "$CONFIG_TEMPLATE" ] ; then
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
35 34 use_template
36 35 fi
37 36
38 37 # Introduce settings
39 38 set -e
40 39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
41 40 set -x
42 41
43 42 # Raspberry Pi model configuration
44 43 RPI_MODEL=${RPI_MODEL:=2}
45 44
46 45 # Debian release
47 RELEASE=${RELEASE:=jessie}
46 RELEASE=${RELEASE:=buster}
48 47
49 48 #Kernel Branch
50 49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
51 50
52 51 # URLs
53 52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
54 53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
55 54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
56 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
57 55 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
58 56 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
59 57
58 # Firmware directory: Blank if download from github
59 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
60
60 61 # Build directories
61 62 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
62 63 BUILDDIR="${BASEDIR}/build"
63 64
64 65 # Prepare date string for default image file name
65 66 DATE="$(date +%Y-%m-%d)"
66 67 if [ -z "$KERNEL_BRANCH" ] ; then
67 68 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
68 69 else
69 70 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
70 71 fi
71 72
72 73 # Chroot directories
73 74 R="${BUILDDIR}/chroot"
74 75 ETC_DIR="${R}/etc"
75 76 LIB_DIR="${R}/lib"
76 77 BOOT_DIR="${R}/boot/firmware"
77 78 KERNEL_DIR="${R}/usr/src/linux"
78 79 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
79 80
80 # Firmware directory: Blank if download from github
81 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
82
83 81 # General settings
84 SET_ARCH=${SET_ARCH}
82 SET_ARCH=${SET_ARCH:=32}
85 83 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
86 84 PASSWORD=${PASSWORD:=raspberry}
87 85 USER_PASSWORD=${USER_PASSWORD:=raspberry}
88 86 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
89 87 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
90 88 EXPANDROOT=${EXPANDROOT:=true}
91 89
92 90 # Keyboard settings
93 91 XKB_MODEL=${XKB_MODEL:=""}
94 92 XKB_LAYOUT=${XKB_LAYOUT:=""}
95 93 XKB_VARIANT=${XKB_VARIANT:=""}
96 94 XKB_OPTIONS=${XKB_OPTIONS:=""}
97 95
98 96 # Network settings (DHCP)
99 97 ENABLE_DHCP=${ENABLE_DHCP:=true}
100 98
101 99 # Network settings (static)
102 100 NET_ADDRESS=${NET_ADDRESS:=""}
103 101 NET_GATEWAY=${NET_GATEWAY:=""}
104 102 NET_DNS_1=${NET_DNS_1:=""}
105 103 NET_DNS_2=${NET_DNS_2:=""}
106 104 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
107 105 NET_NTP_1=${NET_NTP_1:=""}
108 106 NET_NTP_2=${NET_NTP_2:=""}
109 107
110 108 # APT settings
111 109 APT_PROXY=${APT_PROXY:=""}
112 110 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
113 111
114 112 # Feature settings
115 113 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
116 114 ENABLE_I2C=${ENABLE_I2C:=false}
117 115 ENABLE_SPI=${ENABLE_SPI:=false}
118 116 ENABLE_IPV6=${ENABLE_IPV6:=true}
119 117 ENABLE_SSHD=${ENABLE_SSHD:=true}
120 118 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
121 119 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
122 120 ENABLE_SOUND=${ENABLE_SOUND:=true}
123 121 ENABLE_DBUS=${ENABLE_DBUS:=true}
124 122 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
125 123 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
126 124 ENABLE_XORG=${ENABLE_XORG:=false}
127 125 ENABLE_WM=${ENABLE_WM:=""}
128 126 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
129 127 ENABLE_USER=${ENABLE_USER:=true}
130 128 USER_NAME=${USER_NAME:="pi"}
131 129 ENABLE_ROOT=${ENABLE_ROOT:=false}
132 130 ENABLE_QEMU=${ENABLE_QEMU:=false}
133 131
134 132 # SSH settings
135 133 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
136 134 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
137 135 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
138 136 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
139 137 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
140 138
141 139 # Advanced settings
142 140 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
143 141 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
144 142 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
145 143 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
146 144 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
147 145 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
148 146 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
149 147 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
150 148 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
151 149 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
152 150 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
153 151 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
154 152
155 153 # Kernel compilation settings
156 154 BUILD_KERNEL=${BUILD_KERNEL:=true}
157 155 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
158 156 KERNEL_THREADS=${KERNEL_THREADS:=1}
159 157 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
160 158 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
161 159 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
162 160 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
163 161 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
164 162
165 163 # Kernel compilation from source directory settings
166 164 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
167 165 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
168 166 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
169 167 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
170 168
171 169 # Reduce disk usage settings
172 170 REDUCE_APT=${REDUCE_APT:=true}
173 171 REDUCE_DOC=${REDUCE_DOC:=true}
174 172 REDUCE_MAN=${REDUCE_MAN:=true}
175 173 REDUCE_VIM=${REDUCE_VIM:=false}
176 174 REDUCE_BASH=${REDUCE_BASH:=false}
177 175 REDUCE_HWDB=${REDUCE_HWDB:=true}
178 176 REDUCE_SSHD=${REDUCE_SSHD:=true}
179 177 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
180 178
181 179 # Encrypted filesystem settings
182 180 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
183 181 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
184 182 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
185 183 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
186 184 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
187 185
188 186 # Chroot scripts directory
189 187 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
190 188
191 189 # Packages required in the chroot build environment
192 190 APT_INCLUDES=${APT_INCLUDES:=""}
193 191 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
194 192
195 193 # Packages required for bootstrapping
196 194 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
197 195 MISSING_PACKAGES=""
198 196
199 197 #autoselect best apt mirror
200 198 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} netselect-apt"
201 199
202 200 # Packages installed for c/c++ build environment in chroot (keep empty)
203 201 COMPILER_PACKAGES=""
204 202
205 203 set +x
206 204
207 205 #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
208 206 if [ -n "$SET_ARCH" ] ; then
209 207 echo "Setting Architecture specific settings"
210 208 ##################################
211 209 # 64 bit config
212 210 ##################################
213 211 if [ "$SET_ARCH" = 64 ] ; then
214 212 echo "64 bit mode selected - Setting up enviroment"
215 213 # 64 bit depended settings
216 214 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
217 215 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
218 216 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
219 217 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
220 218 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
221 219 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
222 220
223 if ([ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]) ; then
221 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
224 222 # RPI 3 serie specific settings
225 223 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
226 224 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
227 225
228 226 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
229 227 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
230 228 else
231 229 echo "error: At the moment Raspberry PI 3 and 3B+ are the only Models which support 64bit"
232 230 exit 1
233 231 fi
234 232 fi
235 233
236 234 ##################################
237 235 # 32 bit config
238 236 ##################################
239 237 if [ "$SET_ARCH" = 32 ] ; then
240 238 echo "32 bit mode selected - Setting up enviroment"
241 239 #General 32bit configuration
242 240 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
243 241 KERNEL_ARCH=${KERNEL_ARCH:=arm}
244 242 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
245 243
246 244 #Raspberry setting grouped by board compability
247 245 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
248 246 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
249 247 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
250 248 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
251 249 RELEASE_ARCH=${RELEASE_ARCH:=armel}
252 250 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
253 251 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
254 252 fi
255 253 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
256 254 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
257 255 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
258 256 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
259 257 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
260 258 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
261 259 fi
262
263 260 #Device specific configuration
264 261 case "$RPI_MODEL" in
265 262 0)
266 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} ;;
263 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
264 ;;
267 265 1)
268 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} ;;
266 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
267 ;;
269 268 1P)
270 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} ;;
269 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
270 ;;
271 271 2)
272 272 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
273 273 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
274 #Precompiled Kernel rpi2
275 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
276 274 ;;
277 275 3)
278 276 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
279 277 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
280 278 ;;
281 279 3P)
282 280 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
283 281 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
284 282 ;;
285 283 *)
286 284 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
287 285 exit 1
288 286 ;;
289 287 esac
288
289 #Device specific configuration
290 # if [ "$RPI_MODEL" = 0 ] ; then
291 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
292 # fi
293 # if [ "$RPI_MODEL" = 1 ] ; then
294 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
295 # fi
296 # if [ "$RPI_MODEL" = 1P ] ; then
297 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
298 # fi
299 # if [ "$RPI_MODEL" = 2 ] ; then
300 # DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
301 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
302 # #Precompiled Kernel rpi2
303 # #COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
304 # fi
305 # if [ "$RPI_MODEL" = 3 ] ; then
306 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
307 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
308 # fi
309 # if [ "$RPI_MODEL" = 3P ] ; then
310 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
311 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
312 # fi
313 # if [ -z "$RPI_MODEL" ] ; then
314 # echo "error: Raspberry Pi model $RPI_MODEL is not set!"
315 # exit 1
316 # fi
317
290 318 #end 32 bit
291 319 fi
292 320 #SET_ARCH not set
293 321 else
294 322 echo "error: Please set '32' or '64' as value for SET_ARCH"
295 323 exit 1
296 324 fi
297 325
298 326 # Check if the internal wireless interface is supported by the RPi model
299 if [ "$ENABLE_WIRELESS" = true ] && ([ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ]) ; then
327 if [ "$ENABLE_WIRELESS" = true ] && { [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; } ; then
300 328 echo "error: The selected Raspberry Pi model has no internal wireless interface"
301 329 exit 1
302 330 else
303 331 echo "Raspberry Pi model"
304 332 fi
305 333
306 334 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
307 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
335 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
308 336 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
309 337 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
310 338 exit 1
311 339 fi
312 340 fi
313 341
314 342 # Add libncurses5 to enable kernel menuconfig
315 343 if [ "$KERNEL_MENUCONFIG" = true ] ; then
316 344 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
317 345 fi
318 346
319 347 # Add ccache compiler cache for (faster) kernel cross (re)compilation
320 348 if [ "$KERNEL_CCACHE" = true ] ; then
321 349 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
322 350 fi
323 351
324 352 # Add cryptsetup package to enable filesystem encryption
325 353 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
326 354 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
327 355 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
328 356
329 357 if [ -z "$CRYPTFS_PASSWORD" ] ; then
330 358 echo "error: no password defined (CRYPTFS_PASSWORD)!"
331 359 exit 1
332 360 fi
333 361 ENABLE_INITRAMFS=true
334 362 fi
335 363
336 364 # Add initramfs generation tools
337 365 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
338 366 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
339 367 fi
340 368
341 369 # Add device-tree-compiler required for building the U-Boot bootloader
342 370 if [ "$ENABLE_UBOOT" = true ] ; then
343 371 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex"
344 372 fi
345 373
346 374 # Check if root SSH (v2) public key file exists
347 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
375 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
348 376 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
349 377 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
350 378 exit 1
351 379 fi
352 380 fi
353 381
354 382 # Check if $USER_NAME SSH (v2) public key file exists
355 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
383 if [ -n "$SSH_USER_PUB_KEY" ] ; then
356 384 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
357 385 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
358 386 exit 1
359 387 fi
360 388 fi
361 389
362 390 # Check if all required packages are installed on the build system
363 391 for package in $REQUIRED_PACKAGES ; do
364 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
392 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
365 393 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
366 394 fi
367 395 done
368 396
369 397 # If there are missing packages ask confirmation for install, or exit
370 398 if [ -n "$MISSING_PACKAGES" ] ; then
371 399 echo "the following packages needed by this script are not installed:"
372 400 echo "$MISSING_PACKAGES"
373 401
374 echo -n "\ndo you want to install the missing packages right now? [y/n] "
375 read confirm
402 printf "\ndo you want to install the missing packages right now? [y/n] "
403 read -r confirm
376 404 [ "$confirm" != "y" ] && exit 1
377 405
378 406 # Make sure all missing required packages are installed
379 apt-get -qq -y install ${MISSING_PACKAGES}
407 apt-get -qq -y install "${MISSING_PACKAGES}"
380 408 fi
381 409
382 410 # Check if ./bootstrap.d directory exists
383 411 if [ ! -d "./bootstrap.d/" ] ; then
384 412 echo "error: './bootstrap.d' required directory not found!"
385 413 exit 1
386 414 fi
387 415
388 416 # Check if ./files directory exists
389 417 if [ ! -d "./files/" ] ; then
390 418 echo "error: './files' required directory not found!"
391 419 exit 1
392 420 fi
393 421
394 422 # Check if specified KERNELSRC_DIR directory exists
395 423 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
396 424 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
397 425 exit 1
398 426 fi
399 427
400 428 # Check if specified UBOOTSRC_DIR directory exists
401 429 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
402 430 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
403 431 exit 1
404 432 fi
405 433
406 434 # Check if specified FBTURBOSRC_DIR directory exists
407 435 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
408 436 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
409 437 exit 1
410 438 fi
411 439
412 440 # Check if specified CHROOT_SCRIPTS directory exists
413 441 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
414 442 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
415 443 exit 1
416 444 fi
417 445
418 446 # Check if specified device mapping already exists (will be used by cryptsetup)
419 447 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
420 448 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
421 449 exit 1
422 450 fi
423 451
424 452 # Don't clobber an old build
425 453 if [ -e "$BUILDDIR" ] ; then
426 454 echo "error: directory ${BUILDDIR} already exists, not proceeding"
427 455 exit 1
428 456 fi
429 457
430 458 # Setup chroot directory
431 459 mkdir -p "${R}"
432 460
433 461 # Check if build directory has enough of free disk space >512MB
434 462 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
435 463 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
436 464 exit 1
437 465 fi
438 466
439 467 set -x
440 468
441 469 # Call "cleanup" function on various signals and errors
442 470 trap cleanup 0 1 2 3 6
443 471
444 472 # Add required packages for the minbase installation
445 473 if [ "$ENABLE_MINBASE" = true ] ; then
446 474 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
447 475 fi
448 476
449 477 # Add required locales packages
450 if [ "$DEFLOCAL" != "en_US.UTF-8" ] || ([ -n XKB_MODEL ] || [ -n XKB_LAYOUT ] || [ -n XKB_VARIANT ] || [ -n XKB_OPTIONS ]); then
478 if [ "$DEFLOCAL" != "en_US.UTF-8" ] || { [ -n "$XKB_MODEL" ] || [ -n "$XKB_LAYOUT" ] || [ -n "$XKB_VARIANT" ] || [ -n "$XKB_OPTIONS" ] ; } ; then
451 479 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
452 480 fi
453 481
454 482 # Add parted package, required to get partprobe utility
455 483 if [ "$EXPANDROOT" = true ] ; then
456 484 APT_INCLUDES="${APT_INCLUDES},parted"
457 485 fi
458 486
459 487 # Add dbus package, recommended if using systemd
460 488 if [ "$ENABLE_DBUS" = true ] ; then
461 489 APT_INCLUDES="${APT_INCLUDES},dbus"
462 490 fi
463 491
464 492 # Add iptables IPv4/IPv6 package
465 493 if [ "$ENABLE_IPTABLES" = true ] ; then
466 494 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
467 495 fi
468 496
469 497 # Add openssh server package
470 498 if [ "$ENABLE_SSHD" = true ] ; then
471 499 APT_INCLUDES="${APT_INCLUDES},openssh-server"
472 500 fi
473 501
474 502 # Add alsa-utils package
475 503 if [ "$ENABLE_SOUND" = true ] ; then
476 504 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
477 505 fi
478 506
479 507 # Add rng-tools package
480 508 if [ "$ENABLE_HWRANDOM" = true ] ; then
481 509 APT_INCLUDES="${APT_INCLUDES},rng-tools"
482 510 fi
483 511
484 512 # Add fbturbo video driver
485 513 if [ "$ENABLE_FBTURBO" = true ] ; then
486 514 # Enable xorg package dependencies
487 515 ENABLE_XORG=true
488 516 fi
489 517
490 518 # Add user defined window manager package
491 519 if [ -n "$ENABLE_WM" ] ; then
492 520 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
493 521
494 522 # Enable xorg package dependencies
495 523 ENABLE_XORG=true
496 524 fi
497 525
498 526 # Add xorg package
499 527 if [ "$ENABLE_XORG" = true ] ; then
500 528 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
501 529 fi
502 530
503 531 # Replace selected packages with smaller clones
504 532 if [ "$ENABLE_REDUCE" = true ] ; then
505 533 # Add levee package instead of vim-tiny
506 534 if [ "$REDUCE_VIM" = true ] ; then
507 535 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
508 536 fi
509 537
510 538 # Add dropbear package instead of openssh-server
511 539 if [ "$REDUCE_SSHD" = true ] ; then
512 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
540 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
513 541 fi
514 542 fi
515 543
516 #backwards compability to jessie - untested
517 if [ "$RELEASE" != "jessie" ] ; then
518 APT_INCLUDES="${APT_INCLUDES},libnss-systemd"
519 fi
520
521 544 # Configure kernel sources if no KERNELSRC_DIR
522 545 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
523 546 KERNELSRC_CONFIG=true
524 547 fi
525 548
526 549 # Configure reduced kernel
527 550 if [ "$KERNEL_REDUCE" = true ] ; then
528 551 KERNELSRC_CONFIG=false
529 552 fi
530 553
531 554 # Execute bootstrap scripts
532 555 for SCRIPT in bootstrap.d/*.sh; do
533 556 head -n 3 "$SCRIPT"
534 557 . "$SCRIPT"
535 558 done
536 559
537 560 ## Execute custom bootstrap scripts
538 561 if [ -d "custom.d" ] ; then
539 562 for SCRIPT in custom.d/*.sh; do
540 563 . "$SCRIPT"
541 564 done
542 565 fi
543 566
544 567 # Execute custom scripts inside the chroot
545 568 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
546 569 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
547 570 chroot_exec /bin/bash -x <<'EOF'
548 571 for SCRIPT in /chroot_scripts/* ; do
549 572 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
550 573 $SCRIPT
551 574 fi
552 575 done
553 576 EOF
554 577 rm -rf "${R}/chroot_scripts"
555 578 fi
556 579
557 580 # Remove c/c++ build environment from the chroot
558 581 chroot_remove_cc
559 582
560 # Remove apt-utils
561 if [ "$RELEASE" = "jessie" ] ; then
562 chroot_exec apt-get purge -qq -y --force-yes apt-utils
563 fi
564
565 583 # Generate required machine-id
566 584 MACHINE_ID=$(dbus-uuidgen)
567 585 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
568 586 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
569 587
570 588 # APT Cleanup
571 589 chroot_exec apt-get -y clean
572 590 chroot_exec apt-get -y autoclean
573 591 chroot_exec apt-get -y autoremove
574 592
575 593 # Unmount mounted filesystems
576 594 umount -l "${R}/proc"
577 595 umount -l "${R}/sys"
578 596
579 597 # Clean up directories
580 598 rm -rf "${R}/run/*"
581 599 rm -rf "${R}/tmp/*"
582 600
583 601 # Clean up files
584 602 rm -f "${ETC_DIR}/ssh/ssh_host_*"
585 603 rm -f "${ETC_DIR}/dropbear/dropbear_*"
586 604 rm -f "${ETC_DIR}/apt/sources.list.save"
587 605 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
588 606 rm -f "${ETC_DIR}/*-"
589 607 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
590 608 rm -f "${ETC_DIR}/resolv.conf"
591 609 rm -f "${R}/root/.bash_history"
592 610 rm -f "${R}/var/lib/urandom/random-seed"
593 611 rm -f "${R}/initrd.img"
594 612 rm -f "${R}/vmlinuz"
595 613 rm -f "${R}${QEMU_BINARY}"
596 614
597 615 if [ "$ENABLE_QEMU" = true ] ; then
598 616 # Configure qemu compatible kernel
599 617 DTB_FILE=vexpress-v2p-ca15_a7.dtb
600 618 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
601 619 KERNEL_DEFCONFIG="vexpress_defconfig"
602 620 if [ "$KERNEL_MENUCONFIG" = false ] ; then
603 621 KERNEL_OLDDEFCONFIG=true
604 622 fi
605 623
606 624 # Setup QEMU directory
607 625 mkdir "${BASEDIR}/qemu"
608 626
609 627 # Copy kernel image to QEMU directory
610 628 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
611 629
612 630 # Copy kernel config to QEMU directory
613 631 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
614 632
615 633 # Copy kernel dtbs to QEMU directory
616 634 for dtb in "${BOOT_DIR}/"*.dtb ; do
617 635 if [ -f "${dtb}" ] ; then
618 636 install_readonly "${dtb}" "${BASEDIR}/qemu/"
619 637 fi
620 638 done
621 639
622 640 # Copy kernel overlays to QEMU directory
623 641 if [ -d "${BOOT_DIR}/overlays" ] ; then
624 642 # Setup overlays dtbs directory
625 643 mkdir "${BASEDIR}/qemu/overlays"
626 644
627 645 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
628 646 if [ -f "${dtb}" ] ; then
629 647 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
630 648 fi
631 649 done
632 650 fi
633 651
634 652 # Copy u-boot files to QEMU directory
635 653 if [ "$ENABLE_UBOOT" = true ] ; then
636 654 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
637 655 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
638 656 fi
639 657 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
640 658 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
641 659 fi
642 660 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
643 661 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
644 662 fi
645 663 fi
646 664
647 665 # Copy initramfs to QEMU directory
648 666 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
649 667 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
650 668 fi
651 669 fi
652 670
653 671 # Calculate size of the chroot directory in KB
654 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
672 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
655 673
656 674 # Calculate the amount of needed 512 Byte sectors
657 675 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
658 676 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
659 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
677 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
660 678
661 679 # The root partition is EXT4
662 680 # This means more space than the actual used space of the chroot is used.
663 681 # As overhead for journaling and reserved blocks 35% are added.
664 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512)
682 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
665 683
666 684 # Calculate required image size in 512 Byte sectors
667 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
685 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
668 686
669 687 # Prepare image file
670 688 if [ "$ENABLE_SPLITFS" = true ] ; then
671 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
672 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
673 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
674 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
689 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
690 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
691 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
692 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
675 693
676 694 # Write firmware/boot partition tables
677 695 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
678 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
696 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
679 697 EOM
680 698
681 699 # Write root partition table
682 700 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
683 ${TABLE_SECTORS},${ROOT_SECTORS},83
701 "${TABLE_SECTORS}","${ROOT_SECTORS}",83
684 702 EOM
685 703
686 704 # Setup temporary loop devices
687 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
688 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
705 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
706 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
689 707 else # ENABLE_SPLITFS=false
690 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
691 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
708 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
709 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
692 710
693 711 # Write partition table
694 712 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
695 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
696 ${ROOT_OFFSET},${ROOT_SECTORS},83
713 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
714 "${ROOT_OFFSET}","${ROOT_SECTORS}",83
697 715 EOM
698 716
699 717 # Setup temporary loop devices
700 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
701 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
718 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
719 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
702 720 fi
703 721
704 722 if [ "$ENABLE_CRYPTFS" = true ] ; then
705 723 # Create dummy ext4 fs
706 724 mkfs.ext4 "$ROOT_LOOP"
707 725
708 726 # Setup password keyfile
709 727 touch .password
710 728 chmod 600 .password
711 echo -n ${CRYPTFS_PASSWORD} > .password
729 echo -n "${CRYPTFS_PASSWORD}" > .password
712 730
713 731 # Initialize encrypted partition
714 732 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
715 733
716 734 # Open encrypted partition and setup mapping
717 735 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
718 736
719 737 # Secure delete password keyfile
720 738 shred -zu .password
721 739
722 740 # Update temporary loop device
723 741 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
724 742
725 743 # Wipe encrypted partition (encryption cipher is used for randomness)
726 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
744 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
727 745 fi
728 746
729 747 # Build filesystems
730 748 mkfs.vfat "$FRMW_LOOP"
731 749 mkfs.ext4 "$ROOT_LOOP"
732 750
733 751 # Mount the temporary loop devices
734 752 mkdir -p "$BUILDDIR/mount"
735 753 mount "$ROOT_LOOP" "$BUILDDIR/mount"
736 754
737 755 mkdir -p "$BUILDDIR/mount/boot/firmware"
738 756 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
739 757
740 758 # Copy all files from the chroot to the loop device mount point directory
741 759 rsync -a "${R}/" "$BUILDDIR/mount/"
742 760
743 761 # Unmount all temporary loop devices and mount points
744 762 cleanup
745 763
746 764 # Create block map file(s) of image(s)
747 765 if [ "$ENABLE_SPLITFS" = true ] ; then
748 766 # Create block map files for "bmaptool"
749 767 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
750 768 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
751 769
752 770 # Image was successfully created
753 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
754 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
771 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
772 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
755 773 else
756 774 # Create block map file for "bmaptool"
757 775 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
758 776
759 777 # Image was successfully created
760 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
778 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
761 779
762 780 # Create qemu qcow2 image
763 781 if [ "$ENABLE_QEMU" = true ] ; then
764 782 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
765 783 QEMU_SIZE=16G
766 784
767 qemu-img convert -f raw -O qcow2 $IMAGE_NAME.img $QEMU_IMAGE.qcow2
768 qemu-img resize $QEMU_IMAGE.qcow2 $QEMU_SIZE
785 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
786 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
769 787
770 788 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
771 789 fi
772 790 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant