3 my $firmware_tarball = '/boot/efi/vendorfw/firmware.tar';
4 my $firmware_manifest = '/lib/firmware/ASAHI_FIRMWARE_MANIFEST';
5 my $grubcfg = '/mnt/EFI/debian/grub.cfg';
10 open(MOUNT
, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!");
15 if (/^([\S]+)+ \/ /) {
20 die("Could not find root device");
24 find_fs_uuid_of_device
26 my $dev = shift || die;
27 my $blkid_output = `blkid ${dev}`;
29 if ($blkid_output =~ /UUID="([^"]+)"/) {
33 die("Could not find fs uuid of $dev");
39 my $uuid_in_grub_cfg = shift || die;
42 my $efi_parition = undef;
45 if (/^([\S]+):.*TYPE="vfat"/) {
46 push(@candidates, $1);
50 for my $dev (@candidates) {
51 system("mount -o ro $dev /mnt");
53 open(GRUBCFG
, '<', $grubcfg) || die ("Can't open $grubcfg: $!");
54 my @lines = <GRUBCFG
>;
56 if (/${uuid_in_grub_cfg}/) {
62 system("umount /mnt");
63 last if defined $efi_parition;
66 die ("No efi parition found") unless defined $efi_parition;
74 my $root_fs_uuid = shift || die;
75 my $efi_fs_uuid = shift || die;
77 open(FSTAB
, '>', '/etc/fstab') || die ("Can not open fstab");
79 UUID="$root_fs_uuid" / ext4 defaults 0 0
80 UUID="$efi_fs_uuid" /boot/efi vfat defaults 0 0
88 system('rm -rf /boot/efi/*');
89 system('apt-get install -y grub-efi-arm64-signed-');
90 system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections");
91 system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections");
92 system("dpkg-reconfigure -fnoninteractive grub-efi-arm64");
93 system("update-grub");
97 update_wifi_firmware_if_necessary
99 return unless -f
$firmware_tarball;
101 if (-f
$firmware_manifest) {
102 system("sha256sum -c $firmware_manifest --quiet");
106 system("sha256sum $firmware_tarball > $firmware_manifest");
107 system("tar -C /lib/firmware/ -xf $firmware_tarball");
109 system('rmmod brcmfmac');
110 system('rmmod brcmutil');
112 system('modprobe brcmfmac');
114 system('rmmod brcmfmac');
116 system('modprobe brcmfmac');
119 my $root_block_device = undef;
120 my $initial_root_fs_uuid = undef;
121 my $final_root_fs_uuid = undef;
122 my $efi_block_device = undef;
123 my $efi_fs_uuid = undef;
125 unless (-f
'/boot/grub/grub.cfg') {
126 $root_block_device = find_root_device
();
127 system("resize2fs $root_block_device");
128 $initial_root_fs_uuid = find_fs_uuid_of_device
($root_block_device);
129 $efi_block_device = find_efi_parition
($initial_root_fs_uuid);
130 system("mlabel -s -n :: -i $efi_block_device");
131 system("tune2fs -U random ${root_block_device}");
132 $efi_fs_uuid = find_fs_uuid_of_device
($efi_block_device);
133 $final_root_fs_uuid = find_fs_uuid_of_device
($root_block_device);
134 generate_fstab
($final_root_fs_uuid, $efi_fs_uuid);
135 system('mount /boot/efi');
139 update_wifi_firmware_if_necessary
();