xref: /freebsd/sys/contrib/device-tree/scripts/rewrite-index.pl (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1*c66ec88fSEmmanuel Vadot#!/usr/bin/perl
2*c66ec88fSEmmanuel Vadotuse strict;
3*c66ec88fSEmmanuel Vadotuse warnings;
4*c66ec88fSEmmanuel Vadotuse IPC::Open2;
5*c66ec88fSEmmanuel Vadotmy $pid;
6*c66ec88fSEmmanuel Vadot
7*c66ec88fSEmmanuel Vadotopen(my $lsfiles, "-|", "git ls-files -s") or die "fork lsfiles: $!";
8*c66ec88fSEmmanuel Vadot
9*c66ec88fSEmmanuel Vadotwhile (<$lsfiles>) {
10*c66ec88fSEmmanuel Vadot    if ($_ =~ m/^120000 ([0-9a-f]{40}) (.*)\t(.*)/) {
11*c66ec88fSEmmanuel Vadot	my ($obj, $stage, $path) = ($1,$2,$3);
12*c66ec88fSEmmanuel Vadot	if (!defined $pid) {
13*c66ec88fSEmmanuel Vadot	    $pid = open2(*Rderef, *Wderef, "git cat-file --batch-check='deref-ok %(objectname)' --follow-symlinks")
14*c66ec88fSEmmanuel Vadot		or die "open git cat-file: $!";
15*c66ec88fSEmmanuel Vadot	}
16*c66ec88fSEmmanuel Vadot	print Wderef "$ENV{GIT_COMMIT}:$path\n" or die "write Wderef: $!";
17*c66ec88fSEmmanuel Vadot	my $deref = <Rderef>;
18*c66ec88fSEmmanuel Vadot	if ($deref =~ m/^deref-ok ([0-9a-f]{40})$/) {
19*c66ec88fSEmmanuel Vadot	    $_ = "100644 $1 $stage\t$path\n"
20*c66ec88fSEmmanuel Vadot	} elsif ($deref =~ /^dangling /) {
21*c66ec88fSEmmanuel Vadot	    # Skip next line
22*c66ec88fSEmmanuel Vadot	    my $dummy = <Rderef>;
23*c66ec88fSEmmanuel Vadot	} else {
24*c66ec88fSEmmanuel Vadot	    die "Failed to parse symlink $ENV{GIT_COMMIT}:$path $deref";
25*c66ec88fSEmmanuel Vadot	}
26*c66ec88fSEmmanuel Vadot    }
27*c66ec88fSEmmanuel Vadot
28*c66ec88fSEmmanuel Vadot    my $m = 0;
29*c66ec88fSEmmanuel Vadot
30*c66ec88fSEmmanuel Vadot    # Keep the copyright. Also ensures we never have a completely empty commit.
31*c66ec88fSEmmanuel Vadot    $m++ if m/\tCOPYING$/;
32*c66ec88fSEmmanuel Vadot
33*c66ec88fSEmmanuel Vadot    # A few architectures have dts files at non standard paths. Massage those into
34*c66ec88fSEmmanuel Vadot    # a standard arch/ARCH/boot/dts first.
35*c66ec88fSEmmanuel Vadot
36*c66ec88fSEmmanuel Vadot    # symlink: arch/microblaze/boot/dts/system.dts -> ../../platform/generic/system.dts
37*c66ec88fSEmmanuel Vadot    next if m,\tarch/microblaze/boot/dts/system.dts$,;
38*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/microblaze/platform/generic/(system.dts)$,\tarch/microblaze/boot/dts/$1,;
39*c66ec88fSEmmanuel Vadot
40*c66ec88fSEmmanuel Vadot    # arch/mips/lantiq/dts/easy50712.dts
41*c66ec88fSEmmanuel Vadot    # arch/mips/lantiq/dts/danube.dtsi
42*c66ec88fSEmmanuel Vadot    # arch/mips/netlogic/dts/xlp_evp.dts
43*c66ec88fSEmmanuel Vadot    # arch/mips/ralink/dts/rt3050.dtsi
44*c66ec88fSEmmanuel Vadot    # arch/mips/ralink/dts/rt3052_eval.dts
45*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/mips/([^/]*)/dts/(.*\.dts.?)$,\tarch/mips/boot/dts/$2,;
46*c66ec88fSEmmanuel Vadot
47*c66ec88fSEmmanuel Vadot    # arch/mips/cavium-octeon/octeon_68xx.dts
48*c66ec88fSEmmanuel Vadot    # arch/mips/cavium-octeon/octeon_3xxx.dts
49*c66ec88fSEmmanuel Vadot    # arch/mips/mti-sead3/sead3.dts
50*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/mips/([^/]*)/([^/]*\.dts.?)$,\tarch/mips/boot/dts/$2,;
51*c66ec88fSEmmanuel Vadot
52*c66ec88fSEmmanuel Vadot    # arch/x86/platform/ce4100/falconfalls.dts
53*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/x86/platform/ce4100/falconfalls.dts,\tarch/x86/boot/dts/falconfalls.dts,;
54*c66ec88fSEmmanuel Vadot
55*c66ec88fSEmmanuel Vadot    # test cases
56*c66ec88fSEmmanuel Vadot    $m++ if s,\tdrivers/of/testcase-data/,\ttestcase-data/,;
57*c66ec88fSEmmanuel Vadot
58*c66ec88fSEmmanuel Vadot    # Now rewrite generic DTS paths
59*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/([^/]*)/boot/dts/(.*\.dts.?)$,\tsrc/$1/$2,;
60*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/([^/]*)/boot/dts/(.*\.h)$,\tsrc/$1/$2,;
61*c66ec88fSEmmanuel Vadot
62*c66ec88fSEmmanuel Vadot    # Also rewrite the DTS include paths for dtc+cpp support
63*c66ec88fSEmmanuel Vadot    $m++ if s,\tarch/([^/]*)/include/dts/,\tsrc/$1/include/,;
64*c66ec88fSEmmanuel Vadot    $m++ if s,\tinclude/dt-bindings/,\tinclude/dt-bindings/,;
65*c66ec88fSEmmanuel Vadot
66*c66ec88fSEmmanuel Vadot    # Rewrite the bindings subdirectory
67*c66ec88fSEmmanuel Vadot    $m++ if s,\tDocumentation/devicetree/bindings/,\tBindings/,;
68*c66ec88fSEmmanuel Vadot
69*c66ec88fSEmmanuel Vadot    print if $m > 0;
70*c66ec88fSEmmanuel Vadot}
71*c66ec88fSEmmanuel Vadotkill $pid if $pid;
72*c66ec88fSEmmanuel Vadotexit 0;
73