From 32291d88a3987cb9b05b65a1fc5747e69049a882 Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Sun, 9 Oct 2022 01:43:12 +0100 Subject: [PATCH] Add a Contents-firmware file to help with looking up firmware packages in d-i --- debian/changelog | 2 ++ tools/make_disc_trees.pl | 51 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 12a590f0..7f1ccb8f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ debian-cd (3.1.36) UNRELEASED; urgency=medium * Add non-free-firmware support + Add an extra config variable NONFREE_COMPONENTS to declare where to look for non-free packages. + * Add a Contents-firmware file to help with looking up firmware + packages in d-i. [ Cyril Brulebois ] * generate_firmware_patterns: Drop support for the temporary --test diff --git a/tools/make_disc_trees.pl b/tools/make_disc_trees.pl index 72065dac..3c4f5ca6 100755 --- a/tools/make_disc_trees.pl +++ b/tools/make_disc_trees.pl @@ -1188,6 +1188,8 @@ sub add_firmware_stuff { m/^Section: (\S+)/m and $section = $1; m/^Filename: (\S+)/mi and $file = $1; + my $base_file = basename($file); + if ($file =~ /\/main\//) { $dist = "main"; } elsif ($file =~ /\/contrib\//) { @@ -1206,7 +1208,7 @@ sub add_firmware_stuff { } msg_ap(0, "Symlink fw package $p into /firmware\n"); - symlink("../$file", "$dir/firmware/" . basename($file)); + symlink("../$file", "$dir/firmware/$base_file"); msg_ap(0, "Symlink ../$file $dir/firmware/.\n"); if (! -d "$dir/firmware") { mkdir "$dir/firmware" or die "mkdir $dir/firmware failed $!\n"; @@ -1228,6 +1230,28 @@ sub add_firmware_stuff { $blocks_added += get_file_blocks("$dir/firmware/dep11/$p.patterns"); } + # Find the current size of the firmware Contents file + my $contents_blocks_old = 0; + my $cont_file = "$dir/firmware/Contents-firmware"; + if (-f "$cont_file") { + $contents_blocks_old = get_file_blocks("$cont_file"); + } + # Add new contents stuff, and count it + open(OFILE, ">> $cont_file"); + open(DPKGC, "dpkg --contents $dir/firmware/$base_file |") + or die "Can't find contents of $dir/firmware/$base_file: $!"; + while (defined(my $line = )) { + chomp $line; + if ($line =~ m,^[-|l]\S+\s+\S+\s+\d+\s+\S+\s+\S+\s+./(\S+/firmware/\S+)$,) { + printf OFILE "%-55s %s\n", $1, $base_file; + } + } + close DPKGC; + close OFILE; + + my $contents_blocks_new = get_file_blocks($cont_file); + $blocks_added += $contents_blocks_new - $contents_blocks_old; + return $blocks_added; } @@ -1441,8 +1465,10 @@ sub remove_firmware_stuff { m/^Package: (\S+)/mi and $p = $1; m/^Filename: (\S+)/mi and $file = $1; + my $base_file = basename($file); + msg_ap(0, "Remove symlink for fw package $p in /firmware\n"); - unlink("$dir/firmware/" . basename($file)); + unlink("$dir/firmware/$base_file"); if (-f "$dir/firmware/dep11/$p.patterns") { $blocks_removed += get_file_blocks("$dir/firmware/dep11/$p.patterns"); @@ -1450,6 +1476,27 @@ sub remove_firmware_stuff { unlink("$dir/firmware/dep11/$p.patterns"); } + # Find the current size of the firmware Contents file, and grep + # out from the current data + my $contents_blocks_old = 0; + my $cont_file = "$dir/firmware/Contents-firmware"; + open(OFILE, "> $cont_file.1"); + if (-f $cont_file) { + $contents_blocks_old = get_file_blocks($cont_file); + open(IFILE, "< $cont_file"); + while (defined(my $line = )) { + chomp $line; + if ($line !~ /\b$base_file$/) { + print OFILE "$line\n"; + } + } + close IFILE; + } + close OFILE; + rename "$cont_file.1", "$cont_file"; + my $contents_blocks_new = get_file_blocks($cont_file); + $blocks_removed += $contents_blocks_new - $contents_blocks_old; + return $blocks_removed; }