summaryrefslogtreecommitdiffstats
path: root/make_boot_img
blob: ca226f309a3d6af8270353262b16bf606fe07378 (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#!/usr/bin/perl

# This program will show on stdout yenta_socket stuff from pcitable
# which is not in probe.c

use MDK::Common;

my @probelines = cat_('probe.c');
my $status = 0;
foreach (@probelines) {
    if ($status == 0) {
	/^pci_id_t pci_id\[\] = {/ and $status = 1;
    } elsif ($status == 1) {
	/^\s*{\s*0x([\da-f]+),\s*0x([\da-f]+),\s*"([^"]*)",\s*"([^"]*)"\s*}/
	  and push @probes, { vendor => $1, device => $2, tag => $3, name => $4, vd => "$1$2" };
	/^};/ and last;
    }
}

require '/usr/bin/merge2pcitable.pl';
my $drivers = read_pcitable("/usr/share/ldetect-lst/pcitable");

foreach my $k (sort keys %$drivers) {
    $v = $drivers->{$k};
    $k =~ /^(....)(....)/;
    push @pcitable, { vendor => $1, device => $2, driver => $v->[0], name => $v->[1], vd => "$1$2" };
}

my @res;
print "Missing in `probe.c':\n";
foreach my $p (@pcitable) {
    next if $p->{driver} ne 'yenta_socket';
    member($p->{vd}, map { $_->{vd} } @probes) or
      push @res, "    { 0x$p->{vendor}, 0x$p->{device}, \"..\", \"$p->{name}\" },\n";
}
print sort @res;
@res = ();
print "\n";

print "Missing in pcitable:\n";
foreach my $p (@probes) {
    my @r = grep { $_->{vd} eq $p->{vd} } @pcitable;
    @r > 1 and die "duplicate entry in pcitable <$p->{vd}>\n";
    if (@r && $r[0]->{driver} ne 'yenta_socket') {
	push @res, "0x$p->{vendor}\t0x$p->{device}\t\"yenta_socket\"\t\"$r[0]->{name}\"\n";
	$r[0]->{driver} ne 'unknown' and print STDERR "WARNING, driver for <$p->{vd}> was <$r[0]->{driver}>\n";
    }
}
print sort @res;
@res = ();
print "\n";
n132' href='#n132'>132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
#!/usr/bin/perl

@ARGV >= 2 or die "usage: $0 <image> all|other|cdrom|hd|network|usbnet|blank|pcmcia|live|tftp|tftprd\n";

use Config;
Config->import;
my ($arch) = $Config{archname} =~ /(.*)-/;
my $corporate = $ENV{CORPORATE} && " corporate"; #- use this for building a corporate version.

($img, $type) = @ARGV;

$instdir = "mdk-stage1";
$mnt = "/tmp/drakx_mnt";
$mke2fs = "/sbin/mke2fs -q -m 0 -F -s 1";

if ($>) {
    $sudo = "sudo";
    $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";
}

sub __ { print @_, "\n"; system(@_); }
sub _ { __ @_; $? and die; }

_ "$sudo mkdir $mnt" unless -e $mnt;
_ "$sudo mkdir ${mnt}2" unless -e "${mnt}2";

$install = $ {{
    all => "stage1-full",
    other => "stage1-full",
    blank => "stage1-full",
    live => "stage1-full",
    tftp => "stage1-full",
    tftprd => "stage1-full",
    pcmcia => "stage1-full",
    network => "stage1-network",
    usbnet => "stage1-usbnet",
    cdrom => "stage1-cdrom",
    hd => "stage1-disk",
    live64 => "stage1-full",
    tftp64 => "stage1-full",
    tftprd64 => "stage1-full",
    pcmcia64 => "stage1-full",
    network64 => "stage1-network",
    cdrom64 => "stage1-cdrom",
    hd64 => "stage1-disk",
}}{$type} or die;

mkdir "images";
chomp($main = `cat all.kernels/.main`);

if ($img =~ /blank|other/) {
    @kernels = $main;
} else {
    @kernels = map { m|all.kernels/(.*)| } glob('all.kernels/*');
}

foreach (@kernels) {
    if ($img =~ /rdz$/) {
	initrd($mnt, "$img-$_");
    } else {
	$::{"boot_img_$arch"}->($mnt, "$img-$_", glob("all.kernels/$_/boot/vmlinu*"));
    }
}
rename("$img-$main", "$img");

sub install_stripped { _ "strip $_[0]"; _ "$sudo install $_[0] $_[1]" }

sub initrd {
    my ($mnt, $img) = @_;
    my ($ltype, $I) = $type =~ /(.*?)(64)/; $ltype ||= $type;
    my $tmp = "$ENV{HOME}/tmp/initrd";
    my $tar = "$instdir/stage1-data/stage1.tar.bz2";

    __ "$sudo umount $tmp $mnt 2>/dev/null";
    _ "dd if=/dev/zero of=$tmp bs=1k count=" . ($arch =~ /ia64/ ? ($type eq "all" ? 12000 : 12000) : ($type eq "all" ? 4000 : 2000));
    _ "$mke2fs $tmp";
    _ "$sudo mount -t ext2 $tmp $mnt -o loop";

    _ "$sudo tar xjC $mnt -f $tar";
    install_stripped("$instdir/init", "$mnt/sbin");
    install_stripped("$instdir/$install", "$mnt/sbin/stage1");

    if ($type eq "network" || $type eq "usbnet" || $type eq "all" || $type eq "other" || $type eq "blank") {
	install_stripped("$instdir/ppp/pppd-bin", "$mnt/sbin/pppd");
	install_stripped("$instdir/rp-pppoe/pppoe-bin", "$mnt/sbin/pppoe");
	_ "$sudo cp -a /dev/ppp $mnt/dev";
	_ "$sudo cp -a /dev/ptyp0 $mnt/dev";
	_ "$sudo cp -a /dev/ttyp0 $mnt/dev";
    }

    my $ftype = $type =~ /^(all)$/ ? "pcmcia" : $type;
    if ($ftype eq "pcmcia" && $arch !~ /ppc/) {
	 _ "$sudo cp -a /etc/pcmcia $mnt/etc";
	 _ "$sudo patch -p0 -d $mnt/etc < $instdir/pcmcia_config.patch";
    }
    my ($ext) = $img =~ /rdz-(.*)/ or die "bad initrd name ($img)";
    $modz = "all.modules$I/$ext";
    _ "$sudo cp -f $modz/${ltype}_modules.mar $mnt/modules/modules$I.mar" if $type !~ /blank/;
    _ "$sudo cp -f $modz/modules.dep $mnt/modules/";
    _ "$sudo umount $mnt";


# Workaround for vfat-loop bug (quite touchy)
    _ "gzip -9f $tmp";
    _ "cp -f $tmp.gz $img";
    _ "rm -f $tmp.gz";
#    _ "gzip -9 -c $tmp > $img";
#    _ "rm -f $tmp";
}

sub boot_img_i386 {
    my ($mnt, $img, $kernel) = @_;

    __ "$sudo umount $mnt 2>/dev/null";
    my $automatic = "";

    if ($type eq "hd") {
	_ "bunzip2 -c $instdir/init-data/msgboot.img.bz2 > $img";
    } elsif ($type eq "all") {
	_ "bunzip2 -c $instdir/init-data/msgboot-graphicallogo-2880.img.bz2 > $img";
    } else {
	_ "bunzip2 -c $instdir/init-data/msgboot-graphicallogo.img.bz2 > $img";
    }

    $automatic = "automatic=method:cdrom" if ($type eq "cdrom");
    $automatic = "automatic=method:disk" if ($type eq "hd");

    _ "$sudo mount -t vfat -o umask=0 $img $mnt -o loop";
    _ "cat $kernel > $mnt/vmlinuz" if $type !~ /blank/;

    my $rdz = $img; $rdz =~ s/\.img/.rdz/;
    initrd("${mnt}2", $rdz) if !-e $rdz;
    eval { _ "cp -f $rdz $mnt/$type.rdz" };
    if ($@) {
	unlink "$mnt/$type.rdz";
	my $avail = (split ' ', `df $mnt`)[-3];
	my $s = int((-s $rdz) / 1024);
	die sprintf("not enough room for $rdz: need %dKB (available %dKB < needed %dKB)\n", $s - $avail, $avail, $s);
    }

#    my $ftype = $type =~ /^(other|all)$/ ? "cdrom" : $type;
    my $timeout = 72;
    output("$mnt/syslinux.cfg",
"default linux
prompt 1
timeout $timeout
display boot.msg
F1 help.msg
F2 boot.msg
label linux
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 vga=788
label vgalo
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 vga=785
label vgahi
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 vga=791
label vga16
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 vga16
label text
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 text
label patch
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 patch vga=788
label expert
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 expert vga=788
label rescue
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 rescue rw
label lnx4win
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic root=/dev/ram3 lnx4win vga=788
label preinst
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz automatic=method:cdrom root=/dev/ram3 rescue oem rw
label oem
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz automatic=method:cdrom root=/dev/ram3 rescue oem rw
label auto
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz $automatic auto_install=Mandrake/base/auto_inst.cfg.pl
label all
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz pcmcia root=/dev/ram3 vga=788
label ackbar
  kernel vmlinuz
  append ramdisk_size=32000 initrd=$type.rdz automatic=method:nfs,network:static,ip:192.168.1.205,dns:192.168.1.11,domain:mandrakesoft.com,server:ackbar,directory:/export vga=788
");
    _ "sync";
    _ "df $mnt";
}

sub boot_img_alpha {
    my ($mnt, $img) = @_;

    __ "$sudo umount $mnt 2>/dev/null";
    _ "dd if=/dev/zero of=$img bs=1k count=1440";
    _ "$mke2fs $img";
    _ "/sbin/e2writeboot $img /boot/bootlx";
    _ "$sudo mount -t ext2 $img $mnt -o loop";
    _ "cp -f vmlinux.gz $mnt" if $type !~ /blank/;
    -f "$type.rdz" ? _ "cp -f $type.rdz $mnt" : initrd("${mnt}2", "$mnt/$type.rdz");

    mkdir "$mnt/etc", 0777;
    output("$mnt/etc/aboot.conf", 
"0:vmlinux.gz initrd=$type.rdz rw ramdisk_size=32000 root=/dev/ram3 $type
1:vmlinux.gz initrd=$type.rdz rw ramdisk_size=32000 root=/dev/ram3 text $type
");
    _ "sync";
    _ "df $mnt";
}

sub boot_img_ia64 {
    my ($mnt, $img, $kernel) = @_;

    __ "$sudo umount $mnt 2>/dev/null";
    _ "dd if=/dev/zero of=$img bs=1k count=12000";
    _ "mkdosfs $img";
    _ "$sudo mount -t vfat $img $mnt -o loop,umask=000";
    _ "$sudo cp -f $kernel $mnt/vmlinux";
    _ "cp -f images/$type.rdz $mnt/$type.rdz";
    _ "$sudo cp -f tools/ia64/elilo.efi $mnt";
	output("$mnt/elilo.conf", "
prompt
timeout=50

image=vmlinux
        label=linux
        root=/dev/ram3
        initrd=$type.rdz
        append=\"ramdisk_size=120000\"
        read-only
");
    _ "sync";
    _ "df $mnt";

}

sub boot_img_sparc {
    my ($mnt, $img) = @_;
    if ($type =~ /^live(.*)/) {
	#- hack to produce directly into /export the needed file for cdrom boot.
	my $dir = "/export";
	my $boot = "boot"; #- non-absolute pathname only!

	_ "mkdir -p $dir/$boot";
	_ "cp -f /boot/cd.b /boot/second.b $dir/$boot";
	_ "cp -f vmlinux$1 $dir/$boot/vmlinux$1";
	-f "live$1.rdz" ? _ "cp -f live$1.rdz $dir/$boot" : initrd("${mnt}2", "$dir/$boot/live$1.rdz");

	output("$dir/$boot/silo.conf", "
partition=1
default=linux
timeout=100
read-write
message=/$boot/boot.msg
image=\"cat /$boot/boot.msg\"
  label=1
  single-key
image=\"cat /$boot/general.msg\"
  label=2
  single-key
image=\"cat /$boot/expert.msg\"
  label=3
  single-key
image=\"cat /$boot/rescue.msg\"
  label=4
  single-key
image=\"cat /$boot/kickit.msg\"
  label=5
  single-key
image=\"cat /$boot/param.msg\"
  label=6
  single-key
image[sun4c,sun4d,sun4m]=/$boot/vmlinux
  label=linux
  alias=install
  initrd=/$boot/live.rdz
  append=\"ramdisk_size=32000$corporate root=/dev/ram3\"
image[sun4c,sun4d,sun4m]=/$boot/vmlinux
  label=text
  initrd=/$boot/live.rdz
  append=\"ramdisk_size=32000 text$corporate root=/dev/ram3\"
image[sun4c,sun4d,sun4m]=/$boot/vmlinux
  label=expert
  initrd=/$boot/live.rdz
  append=\"ramdisk_size=32000 expert$corporate root=/dev/ram3\"
image[sun4c,sun4d,sun4m]=/$boot/vmlinux
  label=ks
  initrd=/$boot/live.rdz
  append=\"ramdisk_size=32000 ks$corporate root=/dev/ram3\"
image[sun4c,sun4d,sun4m]=/$boot/vmlinux
  label=rescue
  initrd=/$boot/live.rdz
  append=\"ramdisk_size=32000 rescue rw root=/dev/ram3$corporate\"
image[sun4u]=/$boot/vmlinux64
  label=linux
  alias=install
  initrd=/$boot/live64.rdz
  append=\"ramdisk_size=32000$corporate root=/dev/ram3\"
image[sun4u]=/$boot/vmlinux64
  label=text
  initrd=/$boot/live64.rdz
  append=\"ramdisk_size=32000 text$corporate root=/dev/ram3\"
image[sun4u]=/$boot/vmlinux64
  label=expert
  initrd=/$boot/live64.rdz
  append=\"ramdisk_size=32000 expert$corporate root=/dev/ram3\"
image[sun4u]=/$boot/vmlinux64
  label=ks
  initrd=/$boot/live64.rdz
  append=\"ramdisk_size=32000 ks$corporate root=/dev/ram3\"
image[sun4u]=/$boot/vmlinux64
  label=rescue
  initrd=/$boot/live64.rdz
  append=\"ramdisk_size=32000 rescue rw root=/dev/ram3$corporate\"
");

	output("$dir/$boot/README", "
To Build a Bootable CD-ROM, try:
  mkisofs -R -o t.iso -s /$boot/silo.conf /export
");
    } elsif ($type =~ /^tftprd(.*)/) {
	my $dir = "/export";
	my $boot = "images";
	my $setarch = $1 ? "sparc64" : "sparc32";

	_ "mkdir -p $dir/$boot";
	-f "$type.rdz" or initrd("${mnt}2", "$type.rdz");
	_ "cp -f vmlinux$1.aout $dir/$boot/$type.img";
	_ "$setarch kernel$1/src/arch/sparc$1/boot/piggyback $dir/$boot/$type.img kernel$1/boot/System.map $type.rdz";
    } elsif ($type =~ /^tftp(.*)/) {
	my $dir = "/export";
	my $boot = "images";

	_ "mkdir -p $dir/$boot";
	_ "cp -f vmlinux$1.aout $dir/$boot/$type.img";
    } else {
	my $dir = "floppy";
	my ($ltype, $I) = $type =~ /(.*?)(64)/; $ltype ||= $type;

	__ "$sudo umount $mnt 2>/dev/null";
	_ "rm -rf $dir";
	_ "mkdir -p $dir";
	_ "cp -f /boot/fd.b /boot/second.b $dir";
	_ "cp -f vmlinuz$I $dir/vmlinux$I.gz" if $type !~ /blank/;
	-f "$type.rdz" ? _ "cp -f $type.rdz $dir" : initrd("${mnt}2", "$dir/$type.rdz");

	output("$dir/boot.msg", "
Welcome to Mandrake Linux 7.1

Press <Enter> to install or upgrade a system 7mMandrake Linux7m
");

	output("$dir/silo.conf", "
partition=1
default=linux
timeout=100
read-write
message=/boot.msg
image=/vmlinux$I.gz
  label=linux
  initrd=/$type.rdz
  append=\"ramdisk_size=32000 $ltype$corporate root=/dev/ram3\"
");
	_ "genromfs -d $dir -f /dev/ram -A 2048,/.. -a 512 -V \'DrakX boot disk\'";
	_ "$sudo mount -t romfs /dev/ram $mnt";
	_ "silo -r $mnt -F -i /fd.b -b /second.b -C /silo.conf";
	_ "$sudo umount $mnt";
	_ "dd if=/dev/ram of=$type.img bs=1440k count=1";
	_ "sync";
	_ "$sudo mount -t romfs /dev/ram $mnt";
	_ "df $mnt";
    }
}

sub boot_img_ppc {
    my ($mnt, $img, $kern, $modz) = @_;
    my $dir = "/export";
    my $boot = "boot"; #- non-absolute pathname only!
    my ($extension) = $modz =~ /.*\/([^\/]+)/;
    _ "mkdir -p $dir/$boot";
    _ "cp -f $kern $dir/$boot/vmlinux";
    _ "cp -f images/all.rdz$extension $dir/boot/all.gz";
    _ "cp -f tools/ppc/yaboot $dir/boot/yaboot";
	
	output("$dir/$boot/yaboot.conf", "
init-message = \"\\nWelcome to Mandrake Linux PPC!\\nHit <TAB> for boot options.\\n\\n\"
timeout = 150
default = install-novideo

image = cd:,\\\\\\\\vmlinux
    label = install-novideo
    root = /dev/ram3
    initrd = cd:,\\\\\\\\all.gz
    initrd-size = 32000
    append = \" video=ofonly\"
    
image = cd:,\\\\\\\\vmlinux
    label = install-atyfb
    root = /dev/ram3
    initrd = cd:,\\\\\\\\all.gz
    initrd-size = 32000
    append = \" video=atyfb:vmode:17\"
    
image = cd:,\\\\\\\\vmlinux
    label = install-aty128fb
    root = /dev/ram3
    initrd = cd:,\\\\\\\\all.gz
    initrd-size = 32000
    append = \" video=aty128fb:vmode:17\"

image = cd:,\\\\\\\\vmlinux
    label = install-text
    root = /dev/ram3
    initrd = cd:,\\\\\\\\all.gz
    initrd-size = 32000
    append = \" text video=ofonly\"

image = enet:0,vmlinux
    label = install-net
    root = /dev/ram3
    initrd = enet:0,all.gz
    initrd-size = 32000
    append = \" video=ofonly\"

image = enet:0,vmlinux
    label = install-net-text
    root = /dev/ram3
    initrd = enet:0,all.gz
    initrd-size = 32000
    append = \" text video=ofonly\"

image = cd:,\\\\\\\\vmlinux
    label = rescue
    root = /dev/ram3
    initrd = cd:,\\\\\\\\all.gz
    initrd-size = 32000
    append = \" rescue video=ofonly\"    

image = enet:0,vmlinux
    label = rescue-net
    root = /dev/ram3
    initrd = enet:0,all.gz
    initrd-size = 32000
    append = \" rescue video=ofonly\"    
");
	#- seem to need 2 yaboot.conf, one in the root, and one in boot
	_ "cp -f $dir/boot/yaboot.conf $dir/yaboot.conf";		

	output("$dir/$boot/README", "
To Build a Bootable CD-ROM, do:
cd /tools/ppc
./mkINSTALLCD /export ppc-cd.img
");

}

sub output {
    my $f = shift;
    local *F;
    open F, "> $f" or die "error writing to $f";
    print F join '', @_;
}