3 # [x] resize root filesystem
4 # [x] find root fs uuid
5 # [x] find boot partition
9 # [x] extract wifi firmware
10 # [ ] on life system skip everything but wifi firmware
11 # [ ] In order to change the uuid of the root filesystem, bootstrap.sh must remember it in a file within the mounted disk image. And the initrd needs to change it.
13 my $firmware_tarball = '/boot/efi/linux-firmware.tar';
14 my $firmware_manifest = '/lib/firmware/ASAHI_FIRMWARE_MANIFEST';
19 open(MOUNT
, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!");
24 if (/^([\S]+)+ \/ /) {
29 die("Could not find root device");
33 find_fs_uuid_of_device
35 my $dev = shift || die;
36 my $blkid_output = `blkid ${dev}`;
38 if ($blkid_output =~ /UUID="([^"]+)"/) {
42 die("Could not find fs uuid of $dev");
48 my $uuid_in_grub_cfg = shift || die;
51 my $efi_parition = undef;
54 if (/^([\S]+):.*TYPE="vfat"/) {
55 push(@candidates, $1);
59 for my $dev (@candidates) {
60 system("mount -o ro $dev /mnt");
61 if (-f
'/mnt/EFI/boot/grub.cfg') {
62 open(GRUBCFG
, '<', '/mnt/EFI/boot/grub.cfg') || die ("Can't open /mnt/EFI/boot/grub.cfg: $!");
63 my @lines = <GRUBCFG
>;
65 if (/${uuid_in_grub_cfg}/) {
71 system("umount /mnt");
72 last if defined $efi_parition;
75 die ("No efi parition found") unless defined $efi_parition;
83 my $root_fs_uuid = shift || die;
84 my $efi_fs_uuid = shift || die;
86 open(FSTAB
, '>', '/etc/fstab') || die ("Can not open fstab");
89 UUID="$root_fs_uuid" / ext4 defaults 0 0
90 UUID="$efi_fs_uuid" /boot/efi vfat defaults 0 0
98 system('apt-get install -y grub-efi-arm64-signed-');
99 system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections");
100 system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections");
101 system("dpkg-reconfigure -fnoninteractive grub-efi-arm64");
105 update_wifi_firmware_if_necessary
107 return unless -f
$firmware_tarball;
109 if (-f
$firmware_manifest) {
110 system("sha256sum -c $firmware_manifest --quiet");
114 system("sha256sum $firmware_tarball > $firmware_manifest");
115 system("tar -C /lib/firmware/ -xf $firmware_tarball");
117 system('rmmod brcmfmac');
118 system('rmmod brcmutil');
120 system('modprobe brcmfmac');
122 system('rmmod brcmfmac');
124 system('modprobe brcmfmac');
127 my $root_block_device = undef;
128 my $root_fs_uuid = undef;
129 my $efi_block_device = undef;
130 my $efi_fs_uuid = undef;
132 unless (-f
'/etc/fstab') {
133 $root_block_device = find_root_device
();
134 system("resize2fs $root_block_device");
135 $root_fs_uuid = find_fs_uuid_of_device
($root_block_device);
136 $efi_block_device = find_efi_parition
($root_fs_uuid);
137 $efi_fs_uuid = find_fs_uuid_of_device
($efi_block_device);
138 generate_fstab
($root_fs_uuid, $efi_fs_uuid);
139 system('mount /boot/efi');
143 update_wifi_firmware_if_necessary
();