Skip to content

Commit 722ae84

Browse files
authored
Merge pull request RetroPie#3739 from joolswills/image_bullseye
Image creation changes for bullseye
2 parents 4a8597c + 522aeea commit 722ae84

5 files changed

Lines changed: 110 additions & 78 deletions

File tree

scriptmodules/admin/image.sh

Lines changed: 64 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@ rp_module_section=""
1515
rp_module_flags=""
1616

1717
function depends_image() {
18-
local depends=(kpartx unzip binfmt-support rsync parted squashfs-tools dosfstools e2fsprogs openssl xz-utils)
18+
local depends=(kpartx unzip binfmt-support rsync parted squashfs-tools dosfstools e2fsprogs xz-utils)
1919
isPlatform "x86" && depends+=(qemu-user-static)
2020
getDepends "${depends[@]}"
2121
}
2222

23+
function _get_info_image() {
24+
local dist="$1"
25+
local key="$2"
26+
local ini="$md_data/dists/${dist}.ini"
27+
[[ ! -f "$ini" ]] && fatalError "Definition file $ini does not exist"
28+
29+
iniConfig "=" "\"" "$ini"
30+
iniGet "$key"
31+
[[ -z "$ini_value" ]] && fatalError "Unable to locate key '$key' in definition file $ini"
32+
echo "$ini_value"
33+
}
34+
2335
function create_chroot_image() {
2436
local dist="$1"
25-
[[ -z "$dist" ]] && dist="buster"
37+
[[ -z "$dist" ]] && return 1
2638

2739
local chroot="$2"
2840
[[ -z "$chroot" ]] && chroot="$md_build/chroot"
@@ -32,42 +44,21 @@ function create_chroot_image() {
3244

3345
mkdir -p "$chroot"
3446

35-
local url
36-
local image
37-
local fmt=".img.xz"
38-
case "$dist" in
39-
jessie)
40-
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/2017-07-05-raspbian-jessie-lite.zip"
41-
fmt=".zip"
42-
;;
43-
stretch)
44-
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/2019-04-08-raspbian-stretch-lite.zip"
45-
fmt=".zip"
46-
;;
47-
buster)
48-
url="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf_latest"
49-
;;
50-
bullseye)
51-
url="https://downloads.raspberrypi.org/raspios_lite_armhf_latest"
52-
;;
53-
*)
54-
md_ret_errors+=("Unknown/unsupported Raspbian version")
55-
return 1
56-
;;
57-
esac
47+
local url=$(_get_info_image "$dist" "url")
48+
local format=$(_get_info_image "$dist" "format")
5849

5950
local base="raspbian-${dist}-lite"
60-
local image="$base.img"
51+
local image="${dist}.img"
52+
local dest="${image}.${format}"
6153
if [[ ! -f "$image" ]]; then
62-
local dest="$base$fmt"
63-
case "$fmt" in
64-
.zip)
54+
case "$format" in
55+
zip)
6556
download "$url" "$dest"
6657
unzip -o "$dest"
6758
mv "$(unzip -Z -1 "$dest")" "$image"
6859
rm "$dest"
6960
;;
70-
.img.xz)
61+
xz)
7162
download "$url" "$dest"
7263
xz -d -v "$dest"
7364
;;
@@ -94,19 +85,30 @@ function create_chroot_image() {
9485
umount -l "$tmp/boot" "$tmp"
9586
rm -rf "$tmp"
9687

97-
kpartx -d "$image"
88+
dmsetup remove "${partitions[@]}"
9889

9990
popd
10091
return 0
10192
}
10293

