summaryrefslogtreecommitdiffstats
path: root/images/update_kernel
blob: 0b2b82faed3f3f37513daf69d50027845c7b4352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl

# this script takes command kernel rpms (either installed rpms or rpm files)
# and create various files in all_kernels/:
#     all.kernels/VER/all_modules.tar  (used for all.rdz)
#     all.kernels/VER/modules.dep
#     all.kernels/VER/modules.alias
#     all.kernels/VER/vmlinuz

use lib '../kernel';
use MDK::Common;
use list_modules;

(my $karch = arch()) =~ s/^i.86$/i586/;
my $rpm = 'rpm --nosignature';


my $MOVE = $ARGV[0] eq '--move' && shift;

@ARGV or die "usage: ./update_kernel [--move] (<kernel rpm> ... | <installed kernel name> ...)\n";

eval { rm_rf('all.kernels') }; #- remove old things
mkdir 'all.kernels';

my @kernels = map {
    my $kern_ver = rpm2version($_);
    if (/\.rpm$/) {
	extract_kernel($_, $kern_ver);
    } else {
	extract_installed_rpm('', $kern_ver);
    }
    $kern_ver;
} @ARGV;

output('all.kernels/.list', map { "$_\n" } @kernels);

sub system_verbose { print join(' ', @_), "\n"; system(@_) }
sub sys { &system_verbose; $? and die }

sub rpm2version {
    my ($kernel_rpm) = @_;
    my $opt = -e $kernel_rpm ? '-qpl' : '-ql';
    `$rpm $opt $kernel_rpm` =~ m!/boot/vmlinuz-(.*)! && $1 or die "can't find vmlinuz in $kernel_rpm (is it installed?)\n";
}

sub extract_kernel {
    my ($kernel_rpm, $kern_ver) = @_;

    my $dir = "all.kernels/$kern_ver";

    warn "Extracting kernel $kern_ver\n";

    eval { rm_rf($dir) };
    mkdir_p("$dir/modules");
    sys("rpm2cpio $kernel_rpm | (cd $dir ; cpio -id)");

    extract_installed_rpm($dir, $kern_ver);

    eval { rm_rf("$dir$_") } foreach qw(/boot /lib /usr);
}

sub extract_installed_rpm {
    my ($installed_dir, $kern_ver) = @_;
    my $local_dir = "all.kernels/$kern_ver";
    mkdir_p("$local_dir/modules");

    sys('cp', "$installed_dir/boot/vmlinuz-$kern_ver", "$local_dir/vmlinuz");
    sys("cp $installed_dir/lib/modules/$kern_ver/modules.* $local_dir");

    open(my $F, "find $installed_dir/lib/modules/$kern_ver -name '*.ko.gz' |");
    my $file; while ($file = <$F>) {
	chomp($file);
	system('cp', $file, "$local_dir/modules/" . basename($file)) == 0
	  or warn "conflict for $file\n";
    }

    sys('perl', '../kernel/modules.pl', 'remove_unneeded_modules', $kern_ver);
    sys('perl', '../kernel/modules.pl', 'get_firmwares', $kern_ver);
    sys('perl', '../kernel/modules.pl', 'make_modules_per_image', $kern_ver);

    rm_rf("$local_dir/modules");
}