]>
Commit | Line | Data |
---|---|---|
29f98055 LO |
1 | #!/bin/sh |
2 | ||
3 | srcdir="$1" | |
4 | objects="$2" | |
5 | log="$3" | |
6 | shift 3 | |
7 | ||
8 | dkms_dir="$1" | |
9 | abi_flavour="$2" | |
10 | sign="$3" | |
11 | pkgname="$4" | |
12 | pkgdir="$5" | |
13 | dbgpkgdir="$6" | |
14 | package="$7" | |
15 | shift 7 | |
16 | ||
17 | build="$( dirname "$objects" )/build" | |
18 | ||
19 | # Copy over the objects ready for reconstruction. The objects copy contains | |
20 | # the *.o files and the *.o-ur* retpoline files to allow the kernel to track | |
21 | # any retpoline sequences therein. For our purposes we only want the *.o | |
22 | # files, elide the rest. | |
23 | mkdir -p "$pkgdir/bits/scripts" | |
24 | ( | |
25 | gcc_variant1=$(gcc --version | head -1 | sed -e 's/^gcc/GCC:/') | |
26 | gcc_variant2=$(gcc --version | head -1 | sed -e 's/^\(gcc\) \((.*)\) \(.*\)$/\1 version \3 \2/') | |
27 | cd "$objects" || exit 1 | |
28 | find -name \*.o | \ | |
29 | while read file | |
30 | do | |
31 | cp --parents "$file" "$pkgdir/bits" | |
32 | "$srcdir/debian/scripts/fix-filenames" "$pkgdir/bits/$file" "$gcc_variant1" | |
33 | "$srcdir/debian/scripts/fix-filenames" "$pkgdir/bits/$file" "$gcc_variant2" | |
34 | done | |
35 | ) | |
36 | ||
37 | # Install the support files we need. | |
2392988e AR |
38 | echo "II: copying support files ..." |
39 | for lds_src in \ | |
40 | "$dkms_dir/headers/linux-headers-$abi_flavour/scripts/module.lds" \ | |
41 | "/usr/src/linux-headers-$abi_flavour/scripts/module.lds" \ | |
42 | "$dkms_dir/headers/linux-headers-$abi_flavour/scripts/module-common.lds" \ | |
43 | "/usr/src/linux-headers-$abi_flavour/scripts/module-common.lds" | |
44 | do | |
45 | [ ! -f "$lds_src" ] && continue | |
46 | echo "II: copying support files ... found $lds_src" | |
47 | cp "$lds_src" "$pkgdir/bits/scripts" | |
48 | break | |
49 | done | |
50 | ||
51 | # Build helper scripts. | |
52 | cat - <<'EOL' >"$pkgdir/bits/BUILD" | |
53 | [ "$1" = "unsigned" ] && signed_only=: | |
54 | EOL | |
55 | grep /usr/bin/ld.bfd "$log" | grep -v scripts/genksyms/genksyms | sed -e "s@$build/@@g" >>"$pkgdir/bits/BUILD" | |
56 | sed -e 's/.*-o *\([^ ]*\) .*/rm -f \1/g' <"$pkgdir/bits/BUILD" >"$pkgdir/bits/CLEAN" | |
29f98055 LO |
57 | |
58 | # As the builds contain the absolute filenames as used. Use RECONSTRUCT to | |
59 | # rebuild the .ko's, sign them, pull off the signatures and then finally clean | |
60 | # up again. | |
61 | ( | |
62 | cd "$pkgdir/bits" || exit 1 | |
2392988e AR |
63 | |
64 | # Add .ko handling to the CLEAN/BUILD dance. | |
65 | for ko in "$pkgdir"/*.ko | |
29f98055 | 66 | do |
2392988e AR |
67 | ko=$(basename "$ko") |
68 | echo "\$signed_only cat '$ko' '$ko.sig' >'../$ko'" >>"$pkgdir/bits/BUILD" | |
69 | echo "\$signed_only rm -f '$ko'" >>"$pkgdir/bits/BUILD" | |
29f98055 LO |
70 | echo "rm -f '../$ko'" >>"$pkgdir/bits/CLEAN" |
71 | done | |
72 | ||
2392988e AR |
73 | # Clear out anything we are not going to distribute and build unsigned .kos. |
74 | sh ./CLEAN | |
75 | sh ./BUILD unsigned | |
76 | ||
29f98055 LO |
77 | if [ "$sign" = "--custom" ]; then |
78 | # We are building for and archive custom signing upload. Keep everything. | |
79 | : | |
80 | elif [ "$sign" = "--lrm" ]; then | |
2392988e AR |
81 | # We are in the LRM build; grab sha256 checksums and clean up. |
82 | sha256sum -b *.ko >"SHA256SUMS" | |
29f98055 | 83 | sh ./CLEAN |
2392988e | 84 | |
29f98055 LO |
85 | else |
86 | # We are in the main kernel, put the .kos together as we will | |
87 | # on the users machine, sign them, and keep just the signature. | |
88 | : >"SHA256SUMS" | |
89 | for ko in *.ko | |
90 | do | |
91 | echo "detached-signature $ko" | |
92 | $sign "$ko" "$ko.signed" | |
93 | length=$( stat --format %s "$ko" ) | |
94 | dd if="$ko.signed" of="$ko.sig" bs=1 skip="$length" 2>/dev/null | |
95 | ||
96 | rm -f "$ko.signed" | |
97 | # Keep a checksum of the pre-signed object so we can check it is | |
98 | # built correctly in LRM. | |
99 | sha256sum -b "$ko" >>"SHA256SUMS" | |
100 | done | |
101 | ||
102 | # Clean out anything which not a signature. | |
103 | mv "$pkgdir/bits/"*.sig "$pkgdir" | |
104 | mv "$pkgdir/bits/SHA256SUMS" "$pkgdir" | |
105 | find "$pkgdir" -name \*.sig -prune -o -name SHA256SUMS -prune -o -type f -print | xargs rm -f | |
106 | find "$pkgdir" -depth -type d -print | xargs rmdir --ignore-fail-on-non-empty | |
107 | fi | |
108 | ) || exit "$?" |