10394
function install_rp_image() {
10495
local platform="$1"
105-
[[ -z "$platform" ]] && return
96+
if [[ -z "$platform" ]]; then
97+
printMsgs "console" "Requires a platform (eg rpi3/rpi4)"
98+
return 1
99+
fi
106100

107-
local chroot="$2"
101+
local dist="$2"
102+
if [[ -z "$dist" ]]; then
103+
printMsgs "Requires a distribution name (eg rpios-buster/rpios-bullseye)"
104+
return 1
105+
fi
106+
107+
local chroot="$3"
108108
[[ -z "$chroot" ]] && chroot="$md_build/chroot"
109109

110+
local dist_version="$(_get_info_image "$dist" "version")"
111+
110112
# hostname to retropie
111113
echo "retropie" >"$chroot/etc/hostname"
112114
sed -i "s/raspberrypi/retropie/" "$chroot/etc/hosts"
@@ -123,17 +125,25 @@ function install_rp_image() {
123125

124126
# set default GPU mem (videocore only) and overscan_scale so ES scales to overscan settings.
125127
iniConfig "=" "" "$chroot/boot/config.txt"
126-
if ! [[ "$platform" =~ rpi.*kms|rpi4 ]]; then
128+
if [[ "$dist_version" -lt 11 && "platform" != "rpi4" ]]; then
127129
iniSet "gpu_mem_256" 128
128130
iniSet "gpu_mem_512" 256
129131
iniSet "gpu_mem_1024" 256
130132
fi
131133
iniSet "overscan_scale" 1
132134

135+
# disable 64bit kernel
136+
iniSet "arm_64bit" 0
137+
133138
[[ -z "$__chroot_branch" ]] && __chroot_branch="master"
134139
cat > "$chroot/home/pi/install.sh" <<_EOF_
135140
#!/bin/bash
136141
cd
142+
if systemctl is-enabled userconfig &>/dev/null; then
143+
echo "pi:raspberry" | sudo chpasswd
144+
sudo systemctl disable userconfig
145+
sudo systemctl --quiet enable getty@tty1
146+
fi
137147
sudo apt-get update
138148
sudo apt-get -y install git dialog xmlstarlet joystick
139149
git clone -b "$__chroot_branch" https://github.com/RetroPie/RetroPie-Setup.git
@@ -243,8 +253,7 @@ function create_image() {
243253
parted -s "$image" -- \
244254
mklabel msdos \
245255
unit mib \
246-
mkpart primary fat16 4 260 \
247-
set 1 boot on \
256+
mkpart primary fat32 4 260 \
248257
mkpart primary 260 -1s
249258

250259
# format
@@ -260,8 +269,10 @@ function create_image() {
260269
local part_boot="${partitions[0]}"
261270
local part_root="${partitions[1]}"
262271

263-
mkfs.vfat -F 16 -n boot "$part_boot"
264-
mkfs.ext4 -O ^metadata_csum,^huge_file -L retropie "$part_root"
272+
mkfs.vfat -F 32 -n bootfs "$part_boot"
273+
# use the mke2fs config from the chroot so we create the filesystem with supported features
274+
# disable huge_file & 64bit as with the Raspberry Pi OS images
275+
MKE2FS_CONFIG="$chroot/etc/mke2fs.conf" mkfs.ext4 -O ^huge_file,^64bit -L retropie "$part_root"
265276

266277
parted "$image_name" print
267278

@@ -285,13 +296,6 @@ function create_image() {
285296
sed -i "s/$old_id/$new_id/" "$tmp/boot/cmdline.txt"
286297
sed -i "s/$old_id/$new_id/g" "$tmp/etc/fstab"
287298

288-
# pre-set the default username and password on RaspiOS 11
289-
# otherwise the 1st time boot will prompt a username/pass change
290-
if [[ "$image" == *bullseye* ]]; then
291-
local default_pwd="$(echo 'raspberry' | openssl passwd -6 -stdin)"
292-
echo "pi:$default_pwd" > "$tmp/boot/userconf.txt"
293-
fi
294-
295299
# unmount
296300
umount -l "$tmp/boot" "$tmp"
297301
rm -rf "$tmp"
@@ -319,11 +323,12 @@ function create_bb_image() {
319323
}
320324

321325
function all_image() {
322-
local platform
323-
local image
324326
local dist="$1"
325327
local make_bb="$2"
326-
for platform in rpi1 rpi2 rpi4; do
328+
local platforms="$(_get_info_image "$dist" "platforms")"
329+
local platform
330+
printMsgs "heading" "Building $platforms images based on $dist ..."
331+
for platform in $platforms; do
327332
platform_image "$platform" "$dist" "$make_bb"
328333
done
329334
combine_json_image
@@ -335,41 +340,22 @@ function platform_image() {
335340
local make_bb="$3"
336341
[[ -z "$platform" ]] && return 1
337342

338-
if [[ "$dist" == "stretch" && "$platform" == "rpi4" ]]; then
339-
printMsgs "console" "Platform $platform on $dist is unsupported."
340-
return 1
341-
fi
342-
343343
local dest="$__tmpdir/images"
344344
mkdir -p "$dest"
345345

346-
local image_base="retropie-${dist}-${__version}-"
347-
case "$platform" in
348-
rpi1)
349-
image_base+="rpi1_zero"
350-
image_platform="RPI 1/Zero"
351-
;;
352-
rpi2)
353-
image_base+="rpi2_3_zero2w"
354-
image_platform="RPI 2/3/Zero 2 W"
355-
;;
356-
rpi3)
357-
image_base+="rpi3"
358-
image_platform="RPI 3"
359-
;;
360-
rpi4)
361-
image_base+="rpi4_400"
362-
image_platform="RPI 4/400"
363-
;;
364-
*)
365-
fatalError "Unknown platform $platform for image building"
366-
;;
367-
esac
346+
printMsgs "heading" "Building $platform image based on $dist ..."
347+
348+
rp_callModule image create_chroot "$dist"
349+
rp_callModule image install_rp "$platform" "$dist" "$md_build/chroot"
350+
351+
local dist_name="$(_get_info_image "$dist" "name")"
352+
local file_add="$(_get_info_image "$dist" "file_${platform}")"
353+
local image_title="$(_get_info_image "$dist" "title_${platform}")"
354+
355+
local image_base="retropie-${dist_name}-${__version}-${file_add}"
368356
local image_name="${image_base}.img"
369357
local image_file="$dest/$image_name"
370358

371-
rp_callModule image create_chroot "$dist"
372-
rp_callModule image install_rp "$platform"
373359
rp_callModule image create "$image_file"
374360
[[ "$make_bb" -eq 1 ]] && rp_callModule image create_bb "$dest/${image_base}-berryboot.img256"
375361

@@ -384,7 +370,7 @@ function platform_image() {
384370
template="${template/IMG_SHA256/$(sha256sum $image_file | cut -d" " -f1)}"
385371
template="${template/IMG_DOWNLOAD_SIZE/$(stat -c %s ${image_file}.gz)}"
386372
template="${template/IMG_VERSION/$__version}"
387-
template="${template/IMG_PLATFORM/$image_platform}"
373+
template="${template/IMG_PLATFORM/$image_title}"
388374
template="${template/IMG_DATE/$(date '+%Y-%m-%d')}"
389375
echo "$template" >"${image_file}.json"
390376

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name="bullseye"
2+
version="11"
3+
url="https://downloads.raspberrypi.org/raspios_lite_armhf_latest"
4+
format="xz"
5+
platforms="rpi1 rpi2 rpi3 rpi4"
6+
file_rpi1="rpi1_zero"
7+
title_rpi1="RPI 1/Zero"
8+
file_rpi2="rpi2"
9+
title_rpi2="RPI 2"
10+
file_rpi3="rpi3_zero2w"
11+
title_rpi3="RPI 3/Zero 2 W"
12+
file_rpi4="rpi4_400"
13+
title_rpi4="RPI 4/400"
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name="buster"
2+
version="10"
3+
url="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf_latest"
4+
format="xz"
5+
platforms="rpi1 rpi2 rpi4"
6+
file_rpi1="rpi1_zero"
7+
title_rpi1="RPI 1/Zero"
8+
file_rpi2="rpi2_3_zero2w"
9+
title_rpi2="RPI 2/3/Zero 2 W"
10+
file_rpi4="rpi4_400"
11+
title_rpi4="RPI 4/400"
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name="jessie"
2+
version="8"
3+
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/2017-07-05-raspbian-jessie-lite.zip"
4+
format="zip"
5+
platforms="rpi1 rpi2"
6+
file_rpi1="rpi1_zero"
7+
title_rpi1="RPI 1/Zero"
8+
file_rpi2="rpi2_3"
9+
title_rpi2="RPI 2/3"
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name="stretch"
2+
version="9"
3+
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/2019-04-08-raspbian-stretch-lite.zip"
4+
format="xz"
5+
platforms="rpi1 rpi2"
6+
file_rpi1="rpi1_zero"
7+
title_rpi1="RPI 1/Zero"
8+
file_rpi2="rpi2_3"
9+
title_rpi2="RPI 2/3"
10+

0 commit comments

Comments
 (0)