##// END OF EJS Templates
t
Unknown -
r408:fb8ed5eebd29
parent child
Show More
@@ -1,406 +1,406
1 #
1 #
2 # Build and Setup RPi2/3 Kernel
2 # Build and Setup RPi2/3 Kernel
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Fetch and build latest raspberry kernel
8 # Fetch and build latest raspberry kernel
9 if [ "$BUILD_KERNEL" = true ] ; then
9 if [ "$BUILD_KERNEL" = true ] ; then
10 # Setup source directory
10 # Setup source directory
11 mkdir -p "${KERNEL_DIR}"
11 mkdir -p "${KERNEL_DIR}"
12
12
13 # Copy existing kernel sources into chroot directory
13 # Copy existing kernel sources into chroot directory
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 # Copy kernel sources and include hidden files
15 # Copy kernel sources and include hidden files
16 cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}"
16 cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}"
17
17
18 # Clean the kernel sources
18 # Clean the kernel sources
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
20 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 fi
21 fi
22 else # KERNELSRC_DIR=""
22 else # KERNELSRC_DIR=""
23 # Create temporary directory for kernel sources
23 # Create temporary directory for kernel sources
24 temp_dir=$(as_nobody mktemp -d)
24 temp_dir=$(as_nobody mktemp -d)
25
25
26 # Fetch current RPi2/3 kernel sources
26 # Fetch current RPi2/3 kernel sources
27 if [ -z "${KERNEL_BRANCH}" ] ; then
27 if [ -z "${KERNEL_BRANCH}" ] ; then
28 as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux
28 as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux
29 else
29 else
30 as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux
30 as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux
31 fi
31 fi
32
32
33 # Copy downloaded kernel sources
33 # Copy downloaded kernel sources
34 cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}"
34 cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}"
35
35
36 # Remove temporary directory for kernel sources
36 # Remove temporary directory for kernel sources
37 rm -fr "${temp_dir}"
37 rm -fr "${temp_dir}"
38
38
39 # Set permissions of the kernel sources
39 # Set permissions of the kernel sources
40 chown -R root:root "${R}/usr/src"
40 chown -R root:root "${R}/usr/src"
41 fi
41 fi
42
42
43 # Calculate optimal number of kernel building threads
43 # Calculate optimal number of kernel building threads
44 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
44 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
45 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
45 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
46 fi
46 fi
47
47
48 # Configure and build kernel
48 # Configure and build kernel
49 if [ "$KERNELSRC_PREBUILT" = false ] ; then
49 if [ "$KERNELSRC_PREBUILT" = false ] ; then
50 # Remove device, network and filesystem drivers from kernel configuration
50 # Remove device, network and filesystem drivers from kernel configuration
51 if [ "$KERNEL_REDUCE" = true ] ; then
51 if [ "$KERNEL_REDUCE" = true ] ; then
52 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
52 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
53 sed -i\
53 sed -i\
54 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
54 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
55 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
55 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
56 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
56 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
57 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
57 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
58 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
58 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
59 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
59 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
60 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
60 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
61 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
61 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
62 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
62 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
63 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
63 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
64 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
64 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
65 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
65 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
66 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
66 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
67 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
67 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
68 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
68 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
69 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
69 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
70 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
70 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
71 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
71 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
72 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
72 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
73 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
73 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
74 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
74 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
75 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
75 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
76 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
76 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
77 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
77 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
78 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
78 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
79 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
79 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
80 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
80 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
81 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
81 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
82 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
82 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
83 "${KERNEL_DIR}"/.config
83 "${KERNEL_DIR}/.config"
84 fi
84 fi
85
85
86 if [ "$KERNELSRC_CONFIG" = true ] ; then
86 if [ "$KERNELSRC_CONFIG" = true ] ; then
87 # Load default raspberry kernel configuration
87 # Load default raspberry kernel configuration
88 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
88 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
89 #Switch to KERNELSRC_DIR
89 #Switch to KERNELSRC_DIR
90 cd "${KERNEL_DIR}"
90 cd "${KERNEL_DIR}"
91
91
92 # GPL v2.0
92 # GPL v2.0
93 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
93 #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh
94 if [ "$KERNEL_ZSWAP" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
94 if [ "$KERNEL_ZSWAP" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
95 # enable ZSWAP support for better performance during large builds etc.
95 # enable ZSWAP support for better performance during large builds etc.
96 # requires activation via kernel parameter or sysfs
96 # requires activation via kernel parameter or sysfs
97 # see e.g. https://askubuntu.com/a/472227 for a summary of ZSWAP (vs ZRAM etc.)
97 # see e.g. https://askubuntu.com/a/472227 for a summary of ZSWAP (vs ZRAM etc.)
98 # and e.g. https://wiki.archlinux.org/index.php/zswap for parameters etc.
98 # and e.g. https://wiki.archlinux.org/index.php/zswap for parameters etc.
99 set_kernel_config ZPOOL y
99 set_kernel_config ZPOOL y
100 set_kernel_config ZSWAP y
100 set_kernel_config ZSWAP y
101 set_kernel_config ZBUD y
101 set_kernel_config ZBUD y
102 set_kernel_config Z3FOLD y
102 set_kernel_config Z3FOLD y
103 set_kernel_config ZSMALLOC y
103 set_kernel_config ZSMALLOC y
104 set_kernel_config PGTABLE_MAPPING y
104 set_kernel_config PGTABLE_MAPPING y
105 fi
105 fi
106
106
107 if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
107 if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
108 # enable basic KVM support; see e.g.
108 # enable basic KVM support; see e.g.
109 # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453
109 # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453
110 set_kernel_config VIRTUALIZATION y
110 set_kernel_config VIRTUALIZATION y
111 set_kernel_config KVM y
111 set_kernel_config KVM y
112 set_kernel_config VHOST_NET m
112 set_kernel_config VHOST_NET m
113 set_kernel_config VHOST_CROSS_ENDIAN_LEGACY y
113 set_kernel_config VHOST_CROSS_ENDIAN_LEGACY y
114 fi
114 fi
115 #See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406
115 #See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406
116 # Netfilter kernel support
116 # Netfilter kernel support
117 if [ "$KERNEL_NF" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
117 if [ "$KERNEL_NF" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
118 set_kernel_config CONFIG_NETFILTER_XTABLES m
118 set_kernel_config CONFIG_NETFILTER_XTABLES m
119 set_kernel_config CONFIG_NF_DUP_NETDEV m
119 set_kernel_config CONFIG_NF_DUP_NETDEV m
120 set_kernel_config CONFIG_NF_NAT_SIP m
120 set_kernel_config CONFIG_NF_NAT_SIP m
121 set_kernel_config CONFIG_NF_TABLES_ARP m
121 set_kernel_config CONFIG_NF_TABLES_ARP m
122 set_kernel_config CONFIG_NF_TABLES_BRIDGE m
122 set_kernel_config CONFIG_NF_TABLES_BRIDGE m
123 set_kernel_config NF_TABLES m
123 set_kernel_config NF_TABLES m
124 set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m
124 set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m
125 set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m
125 set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m
126 set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m
126 set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m
127 set_kernel_config CONFIG_IP6_NF_IPTABLES m
127 set_kernel_config CONFIG_IP6_NF_IPTABLES m
128 set_kernel_config CONFIG_IP6_NF_MATCH_AH m
128 set_kernel_config CONFIG_IP6_NF_MATCH_AH m
129 set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m
129 set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m
130 set_kernel_config CONFIG_IP6_NF_NAT m
130 set_kernel_config CONFIG_IP6_NF_NAT m
131 set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m
131 set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m
132 set_kernel_config CONFIG_IP6_NF_TARGET_NPT m
132 set_kernel_config CONFIG_IP6_NF_TARGET_NPT m
133 set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m
133 set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m
134 set_kernel_config CONFIG_IP_SET_BITMAP_PORT m
134 set_kernel_config CONFIG_IP_SET_BITMAP_PORT m
135 set_kernel_config CONFIG_IP_SET_HASH_IP m
135 set_kernel_config CONFIG_IP_SET_HASH_IP m
136 set_kernel_config CONFIG_IP_SET_HASH_IPMARK m
136 set_kernel_config CONFIG_IP_SET_HASH_IPMARK m
137 set_kernel_config CONFIG_IP_SET_HASH_IPPORT m
137 set_kernel_config CONFIG_IP_SET_HASH_IPPORT m
138 set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m
138 set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m
139 set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m
139 set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m
140 set_kernel_config CONFIG_IP_SET_HASH_MAC m
140 set_kernel_config CONFIG_IP_SET_HASH_MAC m
141 set_kernel_config CONFIG_IP_SET_HASH_NET m
141 set_kernel_config CONFIG_IP_SET_HASH_NET m
142 set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m
142 set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m
143 set_kernel_config CONFIG_IP_SET_HASH_NETNET m
143 set_kernel_config CONFIG_IP_SET_HASH_NETNET m
144 set_kernel_config CONFIG_IP_SET_HASH_NETPORT m
144 set_kernel_config CONFIG_IP_SET_HASH_NETPORT m
145 set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m
145 set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m
146 set_kernel_config CONFIG_IP_SET_LIST_SET m
146 set_kernel_config CONFIG_IP_SET_LIST_SET m
147 set_kernel_config CONFIG_NFT_BRIDGE_META m
147 set_kernel_config CONFIG_NFT_BRIDGE_META m
148 set_kernel_config CONFIG_NFT_BRIDGE_REJECT m
148 set_kernel_config CONFIG_NFT_BRIDGE_REJECT m
149 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m
149 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m
150 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m
150 set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m
151 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m
151 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m
152 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m
152 set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m
153 set_kernel_config CONFIG_NFT_COMPAT m
153 set_kernel_config CONFIG_NFT_COMPAT m
154 set_kernel_config CONFIG_NFT_COUNTER m
154 set_kernel_config CONFIG_NFT_COUNTER m
155 set_kernel_config CONFIG_NFT_CT m
155 set_kernel_config CONFIG_NFT_CT m
156 set_kernel_config CONFIG_NFT_DUP_IPV4 m
156 set_kernel_config CONFIG_NFT_DUP_IPV4 m
157 set_kernel_config CONFIG_NFT_DUP_IPV6 m
157 set_kernel_config CONFIG_NFT_DUP_IPV6 m
158 set_kernel_config CONFIG_NFT_DUP_NETDEV m
158 set_kernel_config CONFIG_NFT_DUP_NETDEV m
159 set_kernel_config CONFIG_NFT_EXTHDR m
159 set_kernel_config CONFIG_NFT_EXTHDR m
160 set_kernel_config CONFIG_NFT_FWD_NETDEV m
160 set_kernel_config CONFIG_NFT_FWD_NETDEV m
161 set_kernel_config CONFIG_NFT_HASH m
161 set_kernel_config CONFIG_NFT_HASH m
162 set_kernel_config CONFIG_NFT_LIMIT m
162 set_kernel_config CONFIG_NFT_LIMIT m
163 set_kernel_config CONFIG_NFT_LOG m
163 set_kernel_config CONFIG_NFT_LOG m
164 set_kernel_config CONFIG_NFT_MASQ m
164 set_kernel_config CONFIG_NFT_MASQ m
165 set_kernel_config CONFIG_NFT_MASQ_IPV4 m
165 set_kernel_config CONFIG_NFT_MASQ_IPV4 m
166 set_kernel_config CONFIG_NFT_MASQ_IPV6 m
166 set_kernel_config CONFIG_NFT_MASQ_IPV6 m
167 set_kernel_config CONFIG_NFT_META m
167 set_kernel_config CONFIG_NFT_META m
168 set_kernel_config CONFIG_NFT_NAT m
168 set_kernel_config CONFIG_NFT_NAT m
169 set_kernel_config CONFIG_NFT_NUMGEN m
169 set_kernel_config CONFIG_NFT_NUMGEN m
170 set_kernel_config CONFIG_NFT_QUEUE m
170 set_kernel_config CONFIG_NFT_QUEUE m
171 set_kernel_config CONFIG_NFT_QUOTA m
171 set_kernel_config CONFIG_NFT_QUOTA m
172 set_kernel_config CONFIG_NFT_REDIR m
172 set_kernel_config CONFIG_NFT_REDIR m
173 set_kernel_config CONFIG_NFT_REDIR_IPV4 m
173 set_kernel_config CONFIG_NFT_REDIR_IPV4 m
174 set_kernel_config CONFIG_NFT_REDIR_IPV6 m
174 set_kernel_config CONFIG_NFT_REDIR_IPV6 m
175 set_kernel_config CONFIG_NFT_REJECT m
175 set_kernel_config CONFIG_NFT_REJECT m
176 set_kernel_config CONFIG_NFT_REJECT_INET m
176 set_kernel_config CONFIG_NFT_REJECT_INET m
177 set_kernel_config CONFIG_NFT_REJECT_IPV4 m
177 set_kernel_config CONFIG_NFT_REJECT_IPV4 m
178 set_kernel_config CONFIG_NFT_REJECT_IPV6 m
178 set_kernel_config CONFIG_NFT_REJECT_IPV6 m
179 set_kernel_config CONFIG_NFT_SET_HASH m
179 set_kernel_config CONFIG_NFT_SET_HASH m
180 set_kernel_config CONFIG_NFT_SET_RBTREE m
180 set_kernel_config CONFIG_NFT_SET_RBTREE m
181 set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m
181 set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m
182 set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m
182 set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m
183 set_kernel_config CONFIG_NF_DEFRAG_IPV4 m
183 set_kernel_config CONFIG_NF_DEFRAG_IPV4 m
184 set_kernel_config CONFIG_NF_DEFRAG_IPV6 m
184 set_kernel_config CONFIG_NF_DEFRAG_IPV6 m
185 set_kernel_config CONFIG_NF_DUP_IPV4 m
185 set_kernel_config CONFIG_NF_DUP_IPV4 m
186 set_kernel_config CONFIG_NF_DUP_IPV6 m
186 set_kernel_config CONFIG_NF_DUP_IPV6 m
187 set_kernel_config CONFIG_NF_LOG_BRIDGE m
187 set_kernel_config CONFIG_NF_LOG_BRIDGE m
188 set_kernel_config CONFIG_NF_LOG_IPV4 m
188 set_kernel_config CONFIG_NF_LOG_IPV4 m
189 set_kernel_config CONFIG_NF_LOG_IPV6 m
189 set_kernel_config CONFIG_NF_LOG_IPV6 m
190 set_kernel_config CONFIG_NF_NAT_IPV4 m
190 set_kernel_config CONFIG_NF_NAT_IPV4 m
191 set_kernel_config CONFIG_NF_NAT_IPV6 m
191 set_kernel_config CONFIG_NF_NAT_IPV6 m
192 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m
192 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m
193 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m
193 set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m
194 set_kernel_config CONFIG_NF_NAT_PPTP m
194 set_kernel_config CONFIG_NF_NAT_PPTP m
195 set_kernel_config CONFIG_NF_NAT_PROTO_GRE m
195 set_kernel_config CONFIG_NF_NAT_PROTO_GRE m
196 set_kernel_config CONFIG_NF_NAT_REDIRECT m
196 set_kernel_config CONFIG_NF_NAT_REDIRECT m
197 set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m
197 set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m
198 set_kernel_config CONFIG_NF_NAT_TFTP m
198 set_kernel_config CONFIG_NF_NAT_TFTP m
199 set_kernel_config CONFIG_NF_REJECT_IPV4 m
199 set_kernel_config CONFIG_NF_REJECT_IPV4 m
200 set_kernel_config CONFIG_NF_REJECT_IPV6 m
200 set_kernel_config CONFIG_NF_REJECT_IPV6 m
201 set_kernel_config CONFIG_NF_TABLES_INET m
201 set_kernel_config CONFIG_NF_TABLES_INET m
202 set_kernel_config CONFIG_NF_TABLES_IPV4 m
202 set_kernel_config CONFIG_NF_TABLES_IPV4 m
203 set_kernel_config CONFIG_NF_TABLES_IPV6 m
203 set_kernel_config CONFIG_NF_TABLES_IPV6 m
204 set_kernel_config CONFIG_NF_TABLES_NETDEV m
204 set_kernel_config CONFIG_NF_TABLES_NETDEV m
205 set_kernel_config NETFILTER_XTABLES m
205 set_kernel_config NETFILTER_XTABLES m
206 fi
206 fi
207
207
208 #https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA
208 #https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA
209 #https://github.com/torvalds/linux/blob/master/init/Kconfig#L848
209 #https://github.com/torvalds/linux/blob/master/init/Kconfig#L848
210 # Enables BPF syscall for systemd-journald
210 # Enables BPF syscall for systemd-journald
211 if [ "$KERNEL_BPF" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
211 if [ "$KERNEL_BPF" = true ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
212 set_kernel_config CONFIG_BPF_SYSCALL y
212 set_kernel_config CONFIG_BPF_SYSCALL y
213 set_kernel_config CONFIG_CGROUP_BPF y
213 set_kernel_config CONFIG_CGROUP_BPF y
214 fi
214 fi
215
215
216 #Revert to previous directory
216 #Revert to previous directory
217 cd "${R}"
217 cd "${WORKDIR}"
218
218
219 # Set kernel configuration parameters to enable qemu emulation
219 # Set kernel configuration parameters to enable qemu emulation
220 if [ "$ENABLE_QEMU" = true ] ; then
220 if [ "$ENABLE_QEMU" = true ] ; then
221 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
221 echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config
222 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
222 echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config
223
223
224 if [ "$ENABLE_CRYPTFS" = true ] ; then
224 if [ "$ENABLE_CRYPTFS" = true ] ; then
225 {
225 {
226 echo "CONFIG_EMBEDDED=y"
226 echo "CONFIG_EMBEDDED=y"
227 echo "CONFIG_EXPERT=y"
227 echo "CONFIG_EXPERT=y"
228 echo "CONFIG_DAX=y"
228 echo "CONFIG_DAX=y"
229 echo "CONFIG_MD=y"
229 echo "CONFIG_MD=y"
230 echo "CONFIG_BLK_DEV_MD=y"
230 echo "CONFIG_BLK_DEV_MD=y"
231 echo "CONFIG_MD_AUTODETECT=y"
231 echo "CONFIG_MD_AUTODETECT=y"
232 echo "CONFIG_BLK_DEV_DM=y"
232 echo "CONFIG_BLK_DEV_DM=y"
233 echo "CONFIG_BLK_DEV_DM_BUILTIN=y"
233 echo "CONFIG_BLK_DEV_DM_BUILTIN=y"
234 echo "CONFIG_DM_CRYPT=y"
234 echo "CONFIG_DM_CRYPT=y"
235 echo "CONFIG_CRYPTO_BLKCIPHER=y"
235 echo "CONFIG_CRYPTO_BLKCIPHER=y"
236 echo "CONFIG_CRYPTO_CBC=y"
236 echo "CONFIG_CRYPTO_CBC=y"
237 echo "CONFIG_CRYPTO_XTS=y"
237 echo "CONFIG_CRYPTO_XTS=y"
238 echo "CONFIG_CRYPTO_SHA512=y"
238 echo "CONFIG_CRYPTO_SHA512=y"
239 echo "CONFIG_CRYPTO_MANAGER=y"
239 echo "CONFIG_CRYPTO_MANAGER=y"
240 } >> "${KERNEL_DIR}/.config"
240 } >> "${KERNEL_DIR}/.config"
241 fi
241 fi
242 fi
242 fi
243
243
244 # Copy custom kernel configuration file
244 # Copy custom kernel configuration file
245 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
245 if [ -n "$KERNELSRC_USRCONFIG" ] ; then
246 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
246 cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config
247 fi
247 fi
248
248
249 # Set kernel configuration parameters to their default values
249 # Set kernel configuration parameters to their default values
250 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
250 if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then
251 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
251 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
252 fi
252 fi
253
253
254 # Start menu-driven kernel configuration (interactive)
254 # Start menu-driven kernel configuration (interactive)
255 if [ "$KERNEL_MENUCONFIG" = true ] ; then
255 if [ "$KERNEL_MENUCONFIG" = true ] ; then
256 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
256 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
257 fi
257 fi
258 fi
258 fi
259
259
260 # Use ccache to cross compile the kernel
260 # Use ccache to cross compile the kernel
261 if [ "$KERNEL_CCACHE" = true ] ; then
261 if [ "$KERNEL_CCACHE" = true ] ; then
262 cc="ccache ${CROSS_COMPILE}gcc"
262 cc="ccache ${CROSS_COMPILE}gcc"
263 else
263 else
264 cc="${CROSS_COMPILE}gcc"
264 cc="${CROSS_COMPILE}gcc"
265 fi
265 fi
266
266
267 # Cross compile kernel and dtbs
267 # Cross compile kernel and dtbs
268 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
268 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs
269
269
270 # Cross compile kernel modules
270 # Cross compile kernel modules
271 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
271 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
272 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
272 make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules
273 fi
273 fi
274 fi
274 fi
275
275
276 # Check if kernel compilation was successful
276 # Check if kernel compilation was successful
277 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
277 if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then
278 echo "error: kernel compilation failed! (kernel image not found)"
278 echo "error: kernel compilation failed! (kernel image not found)"
279 cleanup
279 cleanup
280 exit 1
280 exit 1
281 fi
281 fi
282
282
283 # Install kernel modules
283 # Install kernel modules
284 if [ "$ENABLE_REDUCE" = true ] ; then
284 if [ "$ENABLE_REDUCE" = true ] ; then
285 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
285 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
286 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
286 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
287 fi
287 fi
288 else
288 else
289 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
289 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
290 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
290 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
291 fi
291 fi
292
292
293 # Install kernel firmware
293 # Install kernel firmware
294 if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then
294 if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then
295 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
295 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
296 fi
296 fi
297 fi
297 fi
298
298
299 # Install kernel headers
299 # Install kernel headers
300 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
300 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
301 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
301 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
302 fi
302 fi
303 # make tar.gz kernel package - missing os bzw. modules
303 # make tar.gz kernel package - missing os bzw. modules
304 #** ** ** WARNING ** ** **
304 #** ** ** WARNING ** ** **
305 #Your architecture did not define any architecture-dependent files
305 #Your architecture did not define any architecture-dependent files
306 #to be placed into the tarball. Please add those to ./scripts/package/buildtar .
306 #to be placed into the tarball. Please add those to ./scripts/package/buildtar .
307 # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg
307 # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg
308
308
309 # Prepare boot (firmware) directory
309 # Prepare boot (firmware) directory
310 mkdir "${BOOT_DIR}"
310 mkdir "${BOOT_DIR}"
311
311
312 # Get kernel release version
312 # Get kernel release version
313 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
313 KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release")
314
314
315 # Copy kernel configuration file to the boot directory
315 # Copy kernel configuration file to the boot directory
316 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
316 install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
317
317
318 # Prepare device tree directory
318 # Prepare device tree directory
319 mkdir "${BOOT_DIR}/overlays"
319 mkdir "${BOOT_DIR}/overlays"
320
320
321 # Ensure the proper .dtb is located
321 # Ensure the proper .dtb is located
322 if [ "$KERNEL_ARCH" = "arm" ] ; then
322 if [ "$KERNEL_ARCH" = "arm" ] ; then
323 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
323 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do
324 if [ -f "${dtb}" ] ; then
324 if [ -f "${dtb}" ] ; then
325 install_readonly "${dtb}" "${BOOT_DIR}/"
325 install_readonly "${dtb}" "${BOOT_DIR}/"
326 fi
326 fi
327 done
327 done
328 else
328 else
329 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
329 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do
330 if [ -f "${dtb}" ] ; then
330 if [ -f "${dtb}" ] ; then
331 install_readonly "${dtb}" "${BOOT_DIR}/"
331 install_readonly "${dtb}" "${BOOT_DIR}/"
332 fi
332 fi
333 done
333 done
334 fi
334 fi
335
335
336 # Copy compiled dtb device tree files
336 # Copy compiled dtb device tree files
337 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
337 if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then
338 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do
338 for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do
339 if [ -f "${dtb}" ] ; then
339 if [ -f "${dtb}" ] ; then
340 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
340 install_readonly "${dtb}" "${BOOT_DIR}/overlays/"
341 fi
341 fi
342 done
342 done
343
343
344 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
344 if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then
345 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
345 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README"
346 fi
346 fi
347 fi
347 fi
348
348
349 if [ "$ENABLE_UBOOT" = false ] ; then
349 if [ "$ENABLE_UBOOT" = false ] ; then
350 # Convert and copy kernel image to the boot directory
350 # Convert and copy kernel image to the boot directory
351 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
351 "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
352 else
352 else
353 # Copy kernel image to the boot directory
353 # Copy kernel image to the boot directory
354 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
354 install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}"
355 fi
355 fi
356
356
357 # Remove kernel sources
357 # Remove kernel sources
358 if [ "$KERNEL_REMOVESRC" = true ] ; then
358 if [ "$KERNEL_REMOVESRC" = true ] ; then
359 rm -fr "${KERNEL_DIR}"
359 rm -fr "${KERNEL_DIR}"
360 else
360 else
361 # Prepare compiled kernel modules
361 # Prepare compiled kernel modules
362 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
362 if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then
363 if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then
363 if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then
364 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
364 make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare
365 fi
365 fi
366
366
367 # Create symlinks for kernel modules
367 # Create symlinks for kernel modules
368 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
368 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build"
369 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
369 chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source"
370 fi
370 fi
371 fi
371 fi
372
372
373 else # BUILD_KERNEL=false
373 else # BUILD_KERNEL=false
374 # echo Install precompiled kernel...
374 # echo Install precompiled kernel...
375 # echo error: not implemented
375 # echo error: not implemented
376 if [ "$KERNEL_ARCH" = arm64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
376 if [ "$KERNEL_ARCH" = arm64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then
377 # Create temporary directory for dl
377 # Create temporary directory for dl
378 temp_dir=$(as_nobody mktemp -d)
378 temp_dir=$(as_nobody mktemp -d)
379
379
380 # Fetch kernel dl
380 # Fetch kernel dl
381 as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL"
381 as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL"
382 #extract download
382 #extract download
383 tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}"
383 tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}"
384
384
385 #move extracted kernel to /boot/firmware
385 #move extracted kernel to /boot/firmware
386 mkdir "${R}/boot/firmware"
386 mkdir "${R}/boot/firmware"
387 cp "${temp_dir}"/boot/* "${R}"/boot/firmware/
387 cp "${temp_dir}"/boot/* "${R}"/boot/firmware/
388 cp -r "${temp_dir}"/lib/* "${R}"/lib/
388 cp -r "${temp_dir}"/lib/* "${R}"/lib/
389
389
390 # Remove temporary directory for kernel sources
390 # Remove temporary directory for kernel sources
391 rm -fr "${temp_dir}"
391 rm -fr "${temp_dir}"
392 # Set permissions of the kernel sources
392 # Set permissions of the kernel sources
393 chown -R root:root "${R}/boot/firmware"
393 chown -R root:root "${R}/boot/firmware"
394 chown -R root:root "${R}/lib/modules"
394 chown -R root:root "${R}/lib/modules"
395 #Create cmdline.txt for 15-rpi-config.sh
395 #Create cmdline.txt for 15-rpi-config.sh
396 touch "${BOOT_DIR}/cmdline.txt"
396 touch "${BOOT_DIR}/cmdline.txt"
397 fi
397 fi
398
398
399 # Check if kernel installation was successful
399 # Check if kernel installation was successful
400 KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)"
400 KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)"
401 if [ -z "$KERNEL" ] ; then
401 if [ -z "$KERNEL" ] ; then
402 echo "error: kernel installation failed! (/boot/kernel* not found)"
402 echo "error: kernel installation failed! (/boot/kernel* not found)"
403 cleanup
403 cleanup
404 exit 1
404 exit 1
405 fi
405 fi
406 fi
406 fi
@@ -1,821 +1,822
1 #!/bin/sh
1 #!/bin/sh
2 ########################################################################
2 ########################################################################
3 # rpi23-gen-image.sh 2015-2017
3 # rpi23-gen-image.sh 2015-2017
4 #
4 #
5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
6 #
6 #
7 # This program is free software; you can redistribute it and/or
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
10 # of the License, or (at your option) any later version.
11 #
11 #
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 #
13 #
14 # Big thanks for patches and enhancements by 20+ github contributors!
14 # Big thanks for patches and enhancements by 20+ github contributors!
15 ########################################################################
15 ########################################################################
16
16
17 # Are we running as root?
17 # Are we running as root?
18 if [ "$(id -u)" -ne "0" ] ; then
18 if [ "$(id -u)" -ne "0" ] ; then
19 echo "error: this script must be executed with root privileges!"
19 echo "error: this script must be executed with root privileges!"
20 exit 1
20 exit 1
21 fi
21 fi
22
22
23 # Check if ./functions.sh script exists
23 # Check if ./functions.sh script exists
24 if [ ! -r "./functions.sh" ] ; then
24 if [ ! -r "./functions.sh" ] ; then
25 echo "error: './functions.sh' required script not found!"
25 echo "error: './functions.sh' required script not found!"
26 exit 1
26 exit 1
27 fi
27 fi
28
28
29 # Load utility functions
29 # Load utility functions
30 . ./functions.sh
30 . ./functions.sh
31
31
32 # Load parameters from configuration template file
32 # Load parameters from configuration template file
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 use_template
34 use_template
35 fi
35 fi
36
36
37 # Introduce settings
37 # Introduce settings
38 set -e
38 set -e
39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
40 set -x
40 set -x
41
41
42 # Raspberry Pi model configuration
42 # Raspberry Pi model configuration
43 RPI_MODEL=${RPI_MODEL:=2}
43 RPI_MODEL=${RPI_MODEL:=2}
44
44
45 # Debian release
45 # Debian release
46 RELEASE=${RELEASE:=buster}
46 RELEASE=${RELEASE:=buster}
47
47
48 #Kernel Branch
48 #Kernel Branch
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
50
50
51 # URLs
51 # URLs
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
59 #BIS= Kernel has KVM and zswap enabled
59 #BIS= Kernel has KVM and zswap enabled
60 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz}
60 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz}
61 #default bcmrpi3_defconfig target kernel
61 #default bcmrpi3_defconfig target kernel
62 RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz}
62 RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz}
63 #enhanced kernel
63 #enhanced kernel
64 RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_BIS_KERNEL_URL}
64 RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_BIS_KERNEL_URL}
65 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
65 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
66
66
67 # Build directories
67 # Build directories
68 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
68 WORKDIR=$(pwd)
69 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
69 BUILDDIR="${BASEDIR}/build"
70 BUILDDIR="${BASEDIR}/build"
70
71
71 # Prepare date string for default image file name
72 # Prepare date string for default image file name
72 DATE="$(date +%Y-%m-%d)"
73 DATE="$(date +%Y-%m-%d)"
73 if [ -z "$KERNEL_BRANCH" ] ; then
74 if [ -z "$KERNEL_BRANCH" ] ; then
74 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
75 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
75 else
76 else
76 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
77 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
77 fi
78 fi
78
79
79 # Chroot directories
80 # Chroot directories
80 R="${BUILDDIR}/chroot"
81 R="${BUILDDIR}/chroot"
81 ETC_DIR="${R}/etc"
82 ETC_DIR="${R}/etc"
82 LIB_DIR="${R}/lib"
83 LIB_DIR="${R}/lib"
83 BOOT_DIR="${R}/boot/firmware"
84 BOOT_DIR="${R}/boot/firmware"
84 KERNEL_DIR="${R}/usr/src/linux"
85 KERNEL_DIR="${R}/usr/src/linux"
85 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
86 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
86
87
87 # Firmware directory: Blank if download from github
88 # Firmware directory: Blank if download from github
88 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
89 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
89
90
90 # General settings
91 # General settings
91 SET_ARCH=${SET_ARCH:=32}
92 SET_ARCH=${SET_ARCH:=32}
92 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
93 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
93 PASSWORD=${PASSWORD:=raspberry}
94 PASSWORD=${PASSWORD:=raspberry}
94 USER_PASSWORD=${USER_PASSWORD:=raspberry}
95 USER_PASSWORD=${USER_PASSWORD:=raspberry}
95 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
96 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
96 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
97 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
97 EXPANDROOT=${EXPANDROOT:=true}
98 EXPANDROOT=${EXPANDROOT:=true}
98
99
99 # Keyboard settings
100 # Keyboard settings
100 XKB_MODEL=${XKB_MODEL:=""}
101 XKB_MODEL=${XKB_MODEL:=""}
101 XKB_LAYOUT=${XKB_LAYOUT:=""}
102 XKB_LAYOUT=${XKB_LAYOUT:=""}
102 XKB_VARIANT=${XKB_VARIANT:=""}
103 XKB_VARIANT=${XKB_VARIANT:=""}
103 XKB_OPTIONS=${XKB_OPTIONS:=""}
104 XKB_OPTIONS=${XKB_OPTIONS:=""}
104
105
105 # Network settings (DHCP)
106 # Network settings (DHCP)
106 ENABLE_DHCP=${ENABLE_DHCP:=true}
107 ENABLE_DHCP=${ENABLE_DHCP:=true}
107
108
108 # Network settings (static)
109 # Network settings (static)
109 NET_ADDRESS=${NET_ADDRESS:=""}
110 NET_ADDRESS=${NET_ADDRESS:=""}
110 NET_GATEWAY=${NET_GATEWAY:=""}
111 NET_GATEWAY=${NET_GATEWAY:=""}
111 NET_DNS_1=${NET_DNS_1:=""}
112 NET_DNS_1=${NET_DNS_1:=""}
112 NET_DNS_2=${NET_DNS_2:=""}
113 NET_DNS_2=${NET_DNS_2:=""}
113 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
114 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
114 NET_NTP_1=${NET_NTP_1:=""}
115 NET_NTP_1=${NET_NTP_1:=""}
115 NET_NTP_2=${NET_NTP_2:=""}
116 NET_NTP_2=${NET_NTP_2:=""}
116
117
117 # APT settings
118 # APT settings
118 APT_PROXY=${APT_PROXY:=""}
119 APT_PROXY=${APT_PROXY:=""}
119 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
120 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
120
121
121 # Feature settings
122 # Feature settings
122 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
123 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
123 ENABLE_I2C=${ENABLE_I2C:=false}
124 ENABLE_I2C=${ENABLE_I2C:=false}
124 ENABLE_SPI=${ENABLE_SPI:=false}
125 ENABLE_SPI=${ENABLE_SPI:=false}
125 ENABLE_IPV6=${ENABLE_IPV6:=true}
126 ENABLE_IPV6=${ENABLE_IPV6:=true}
126 ENABLE_SSHD=${ENABLE_SSHD:=true}
127 ENABLE_SSHD=${ENABLE_SSHD:=true}
127 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
128 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
128 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
129 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
129 ENABLE_SOUND=${ENABLE_SOUND:=true}
130 ENABLE_SOUND=${ENABLE_SOUND:=true}
130 ENABLE_DBUS=${ENABLE_DBUS:=true}
131 ENABLE_DBUS=${ENABLE_DBUS:=true}
131 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
132 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
132 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
133 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
133 ENABLE_XORG=${ENABLE_XORG:=false}
134 ENABLE_XORG=${ENABLE_XORG:=false}
134 ENABLE_WM=${ENABLE_WM:=""}
135 ENABLE_WM=${ENABLE_WM:=""}
135 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
136 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
136 ENABLE_USER=${ENABLE_USER:=true}
137 ENABLE_USER=${ENABLE_USER:=true}
137 USER_NAME=${USER_NAME:="pi"}
138 USER_NAME=${USER_NAME:="pi"}
138 ENABLE_ROOT=${ENABLE_ROOT:=false}
139 ENABLE_ROOT=${ENABLE_ROOT:=false}
139 ENABLE_QEMU=${ENABLE_QEMU:=false}
140 ENABLE_QEMU=${ENABLE_QEMU:=false}
140 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
141 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
141
142
142 # SSH settings
143 # SSH settings
143 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
144 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
144 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
145 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
145 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
146 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
146 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
147 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
147 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
148 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
148
149
149 # Advanced settings
150 # Advanced settings
150 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
151 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
151 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
152 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
152 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
153 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
153 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
154 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
154 ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
155 ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
155 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
156 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
156 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true}
157 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true}
157 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
158 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
158 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
159 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
159 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
160 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
160 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
161 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
161 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
162 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
162 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
163 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
163 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
164 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
164 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
165 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
165
166
166 # Kernel compilation settings
167 # Kernel compilation settings
167 BUILD_KERNEL=${BUILD_KERNEL:=true}
168 BUILD_KERNEL=${BUILD_KERNEL:=true}
168 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
169 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
169 KERNEL_THREADS=${KERNEL_THREADS:=1}
170 KERNEL_THREADS=${KERNEL_THREADS:=1}
170 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
171 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
171 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
172 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
172 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
173 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
173 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
174 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
174 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
175 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
175 KERNEL_ZSWAP=${KERNEL_ZSWAP:=false}
176 KERNEL_ZSWAP=${KERNEL_ZSWAP:=false}
176 KERNEL_VIRT=${KERNEL_VIRT:=false}
177 KERNEL_VIRT=${KERNEL_VIRT:=false}
177 KERNEL_BPF=${KERNEL_BPF:=true}
178 KERNEL_BPF=${KERNEL_BPF:=true}
178
179
179 # Kernel compilation from source directory settings
180 # Kernel compilation from source directory settings
180 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
181 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
181 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
182 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
182 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
183 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
183 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
184 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
184
185
185 # Reduce disk usage settings
186 # Reduce disk usage settings
186 REDUCE_APT=${REDUCE_APT:=true}
187 REDUCE_APT=${REDUCE_APT:=true}
187 REDUCE_DOC=${REDUCE_DOC:=true}
188 REDUCE_DOC=${REDUCE_DOC:=true}
188 REDUCE_MAN=${REDUCE_MAN:=true}
189 REDUCE_MAN=${REDUCE_MAN:=true}
189 REDUCE_VIM=${REDUCE_VIM:=false}
190 REDUCE_VIM=${REDUCE_VIM:=false}
190 REDUCE_BASH=${REDUCE_BASH:=false}
191 REDUCE_BASH=${REDUCE_BASH:=false}
191 REDUCE_HWDB=${REDUCE_HWDB:=true}
192 REDUCE_HWDB=${REDUCE_HWDB:=true}
192 REDUCE_SSHD=${REDUCE_SSHD:=true}
193 REDUCE_SSHD=${REDUCE_SSHD:=true}
193 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
194 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
194
195
195 # Encrypted filesystem settings
196 # Encrypted filesystem settings
196 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
197 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
197 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
198 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
198 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
199 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
199 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
200 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
200 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
201 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
201
202
202 # Chroot scripts directory
203 # Chroot scripts directory
203 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
204 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
204
205
205 # Packages required in the chroot build environment
206 # Packages required in the chroot build environment
206 APT_INCLUDES=${APT_INCLUDES:=""}
207 APT_INCLUDES=${APT_INCLUDES:=""}
207 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup"
208 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup"
208
209
209 #Packages to exclude from chroot build environment
210 #Packages to exclude from chroot build environment
210 APT_EXCLUDES=${APT_EXCLUDES:=""}
211 APT_EXCLUDES=${APT_EXCLUDES:=""}
211
212
212 # Packages required for bootstrapping
213 # Packages required for bootstrapping
213 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
214 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
214 MISSING_PACKAGES=""
215 MISSING_PACKAGES=""
215
216
216 # Packages installed for c/c++ build environment in chroot (keep empty)
217 # Packages installed for c/c++ build environment in chroot (keep empty)
217 COMPILER_PACKAGES=""
218 COMPILER_PACKAGES=""
218
219
219 #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts
220 #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts
220 if [ "$ENABLE_SYSVINIT" = false ] ; then
221 if [ "$ENABLE_SYSVINIT" = false ] ; then
221 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
222 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
222 fi
223 fi
223
224
224 #Check if apt-cacher-ng has its default port open on and set APT_PROXY
225 #Check if apt-cacher-ng has its default port open on and set APT_PROXY
225 if [ -n "$(lsof -i :3142)" ] ; then
226 if [ -n "$(lsof -i :3142)" ] ; then
226 HTTP_PROXY=http://127.0.0.1:3142/
227 HTTP_PROXY=http://127.0.0.1:3142/
227 fi
228 fi
228
229
229 #netselect-apt does not know buster yet
230 #netselect-apt does not know buster yet
230 if [ "$RELEASE" = "buster" ] ; then
231 if [ "$RELEASE" = "buster" ] ; then
231 RLS=testing
232 RLS=testing
232 else
233 else
233 RLS="$RELEASE"
234 RLS="$RELEASE"
234 fi
235 fi
235
236
236 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
237 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
237 rm "$(pwd)/files/apt/sources.list"
238 rm "$(pwd)/files/apt/sources.list"
238 fi
239 fi
239
240
240 if [ "$ENABLE_NONFREE" = true ] ; then
241 if [ "$ENABLE_NONFREE" = true ] ; then
241 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
242 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
242 else
243 else
243 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
244 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
244 fi
245 fi
245
246
246 #sed and cut the result string so we can use it as APT_SERVER
247 #sed and cut the result string so we can use it as APT_SERVER
247 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|')
248 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|')
248
249
249 #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
250 #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
250 if [ -n "$SET_ARCH" ] ; then
251 if [ -n "$SET_ARCH" ] ; then
251 echo "Setting Architecture specific settings"
252 echo "Setting Architecture specific settings"
252 ##################################
253 ##################################
253 # 64 bit config
254 # 64 bit config
254 ##################################
255 ##################################
255 if [ "$SET_ARCH" = 64 ] ; then
256 if [ "$SET_ARCH" = 64 ] ; then
256 # General 64 bit depended settings
257 # General 64 bit depended settings
257 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
258 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
258 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
259 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
259 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
260 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
260
261
261 # Board specific settings
262 # Board specific settings
262 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
263 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
263 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
264 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
264 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
265 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
265 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
266 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
266 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
267 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
267 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
268 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
268 else
269 else
269 echo "error: Only Raspberry PI 3 and 3B+ support 64 bit"
270 echo "error: Only Raspberry PI 3 and 3B+ support 64 bit"
270 exit 1
271 exit 1
271 fi
272 fi
272 fi
273 fi
273
274
274 # 32 bit configuration
275 # 32 bit configuration
275 if [ "$SET_ARCH" = 32 ] ; then
276 if [ "$SET_ARCH" = 32 ] ; then
276 # General 32 bit dependend settings
277 # General 32 bit dependend settings
277 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
278 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
278 KERNEL_ARCH=${KERNEL_ARCH:=arm}
279 KERNEL_ARCH=${KERNEL_ARCH:=arm}
279 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
280 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
280
281
281 # Hardware specific settings
282 # Hardware specific settings
282 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
283 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
283 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
284 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
284 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
285 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
285 RELEASE_ARCH=${RELEASE_ARCH:=armel}
286 RELEASE_ARCH=${RELEASE_ARCH:=armel}
286 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
287 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
287 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
288 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
288 fi
289 fi
289
290
290 # Hardware specific settings
291 # Hardware specific settings
291 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
292 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
292 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
293 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
293 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
294 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
294 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
295 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
295 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
296 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
296 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
297 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
297 fi
298 fi
298 fi
299 fi
299 #SET_ARCH not set
300 #SET_ARCH not set
300 else
301 else
301 echo "error: Please set '32' or '64' as value for SET_ARCH"
302 echo "error: Please set '32' or '64' as value for SET_ARCH"
302 exit 1
303 exit 1
303 fi
304 fi
304 # Device specific configuration and U-Boot configuration
305 # Device specific configuration and U-Boot configuration
305 case "$RPI_MODEL" in
306 case "$RPI_MODEL" in
306 0)
307 0)
307 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
308 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
308 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
309 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
309 ;;
310 ;;
310 1)
311 1)
311 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
312 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
312 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
313 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
313 ;;
314 ;;
314 1P)
315 1P)
315 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
316 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
316 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
317 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
317 ;;
318 ;;
318 2)
319 2)
319 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
320 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
320 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
321 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
321 ;;
322 ;;
322 3)
323 3)
323 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
324 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
324 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
325 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
325 ;;
326 ;;
326 3P)
327 3P)
327 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
328 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
328 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
329 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
329 ;;
330 ;;
330 *)
331 *)
331 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
332 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
332 exit 1
333 exit 1
333 ;;
334 ;;
334 esac
335 esac
335
336
336 #DEBUG off
337 #DEBUG off
337 set +x
338 set +x
338
339
339 # Check if the internal wireless interface is supported by the RPi model
340 # Check if the internal wireless interface is supported by the RPi model
340 if [ "$ENABLE_WIRELESS" = true ] ; then
341 if [ "$ENABLE_WIRELESS" = true ] ; then
341 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
342 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
342 echo "error: The selected Raspberry Pi model has no internal wireless interface"
343 echo "error: The selected Raspberry Pi model has no internal wireless interface"
343 exit 1
344 exit 1
344 fi
345 fi
345 fi
346 fi
346
347
347 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
348 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
348 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
349 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
349 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
350 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
350 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
351 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
351 exit 1
352 exit 1
352 fi
353 fi
353 fi
354 fi
354
355
355 # Add cmake to compile videocore sources
356 # Add cmake to compile videocore sources
356 if [ "$ENABLE_VIDEOCORE" = true ] ; then
357 if [ "$ENABLE_VIDEOCORE" = true ] ; then
357 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
358 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
358 fi
359 fi
359
360
360 # Add libncurses5 to enable kernel menuconfig
361 # Add libncurses5 to enable kernel menuconfig
361 if [ "$KERNEL_MENUCONFIG" = true ] ; then
362 if [ "$KERNEL_MENUCONFIG" = true ] ; then
362 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
363 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
363 fi
364 fi
364
365
365 # Add ccache compiler cache for (faster) kernel cross (re)compilation
366 # Add ccache compiler cache for (faster) kernel cross (re)compilation
366 if [ "$KERNEL_CCACHE" = true ] ; then
367 if [ "$KERNEL_CCACHE" = true ] ; then
367 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
368 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
368 fi
369 fi
369
370
370 # Add cryptsetup package to enable filesystem encryption
371 # Add cryptsetup package to enable filesystem encryption
371 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
372 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
372 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
373 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
373 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
374 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
374
375
375 if [ -z "$CRYPTFS_PASSWORD" ] ; then
376 if [ -z "$CRYPTFS_PASSWORD" ] ; then
376 echo "error: no password defined (CRYPTFS_PASSWORD)!"
377 echo "error: no password defined (CRYPTFS_PASSWORD)!"
377 exit 1
378 exit 1
378 fi
379 fi
379 ENABLE_INITRAMFS=true
380 ENABLE_INITRAMFS=true
380 fi
381 fi
381
382
382 # Add initramfs generation tools
383 # Add initramfs generation tools
383 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
384 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
384 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
385 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
385 fi
386 fi
386
387
387 # Add device-tree-compiler required for building the U-Boot bootloader
388 # Add device-tree-compiler required for building the U-Boot bootloader
388 if [ "$ENABLE_UBOOT" = true ] ; then
389 if [ "$ENABLE_UBOOT" = true ] ; then
389 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
390 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
390 else
391 else
391 if [ "$ENABLE_UBOOTUSB" = true ] ; then
392 if [ "$ENABLE_UBOOTUSB" = true ] ; then
392 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
393 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
393 exit 1
394 exit 1
394 fi
395 fi
395 fi
396 fi
396
397
397 # Check if root SSH (v2) public key file exists
398 # Check if root SSH (v2) public key file exists
398 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
399 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
399 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
400 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
400 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
401 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
401 exit 1
402 exit 1
402 fi
403 fi
403 fi
404 fi
404
405
405 # Check if $USER_NAME SSH (v2) public key file exists
406 # Check if $USER_NAME SSH (v2) public key file exists
406 if [ -n "$SSH_USER_PUB_KEY" ] ; then
407 if [ -n "$SSH_USER_PUB_KEY" ] ; then
407 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
408 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
408 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
409 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
409 exit 1
410 exit 1
410 fi
411 fi
411 fi
412 fi
412
413
413 # Check if all required packages are installed on the build system
414 # Check if all required packages are installed on the build system
414 for package in $REQUIRED_PACKAGES ; do
415 for package in $REQUIRED_PACKAGES ; do
415 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
416 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
416 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
417 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
417 fi
418 fi
418 done
419 done
419
420
420 # If there are missing packages ask confirmation for install, or exit
421 # If there are missing packages ask confirmation for install, or exit
421 if [ -n "$MISSING_PACKAGES" ] ; then
422 if [ -n "$MISSING_PACKAGES" ] ; then
422 echo "the following packages needed by this script are not installed:"
423 echo "the following packages needed by this script are not installed:"
423 echo "$MISSING_PACKAGES"
424 echo "$MISSING_PACKAGES"
424
425
425 printf "\ndo you want to install the missing packages right now? [y/n] "
426 printf "\ndo you want to install the missing packages right now? [y/n] "
426 read -r confirm
427 read -r confirm
427 [ "$confirm" != "y" ] && exit 1
428 [ "$confirm" != "y" ] && exit 1
428
429
429 # Make sure all missing required packages are installed
430 # Make sure all missing required packages are installed
430 apt-get -qq -y install "${MISSING_PACKAGES}"
431 apt-get -qq -y install "${MISSING_PACKAGES}"
431 fi
432 fi
432
433
433 # Check if ./bootstrap.d directory exists
434 # Check if ./bootstrap.d directory exists
434 if [ ! -d "./bootstrap.d/" ] ; then
435 if [ ! -d "./bootstrap.d/" ] ; then
435 echo "error: './bootstrap.d' required directory not found!"
436 echo "error: './bootstrap.d' required directory not found!"
436 exit 1
437 exit 1
437 fi
438 fi
438
439
439 # Check if ./files directory exists
440 # Check if ./files directory exists
440 if [ ! -d "./files/" ] ; then
441 if [ ! -d "./files/" ] ; then
441 echo "error: './files' required directory not found!"
442 echo "error: './files' required directory not found!"
442 exit 1
443 exit 1
443 fi
444 fi
444
445
445 # Check if specified KERNELSRC_DIR directory exists
446 # Check if specified KERNELSRC_DIR directory exists
446 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
447 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
447 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
448 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
448 exit 1
449 exit 1
449 fi
450 fi
450
451
451 # Check if specified UBOOTSRC_DIR directory exists
452 # Check if specified UBOOTSRC_DIR directory exists
452 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
453 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
453 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
454 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
454 exit 1
455 exit 1
455 fi
456 fi
456
457
457 # Check if specified VIDEOCORESRC_DIR directory exists
458 # Check if specified VIDEOCORESRC_DIR directory exists
458 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
459 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
459 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
460 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
460 exit 1
461 exit 1
461 fi
462 fi
462
463
463 # Check if specified FBTURBOSRC_DIR directory exists
464 # Check if specified FBTURBOSRC_DIR directory exists
464 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
465 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
465 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
466 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
466 exit 1
467 exit 1
467 fi
468 fi
468
469
469 # Check if specified CHROOT_SCRIPTS directory exists
470 # Check if specified CHROOT_SCRIPTS directory exists
470 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
471 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
471 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
472 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
472 exit 1
473 exit 1
473 fi
474 fi
474
475
475 # Check if specified device mapping already exists (will be used by cryptsetup)
476 # Check if specified device mapping already exists (will be used by cryptsetup)
476 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
477 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
477 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
478 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
478 exit 1
479 exit 1
479 fi
480 fi
480
481
481 # Don't clobber an old build
482 # Don't clobber an old build
482 if [ -e "$BUILDDIR" ] ; then
483 if [ -e "$BUILDDIR" ] ; then
483 echo "error: directory ${BUILDDIR} already exists, not proceeding"
484 echo "error: directory ${BUILDDIR} already exists, not proceeding"
484 exit 1
485 exit 1
485 fi
486 fi
486
487
487 # Setup chroot directory
488 # Setup chroot directory
488 mkdir -p "${R}"
489 mkdir -p "${R}"
489
490
490 # Check if build directory has enough of free disk space >512MB
491 # Check if build directory has enough of free disk space >512MB
491 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
492 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
492 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
493 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
493 exit 1
494 exit 1
494 fi
495 fi
495
496
496 set -x
497 set -x
497
498
498 # Call "cleanup" function on various signals and errors
499 # Call "cleanup" function on various signals and errors
499 trap cleanup 0 1 2 3 6
500 trap cleanup 0 1 2 3 6
500
501
501 # Add required packages for the minbase installation
502 # Add required packages for the minbase installation
502 if [ "$ENABLE_MINBASE" = true ] ; then
503 if [ "$ENABLE_MINBASE" = true ] ; then
503 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
504 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
504 fi
505 fi
505
506
506 # Add parted package, required to get partprobe utility
507 # Add parted package, required to get partprobe utility
507 if [ "$EXPANDROOT" = true ] ; then
508 if [ "$EXPANDROOT" = true ] ; then
508 APT_INCLUDES="${APT_INCLUDES},parted"
509 APT_INCLUDES="${APT_INCLUDES},parted"
509 fi
510 fi
510
511
511 # Add dbus package, recommended if using systemd
512 # Add dbus package, recommended if using systemd
512 if [ "$ENABLE_DBUS" = true ] ; then
513 if [ "$ENABLE_DBUS" = true ] ; then
513 APT_INCLUDES="${APT_INCLUDES},dbus"
514 APT_INCLUDES="${APT_INCLUDES},dbus"
514 fi
515 fi
515
516
516 # Add iptables IPv4/IPv6 package
517 # Add iptables IPv4/IPv6 package
517 if [ "$ENABLE_IPTABLES" = true ] ; then
518 if [ "$ENABLE_IPTABLES" = true ] ; then
518 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
519 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
519 fi
520 fi
520
521
521 # Add openssh server package
522 # Add openssh server package
522 if [ "$ENABLE_SSHD" = true ] ; then
523 if [ "$ENABLE_SSHD" = true ] ; then
523 APT_INCLUDES="${APT_INCLUDES},openssh-server"
524 APT_INCLUDES="${APT_INCLUDES},openssh-server"
524 fi
525 fi
525
526
526 # Add alsa-utils package
527 # Add alsa-utils package
527 if [ "$ENABLE_SOUND" = true ] ; then
528 if [ "$ENABLE_SOUND" = true ] ; then
528 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
529 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
529 fi
530 fi
530
531
531 # Add rng-tools package
532 # Add rng-tools package
532 if [ "$ENABLE_HWRANDOM" = true ] ; then
533 if [ "$ENABLE_HWRANDOM" = true ] ; then
533 APT_INCLUDES="${APT_INCLUDES},rng-tools"
534 APT_INCLUDES="${APT_INCLUDES},rng-tools"
534 fi
535 fi
535
536
536 # Add fbturbo video driver
537 # Add fbturbo video driver
537 if [ "$ENABLE_FBTURBO" = true ] ; then
538 if [ "$ENABLE_FBTURBO" = true ] ; then
538 # Enable xorg package dependencies
539 # Enable xorg package dependencies
539 ENABLE_XORG=true
540 ENABLE_XORG=true
540 fi
541 fi
541
542
542 # Add user defined window manager package
543 # Add user defined window manager package
543 if [ -n "$ENABLE_WM" ] ; then
544 if [ -n "$ENABLE_WM" ] ; then
544 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
545 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
545
546
546 # Enable xorg package dependencies
547 # Enable xorg package dependencies
547 ENABLE_XORG=true
548 ENABLE_XORG=true
548 fi
549 fi
549
550
550 # Add xorg package
551 # Add xorg package
551 if [ "$ENABLE_XORG" = true ] ; then
552 if [ "$ENABLE_XORG" = true ] ; then
552 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
553 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
553 fi
554 fi
554
555
555 # Replace selected packages with smaller clones
556 # Replace selected packages with smaller clones
556 if [ "$ENABLE_REDUCE" = true ] ; then
557 if [ "$ENABLE_REDUCE" = true ] ; then
557 # Add levee package instead of vim-tiny
558 # Add levee package instead of vim-tiny
558 if [ "$REDUCE_VIM" = true ] ; then
559 if [ "$REDUCE_VIM" = true ] ; then
559 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
560 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
560 fi
561 fi
561
562
562 # Add dropbear package instead of openssh-server
563 # Add dropbear package instead of openssh-server
563 if [ "$REDUCE_SSHD" = true ] ; then
564 if [ "$REDUCE_SSHD" = true ] ; then
564 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
565 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
565 fi
566 fi
566 fi
567 fi
567
568
568 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
569 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
569 if [ "$ENABLE_SYSVINIT" = false ] ; then
570 if [ "$ENABLE_SYSVINIT" = false ] ; then
570 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
571 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
571 fi
572 fi
572
573
573 # Configure kernel sources if no KERNELSRC_DIR
574 # Configure kernel sources if no KERNELSRC_DIR
574 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
575 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
575 KERNELSRC_CONFIG=true
576 KERNELSRC_CONFIG=true
576 fi
577 fi
577
578
578 # Configure reduced kernel
579 # Configure reduced kernel
579 if [ "$KERNEL_REDUCE" = true ] ; then
580 if [ "$KERNEL_REDUCE" = true ] ; then
580 KERNELSRC_CONFIG=false
581 KERNELSRC_CONFIG=false
581 fi
582 fi
582
583
583 # Configure qemu compatible kernel
584 # Configure qemu compatible kernel
584 if [ "$ENABLE_QEMU" = true ] ; then
585 if [ "$ENABLE_QEMU" = true ] ; then
585 DTB_FILE=vexpress-v2p-ca15_a7.dtb
586 DTB_FILE=vexpress-v2p-ca15_a7.dtb
586 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
587 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
587 KERNEL_DEFCONFIG="vexpress_defconfig"
588 KERNEL_DEFCONFIG="vexpress_defconfig"
588 if [ "$KERNEL_MENUCONFIG" = false ] ; then
589 if [ "$KERNEL_MENUCONFIG" = false ] ; then
589 KERNEL_OLDDEFCONFIG=true
590 KERNEL_OLDDEFCONFIG=true
590 fi
591 fi
591 fi
592 fi
592
593
593 # Execute bootstrap scripts
594 # Execute bootstrap scripts
594 for SCRIPT in bootstrap.d/*.sh; do
595 for SCRIPT in bootstrap.d/*.sh; do
595 head -n 3 "$SCRIPT"
596 head -n 3 "$SCRIPT"
596 . "$SCRIPT"
597 . "$SCRIPT"
597 done
598 done
598
599
599 ## Execute custom bootstrap scripts
600 ## Execute custom bootstrap scripts
600 if [ -d "custom.d" ] ; then
601 if [ -d "custom.d" ] ; then
601 for SCRIPT in custom.d/*.sh; do
602 for SCRIPT in custom.d/*.sh; do
602 . "$SCRIPT"
603 . "$SCRIPT"
603 done
604 done
604 fi
605 fi
605
606
606 # Execute custom scripts inside the chroot
607 # Execute custom scripts inside the chroot
607 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
608 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
608 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
609 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
609 chroot_exec /bin/bash -x <<'EOF'
610 chroot_exec /bin/bash -x <<'EOF'
610 for SCRIPT in /chroot_scripts/* ; do
611 for SCRIPT in /chroot_scripts/* ; do
611 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
612 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
612 $SCRIPT
613 $SCRIPT
613 fi
614 fi
614 done
615 done
615 EOF
616 EOF
616 rm -rf "${R}/chroot_scripts"
617 rm -rf "${R}/chroot_scripts"
617 fi
618 fi
618
619
619 # Remove c/c++ build environment from the chroot
620 # Remove c/c++ build environment from the chroot
620 chroot_remove_cc
621 chroot_remove_cc
621
622
622 # Generate required machine-id
623 # Generate required machine-id
623 MACHINE_ID=$(dbus-uuidgen)
624 MACHINE_ID=$(dbus-uuidgen)
624 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
625 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
625 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
626 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
626
627
627 # APT Cleanup
628 # APT Cleanup
628 chroot_exec apt-get -y clean
629 chroot_exec apt-get -y clean
629 chroot_exec apt-get -y autoclean
630 chroot_exec apt-get -y autoclean
630 chroot_exec apt-get -y autoremove
631 chroot_exec apt-get -y autoremove
631
632
632 # Unmount mounted filesystems
633 # Unmount mounted filesystems
633 umount -l "${R}/proc"
634 umount -l "${R}/proc"
634 umount -l "${R}/sys"
635 umount -l "${R}/sys"
635
636
636 # Clean up directories
637 # Clean up directories
637 rm -rf "${R}/run/*"
638 rm -rf "${R}/run/*"
638 rm -rf "${R}/tmp/*"
639 rm -rf "${R}/tmp/*"
639
640
640 # Clean up files
641 # Clean up files
641 rm -f "${ETC_DIR}/ssh/ssh_host_*"
642 rm -f "${ETC_DIR}/ssh/ssh_host_*"
642 rm -f "${ETC_DIR}/dropbear/dropbear_*"
643 rm -f "${ETC_DIR}/dropbear/dropbear_*"
643 rm -f "${ETC_DIR}/apt/sources.list.save"
644 rm -f "${ETC_DIR}/apt/sources.list.save"
644 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
645 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
645 rm -f "${ETC_DIR}/*-"
646 rm -f "${ETC_DIR}/*-"
646 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
647 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
647 rm -f "${ETC_DIR}/resolv.conf"
648 rm -f "${ETC_DIR}/resolv.conf"
648 rm -f "${R}/root/.bash_history"
649 rm -f "${R}/root/.bash_history"
649 rm -f "${R}/var/lib/urandom/random-seed"
650 rm -f "${R}/var/lib/urandom/random-seed"
650 rm -f "${R}/initrd.img"
651 rm -f "${R}/initrd.img"
651 rm -f "${R}/vmlinuz"
652 rm -f "${R}/vmlinuz"
652 rm -f "${R}${QEMU_BINARY}"
653 rm -f "${R}${QEMU_BINARY}"
653
654
654 if [ "$ENABLE_QEMU" = true ] ; then
655 if [ "$ENABLE_QEMU" = true ] ; then
655 # Setup QEMU directory
656 # Setup QEMU directory
656 mkdir "${BASEDIR}/qemu"
657 mkdir "${BASEDIR}/qemu"
657
658
658 # Copy kernel image to QEMU directory
659 # Copy kernel image to QEMU directory
659 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
660 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
660
661
661 # Copy kernel config to QEMU directory
662 # Copy kernel config to QEMU directory
662 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
663 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
663
664
664 # Copy kernel dtbs to QEMU directory
665 # Copy kernel dtbs to QEMU directory
665 for dtb in "${BOOT_DIR}/"*.dtb ; do
666 for dtb in "${BOOT_DIR}/"*.dtb ; do
666 if [ -f "${dtb}" ] ; then
667 if [ -f "${dtb}" ] ; then
667 install_readonly "${dtb}" "${BASEDIR}/qemu/"
668 install_readonly "${dtb}" "${BASEDIR}/qemu/"
668 fi
669 fi
669 done
670 done
670
671
671 # Copy kernel overlays to QEMU directory
672 # Copy kernel overlays to QEMU directory
672 if [ -d "${BOOT_DIR}/overlays" ] ; then
673 if [ -d "${BOOT_DIR}/overlays" ] ; then
673 # Setup overlays dtbs directory
674 # Setup overlays dtbs directory
674 mkdir "${BASEDIR}/qemu/overlays"
675 mkdir "${BASEDIR}/qemu/overlays"
675
676
676 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
677 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
677 if [ -f "${dtb}" ] ; then
678 if [ -f "${dtb}" ] ; then
678 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
679 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
679 fi
680 fi
680 done
681 done
681 fi
682 fi
682
683
683 # Copy u-boot files to QEMU directory
684 # Copy u-boot files to QEMU directory
684 if [ "$ENABLE_UBOOT" = true ] ; then
685 if [ "$ENABLE_UBOOT" = true ] ; then
685 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
686 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
686 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
687 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
687 fi
688 fi
688 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
689 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
689 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
690 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
690 fi
691 fi
691 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
692 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
692 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
693 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
693 fi
694 fi
694 fi
695 fi
695
696
696 # Copy initramfs to QEMU directory
697 # Copy initramfs to QEMU directory
697 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
698 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
698 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
699 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
699 fi
700 fi
700 fi
701 fi
701
702
702 # Calculate size of the chroot directory in KB
703 # Calculate size of the chroot directory in KB
703 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
704 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
704
705
705 # Calculate the amount of needed 512 Byte sectors
706 # Calculate the amount of needed 512 Byte sectors
706 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
707 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
707 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
708 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
708 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
709 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
709
710
710 # The root partition is EXT4
711 # The root partition is EXT4
711 # This means more space than the actual used space of the chroot is used.
712 # This means more space than the actual used space of the chroot is used.
712 # As overhead for journaling and reserved blocks 35% are added.
713 # As overhead for journaling and reserved blocks 35% are added.
713 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
714 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
714
715
715 # Calculate required image size in 512 Byte sectors
716 # Calculate required image size in 512 Byte sectors
716 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
717 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
717
718
718 # Prepare image file
719 # Prepare image file
719 if [ "$ENABLE_SPLITFS" = true ] ; then
720 if [ "$ENABLE_SPLITFS" = true ] ; then
720 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
721 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
721 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
722 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
722 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
723 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
723 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
724 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
724
725
725 # Write firmware/boot partition tables
726 # Write firmware/boot partition tables
726 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
727 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
727 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
728 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
728 EOM
729 EOM
729
730
730 # Write root partition table
731 # Write root partition table
731 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
732 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
732 ${TABLE_SECTORS},${ROOT_SECTORS},83
733 ${TABLE_SECTORS},${ROOT_SECTORS},83
733 EOM
734 EOM
734
735
735 # Setup temporary loop devices
736 # Setup temporary loop devices
736 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
737 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
737 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
738 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
738 else # ENABLE_SPLITFS=false
739 else # ENABLE_SPLITFS=false
739 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
740 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
740 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
741 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
741
742
742 # Write partition table
743 # Write partition table
743 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
744 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
744 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
745 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
745 ${ROOT_OFFSET},${ROOT_SECTORS},83
746 ${ROOT_OFFSET},${ROOT_SECTORS},83
746 EOM
747 EOM
747
748
748 # Setup temporary loop devices
749 # Setup temporary loop devices
749 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
750 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
750 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
751 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
751 fi
752 fi
752
753
753 if [ "$ENABLE_CRYPTFS" = true ] ; then
754 if [ "$ENABLE_CRYPTFS" = true ] ; then
754 # Create dummy ext4 fs
755 # Create dummy ext4 fs
755 mkfs.ext4 "$ROOT_LOOP"
756 mkfs.ext4 "$ROOT_LOOP"
756
757
757 # Setup password keyfile
758 # Setup password keyfile
758 touch .password
759 touch .password
759 chmod 600 .password
760 chmod 600 .password
760 echo -n ${CRYPTFS_PASSWORD} > .password
761 echo -n ${CRYPTFS_PASSWORD} > .password
761
762
762 # Initialize encrypted partition
763 # Initialize encrypted partition
763 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
764 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
764
765
765 # Open encrypted partition and setup mapping
766 # Open encrypted partition and setup mapping
766 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
767 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
767
768
768 # Secure delete password keyfile
769 # Secure delete password keyfile
769 shred -zu .password
770 shred -zu .password
770
771
771 # Update temporary loop device
772 # Update temporary loop device
772 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
773 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
773
774
774 # Wipe encrypted partition (encryption cipher is used for randomness)
775 # Wipe encrypted partition (encryption cipher is used for randomness)
775 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
776 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
776 fi
777 fi
777
778
778 # Build filesystems
779 # Build filesystems
779 mkfs.vfat "$FRMW_LOOP"
780 mkfs.vfat "$FRMW_LOOP"
780 mkfs.ext4 "$ROOT_LOOP"
781 mkfs.ext4 "$ROOT_LOOP"
781
782
782 # Mount the temporary loop devices
783 # Mount the temporary loop devices
783 mkdir -p "$BUILDDIR/mount"
784 mkdir -p "$BUILDDIR/mount"
784 mount "$ROOT_LOOP" "$BUILDDIR/mount"
785 mount "$ROOT_LOOP" "$BUILDDIR/mount"
785
786
786 mkdir -p "$BUILDDIR/mount/boot/firmware"
787 mkdir -p "$BUILDDIR/mount/boot/firmware"
787 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
788 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
788
789
789 # Copy all files from the chroot to the loop device mount point directory
790 # Copy all files from the chroot to the loop device mount point directory
790 rsync -a "${R}/" "$BUILDDIR/mount/"
791 rsync -a "${R}/" "$BUILDDIR/mount/"
791
792
792 # Unmount all temporary loop devices and mount points
793 # Unmount all temporary loop devices and mount points
793 cleanup
794 cleanup
794
795
795 # Create block map file(s) of image(s)
796 # Create block map file(s) of image(s)
796 if [ "$ENABLE_SPLITFS" = true ] ; then
797 if [ "$ENABLE_SPLITFS" = true ] ; then
797 # Create block map files for "bmaptool"
798 # Create block map files for "bmaptool"
798 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
799 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
799 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
800 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
800
801
801 # Image was successfully created
802 # Image was successfully created
802 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
803 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
803 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
804 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
804 else
805 else
805 # Create block map file for "bmaptool"
806 # Create block map file for "bmaptool"
806 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
807 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
807
808
808 # Image was successfully created
809 # Image was successfully created
809 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
810 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
810
811
811 # Create qemu qcow2 image
812 # Create qemu qcow2 image
812 if [ "$ENABLE_QEMU" = true ] ; then
813 if [ "$ENABLE_QEMU" = true ] ; then
813 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
814 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
814 QEMU_SIZE=16G
815 QEMU_SIZE=16G
815
816
816 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
817 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
817 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
818 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
818
819
819 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
820 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
820 fi
821 fi
821 fi
822 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant