summaryrefslogtreecommitdiffstats
path: root/kernel/update_kernel
blob: c843fd595ef55670f1697f687c7fb01588851d2c (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash

ALL_KERNELS="all.kernels"
RPMS=/export/Mandrake/RPMS

ARCH=`uname -m | sed -e 's/i.86/i386/' -e 's/sparc.*/sparc/'`


# move stuff to this new "kernel" directory
if [ ! -d all.kernels ]; then
  if [ -d ../all.kernels ]; then
  mv ../all.kernels .
  rm -rf ../all.modules
  else
    # make sure "all.kernels" directory exists
    mkdir all.kernels
  fi
fi

function create_marfile() {
    marfile=$1
    shift
    $GIBASEDIR/mdk-stage1/mar/mar -c $marfile $*
}

function create_modules() {
    kernel_path=$1
    kern=$2
    echo "Updating modules in '`pwd`' for kernel '$kern'"
    find $kernel_path/lib/modules/ -name "*.o" -exec cp -f {} . \;
    /sbin/depmod -F $kernel_path/boot/System.map* -e *.o | perl -pe 's/\\\n//' \
	| perl -ne 's/\.o//g; s/[ \t]+/ /g; print if /: /' > modules.dep
    perl -pi -e 's/((plip|ppa|imm): parport)/$1 parport_pc/' modules.dep

    /sbin/modinfo -f '%{filename} %{description}\n' *.o | perl -lne 'print "$1\t$2" if /(.*?)\.o "(.*)"/' > modules.description
}

function create_modules_mar() {
    echo -n "stripping $kern: "
    $GIBASEDIR/kernel/strip_modules *.o 2>/dev/null
    echo "done"

    echo -n "packdrake $kern: "
    ls *.o | packdrake -b9s "modules.cz" 400000
    echo "done"
    mv modules.cz ../modules.cz-$kern
    for i in network network_gigabit_usb network_gigabit network_usb cdrom hd hdcdrom_usb pcmcia all; do
        eval "modules=\$${i}_modules_raw"
        modules_with_deps=`perl -I $GIBASEDIR/kernel $GIBASEDIR/kernel/dependencies.pl modules.dep $modules`
        if [ -n "$MOVE" ]; then modules_with_deps="$modules_with_deps loop.o gzloop.o isofs.o zlib_inflate.o supermount.o"; fi
	eval "create_marfile ${i}_modules.mar $modules_with_deps"
    done
    echo
}

[ -e $ALL_KERNELS/.main ] && main=$(cat $ALL_KERNELS/.main)

if [ "$ARCH" == "ia64" ] || [ "$ARCH" == "ppc" ]; then
	rpm=$(rpm -qp --qf '%{name}' $RPMS/kernel-[0-9]*.rpm | perl -pe 's/kernel-((\.?[0-9]+){3})\.(.*)/$1-${3}/')
else 
        #- allow specifying a kernel file on commandline (./update_kernel /RPMS/kernel-2.4.22.10mdk-1-1mdk.i586.rpm 2.4.22-10mdk)
        if [ -n "$1" ]; then
            file=$1
            rpm=$2
            MOVE=1
        else
            file=$RPMS/kernel-BOOT-*.rpm
            rpm=$(rpm -qp --qf '%{name}' $file | perl -pe 's/kernel-BOOT-((\.?[0-9]+){3})\.(.*)/$1-${3}BOOT/')
        fi
fi
if [ -n "$rpm" -a ! -e $ALL_KERNELS/$rpm ]; then
    [ -n "$main" ] && rm -rf $ALL_KERNELS/$main
    cd $ALL_KERNELS
    rm -rf $rpm ; mkdir $rpm
    cd $rpm
    if [ "$ARCH" == "ia64" ] || [ "$ARCH" == "ppc" ]; then
      rpm2cpio $RPMS/kernel-[0-9]*.rpm | cpio -id
    else
      rpm2cpio $file | cpio -id
    fi
    find -type f -name "*.o.gz" | xargs gunzip
    cd ../..

    for dir in /tftpboot /var/lib/tftpboot; do
	rm -f $dir/{vmlinuz,network.rdz}
    done
fi 

[ -n "$main" -a -e $ALL_KERNELS/$main ] || {
    cd $ALL_KERNELS
    main=$(echo 2.* | sed 's/.* //')
    echo "Choosing $main"
    echo $main > .main
    cd ..
}


if [ "$ARCH" == "i386" ]; then
    for i in $ALL_KERNELS/*/boot/vmlinuz*; do
	#disable any existing resolution!!!
	/usr/sbin/rdev -v $i 65535 #788 #785 
    done
fi


GIBASEDIR=`pwd`/..

rm -rf all.modules ; mkdir all.modules
for i in $ALL_KERNELS/*; do
	kern=`basename $i`
	(
	    mkdir all.modules/$kern
	    cd all.modules/$kern

	    create_modules ../../$i $kern
	) || exit 1
done
cp -f all.modules/$main/modules.description .

l=`perl modules.pl images` || exit 1
eval $l

for i in $ALL_KERNELS/*; do
	kern=`basename $i`
	(
	    cd all.modules/$kern

	    if [ "$kern" = "$main" ]; then
		create_modules_mar ../../$i $kern
	    else
		echo "$kern ($main)"
		create_modules_mar ../../$i $kern 2>/dev/null
	    fi
	) || exit 1
done


./check_mar.pl
n349'>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 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
package Xconfig::xfree; # $Id$

my ($Revision) = '$Revision$' =~ /(\d+)/;

use diagnostics;
use strict;

use common;
use Xconfig::parse;

#- mostly internal only
sub new {
    my ($class, $raw) = @_;
    @$raw && bless { raw => $raw }, $class;
}

sub _conf_files() {
    map { "$::prefix/etc/X11/$_" } 'xorg.conf', 'XF86Config-4', 'XF86Config';
}

################################################################################
# I/O ##########################################################################
################################################################################
sub read {
    my ($class) = @_;
    my $file = find { -f $_ } _conf_files();
    my $raw_X = $class->new(Xconfig::parse::read_XF86Config($file)) or return;
    $raw_X->{before} = $raw_X->prepare_write;

    if (my ($keyboard) = $raw_X->get_InputDevices('keyboard')) {
	$keyboard->{Driver}{val} = 'kbd';
    }
    if (my ($keyboard) = $raw_X->get_InputDevices('Keyboard')) {
	$keyboard->{Driver}{val} = 'kbd';
    }

    #- ugly hack to fix empty ModeLine lines, XFdrake seems to generate some, but where???
    #- at least this allows fixing the pb by re-running XFdrake 
    foreach ($raw_X->get_Sections('Monitor')) {
	my $l = $_->{ModeLine} or next;
	@$l = grep { $_->{val} } @$l;
    }

    foreach ($raw_X->get_Sections('Device')) {
	$_->{Driver} && $_->{Driver}{val} eq 'i810' and $_->{Driver}{val} = 'intel';
    }

    $raw_X;
}
sub write {
    my ($raw_X, $o_file) = @_;
    my $file = $o_file || first(_conf_files());
    if (!$o_file) {
	foreach (_conf_files()) {
	    if (-l $_) {
		unlink $_;
	    } else {
		renamef($_, "$_.old"); #- there will not be any XF86Config nor XF86Config-4 anymore, we want this!
	    }
	}
	#- keep it for old programs still using this name
	symlink basename($file), "$::prefix/etc/X11/XF86Config";
    }
    set_Revision($raw_X);
    Xconfig::parse::write_XF86Config($raw_X->{raw}, $file);
}
sub prepare_write {
    my ($raw_X) = @_;
    set_Revision($raw_X);
    join('', Xconfig::parse::prepare_write_XF86Config($raw_X->{raw}));
}
sub is_modified {
    my ($raw_X) = @_;
    $raw_X->{before} ne $raw_X->prepare_write;
}
sub is_only_resolution_modified {
    my ($raw_X) = @_;
    ($raw_X->{after_set_resolutions} || $raw_X->{before}) eq $raw_X->prepare_write;
}
sub empty_config {
    my ($class) = @_;
    $class->new(Xconfig::parse::read_XF86Config_from_string(our $default_header));
}

my $mark = '# File generated by XFdrake';
sub get_Revision {
    my ($raw_X) = @_;
    my $first = $raw_X->{raw}[0];
    $first->{pre_comment} =~ /^\Q$mark\E \(rev (\d+)\)/ && $1;
}
sub set_Revision {
    my ($raw_X) = @_;
    my $first = $raw_X->{raw}[0];
    my $first_comment = $first->{pre_comment};

    my $was_there = $first_comment =~ s/^\Q$mark\E.*\n//;
    $first->{pre_comment} = "$mark (rev $Revision)\n" . ($was_there ? '' : "\n") . $first_comment;
}

################################################################################
# keyboard #####################################################################
################################################################################
my @keyboard_fields = qw(XkbLayout XkbModel XkbDisable XkbOptions XkbCompat);
sub get_keyboard {
    my ($raw_X) = @_;
    my $raw_kbd = _raw_get_keyboard($raw_X) or die "no keyboard section";
    raw_export_section($raw_kbd, \@keyboard_fields);
}
sub set_keyboard {
    my ($raw_X, $kbd) = @_;
    my $raw_kbd = _raw_get_keyboard($raw_X) || _new_keyboard_section($raw_X);
    raw_import_section($raw_kbd, $kbd);
    _set_Option('keyboard', $raw_kbd, keys %$kbd);
}
sub _raw_get_keyboard {
    my ($raw_X) = @_;
    first($raw_X->get_Sections('InputDevice', sub { 
	my ($entry) = @_;
	my $Driver = val($entry->{Driver});
	$Driver eq 'kbd' || $Driver eq 'evdev' && val($entry->{XkbLayout});
    }));
}
sub _new_keyboard_section {
    my ($raw_X) = @_;
    my $raw_kbd = { Identifier => { val => 'Keyboard1' }, Driver => { val => 'kbd' } };
    $raw_X->add_Section('InputDevice', $raw_kbd);

    my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
    push @$layout, { val => '"Keyboard1" "CoreKeyboard"' };

    $raw_kbd;
}


################################################################################
# mouse ########################################################################
################################################################################
#- example mouse: { Protocol => 'IMPS/2', Device => '/dev/psaux', Emulate3Buttons => undef, Emulate3Timeout => 50, ZAxisMapping => [ '4 5', '6 7' ] }
#- example evdev: { vendor => '0x045e', product => '0x008c' }
my @mouse_fields = qw(Protocol Device ZAxisMapping Emulate3Buttons Emulate3Timeout vendor product); #-);
sub get_mice {
    my ($raw_X) = @_;
    my @raw_mice = $raw_X->get_Sections('InputDevice', \&_is_mouse);
    map { raw_export_section($_, \@mouse_fields) } @raw_mice;
}
sub set_mice {
    my ($raw_X, @mice) = @_;
    my @raw_mice = _new_mouse_sections($raw_X, map { $_->{Protocol} ? 'mouse' : 'evdev' } @mice);
    mapn { 
	my ($raw_mouse, $mouse) = @_;
	raw_import_section($raw_mouse, $mouse);
	_set_Option('mouse', $raw_mouse, keys %$mouse);
    } \@raw_mice, \@mice;
}
sub _is_mouse {
    my ($entry) = @_;
    my $Driver = val($entry->{Driver});
    $Driver eq 'mouse' || $Driver eq 'evdev' && !val($entry->{XkbLayout});
}
sub _new_mouse_sections {
    my ($raw_X, @Drivers) = @_;
    $raw_X->remove_Section('InputDevice', \&_is_mouse);
    
    my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
    @$layout = grep { $_->{val} !~ /^"Mouse/ } @$layout;
    
    @Drivers or return;
    
    my @l = map_index {
	my $h = { Identifier => { val => 'Mouse' . ($::i + 1) }, Driver => { val => $_ } };
	$raw_X->add_Section('InputDevice', $h);
    } @Drivers;
    
    push @$layout, { val => qq("Mouse1" "CorePointer") };
    push @$layout, { val => qq("Mouse$_" "SendCoreEvents") } foreach 2 .. @Drivers;
    
    @l;
}


################################################################################
# resolution ###################################################################
################################################################################
sub get_resolution {
    my ($raw_X, $o_Screen) = @_;
    first(get_resolutions($raw_X, $o_Screen));
}
sub get_resolutions {
    my ($raw_X, $o_Screen) = @_;
    my $Screen = $o_Screen || $raw_X->get_default_screen or return {};
    
    my $depth = val($Screen->{DefaultColorDepth} || $Screen->{DefaultDepth});
    my $Display = find { !$depth || val($_->{l}{Depth}) eq $depth } @{$Screen->{Display} || []} or return {};
    my $s = val($Display->{l}{Virtual} || $Display->{l}{Modes});
    my @l;
    while ($s =~ /(\d+)(x|\s+)(\d+)/g) {
	push @l, { X => $1, Y => $3, Depth => val($Display->{l}{Depth}) };
    }
    @l;
}
sub set_resolutions {
    my ($raw_X, $resolutions, $o_Screen) = @_;
    
    my $Depth = $resolutions->[0]{Depth} eq '32' ? 24 : $resolutions->[0]{Depth};
    my $only_resolution = $raw_X->is_only_resolution_modified;
    
    foreach my $Screen ($o_Screen ? $o_Screen : $raw_X->get_Sections('Screen')) {
	$Screen ||= $raw_X->get_default_screen or internal_error('no screen');

	#- if the existing config is using Virtual, keep Virtual, otherwise default to Modes
	my $Mode_name = (any { $_->{l}{Virtual} } @{$Screen->{Display} || []}) ? 'Virtual' : 'Modes';
	
	my @l = $Mode_name eq 'Modes' ? @$resolutions : first(@$resolutions);
	my @Modes = map { sprintf($Mode_name eq 'Modes' ? '"%dx%d"' : '%d %d', @$_{'X', 'Y'}) } @l;
	
	delete $Screen->{DefaultDepth};
	$only_resolution &&= $Screen->{DefaultColorDepth} && $Screen->{DefaultColorDepth}{val} eq $Depth;
	$Screen->{DefaultColorDepth} = { val => $Depth };
	$Screen->{Display} = [ map {
	    { l => { Depth => { val => $_ }, $Mode_name => { val => join(' ', @Modes) } } };
	} 8, 15, 16, 24 ];
    }
    add_gtf_ModeLines($raw_X, $resolutions);

    $raw_X->{after_set_resolutions} = $only_resolution ? $raw_X->prepare_write : '';
}


################################################################################
# device #######################################################################
################################################################################
my @device_fields = qw(VendorName BoardName Driver VideoRam Screen BusID); #-);
sub get_device {
    my ($raw_X) = @_;
    first(get_devices($raw_X));
}
sub get_devices {
    my ($raw_X) = @_;
    my @raw_devices = $raw_X->get_Sections('Device');
    map {
	my $raw_device = $_;
	my $device = raw_export_section($raw_device, [ 'Identifier', @device_fields ]);
	$device->{Options} = raw_export_section($raw_device, [ grep { (deref_array($raw_device->{$_}))[0]->{Option} } keys %$raw_device ]);
	$device;
    } @raw_devices;
}
sub set_devices {
    my ($raw_X, @devices) = @_;
    my @raw_devices = _new_device_sections($raw_X, int @devices);
    mapn { 
	my ($raw_device, $device) = @_;
	my %Options  = %{$device->{Options} || {}};
	raw_import_section($raw_device, $device, \@device_fields);
	raw_import_section($raw_device, \%Options);
	$_->{Option} = 1 foreach map { deref_array($raw_device->{$_}) } keys %Options;
	$raw_device->{''} = [ { post_comment => $device->{raw_LINES} } ] if $device->{raw_LINES};
    } \@raw_devices, \@devices;
}
sub _new_device_sections {
    my ($raw_X, $nb_new) = @_;
    $raw_X->remove_Section('Device');
    map { $raw_X->add_Section('Device', { Identifier => { val => "device$_" }, DPMS => { Option => 1 } }) } (1 .. $nb_new);
}
sub get_Driver {
    my ($raw_X) = @_;
    my $card = eval { $raw_X->get_device };
    $card && $card->{Driver};
}

################################################################################
# wacoms #######################################################################
################################################################################
sub set_wacoms {
    my ($raw_X, @wacoms) = @_;
    $raw_X->remove_InputDevices('wacom');
    
    my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
    @$layout = grep { $_->{val} !~ /^"(Stylus|Eraser|Cursor|Pad)/ } @$layout;
    
    @wacoms or return;
    
    my @Modes = ('Stylus', 'Eraser', 'Cursor', 'Pad');
   
    each_index {
	my $wacom = $_;
	foreach (@Modes) {
	    my $identifier = $_ . ($::i + 1);
	    my $h = { Identifier => { val => $identifier }, 
		      Driver => { val => 'wacom' },
		      Type => { val => lc $_, Option => 1 },
		      Device => { val => $wacom->{Device}, Option => 1 },
		      if_($wacom->{USB}, USB => { Option => 1 })
		    };
	    $raw_X->add_Section('InputDevice', $h);
	    push @$layout, { val => qq("$identifier" "AlwaysCore") };
	}
    } @wacoms;
}


################################################################################
# synaptics ####################################################################
################################################################################
sub set_synaptics {
    my ($raw_X, @synaptics) = @_;
    $raw_X->remove_InputDevices('synaptics');

    my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
    @$layout = grep { $_->{val} !~ /^"SynapticsMouse/ } @$layout;

    @synaptics or return;

    each_index {
	my $synaptics_mouse = $_;
        my $identifier = "SynapticsMouse" . ($::i + 1);
        my $pointer_type = $synaptics_mouse->{Primary} ? "CorePointer" : "AlwaysCore";
        my $h = {
            Identifier => { val => $identifier },
            Driver => { val => "synaptics" },
        };
        my %opts = (
            if_($synaptics_mouse->{ALPS},
                #- from /usr/share/doc/synaptics-0.14.0/README.alps
                #- and http://qa.mandrakesoft.com/show_bug.cgi?id=14512
                LeftEdge => 120,
                RightEdge => 830,
                TopEdge => 120,
                BottomEdge => 650,
                FingerLow => 14,
                FingerHigh => 15,
                MaxTapMove => 110,
                VertScrollDelta => 20,
                HorizScrollDelta => 20,
                MinSpeed => '0.8',
                MaxSpeed => '1.00',
                AccelFactor => '0.015',
                EdgeMotionMinSpeed => 200,
                EdgeMotionMaxSpeed => 200,
                UpDownScrolling => 1,
                CircularScrolling => 1,
                CircScrollTrigger => 2,
                UpDownScrolling => 0,
            ), #- use default driver options for non-ALPS
            SHMConfig => "on",
        );
        while (my ($k, $v) = each %opts) {
            $h->{$k} = { val => $v, Option => 1 };
        }
        $raw_X->add_Section('InputDevice', $h);
        push @$layout, { val => qq("$identifier" "$pointer_type") };
    } @synaptics;
}


################################################################################
# monitor ######################################################################