sys-kernel/mips-sources: Update to more recent versions & EAPI6
[gentoo.git] / sys-kernel / mips-sources / mips-sources-4.4.152.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # EAPI Version
5 EAPI="6"
6
7 #//------------------------------------------------------------------------------
8
9 # Version Data
10 GITDATE="20160123"                      # Date of diff between kernel.org and lmo GIT
11 GENPATCHREV="2"                         # Tarball revision for patches
12
13 # Directories
14 S="${WORKDIR}/linux-${OKV}-${GITDATE}"
15 MIPS_PATCHES="${WORKDIR}/mips-patches"
16
17 # Kernel-2 Vars
18 K_SECURITY_UNSUPPORTED="yes"
19 K_NOUSENAME="yes"
20 K_NOSETEXTRAVERSION="yes"
21 K_NOUSEPR="yes"
22 K_BASE_VER="4.3"
23 K_FROM_GIT="yes"
24 ETYPE="sources"
25
26 # Inherit Eclasses
27 inherit kernel-2 eutils eapi7-ver
28 detect_version
29
30 # EPATCH Vars
31 # XXX: Required to properly apply Impact/Odyssey driver patches.
32 EPATCH_OPTS="-F3"
33
34 # Version Data
35 F_KV="${PVR}"
36 BASE_KV="$(ver_cut 1-2).0"
37 [[ "${EXTRAVERSION}" = -rc* ]] && KVE="${EXTRAVERSION}"
38
39 # Portage Vars
40 HOMEPAGE="https://www.linux-mips.org/ https://www.gentoo.org/"
41 KEYWORDS="-* ~mips"
42 IUSE="experimental ip27 ip28 ip30"
43 RDEPEND=""
44 DEPEND="${RDEPEND}
45         >=sys-devel/gcc-4.7.0
46         >=sys-devel/patch-2.7.4"
47
48 # Specify any patches or patch familes to NOT apply here.
49 # Use only the 4-digit number followed by a '*'.
50 P_EXCLUDE=""
51
52 # Machine Support Control Variables
53 DO_IP22="test"                          # If "yes", enable IP22 support         (SGI Indy, Indigo2 R4x00)
54 DO_IP27="yes"                           #                  IP27 support         (SGI Origin)
55 DO_IP28="test"                          #                  IP28 support         (SGI Indigo2 Impact R10000)
56 DO_IP30="yes"                           #                  IP30 support         (SGI Octane)
57 DO_IP32="yes"                           #                  IP32 support         (SGI O2, R5000/RM5200 Only)
58
59 # Machine Stable Version Variables
60 SV_IP22=""                              # If set && DO_IP22 == "no", indicates last "good" IP22 version
61 SV_IP27=""                              #           DO_IP27 == "no",                       IP27
62 SV_IP28=""                              #           DO_IP28 == "no",                       IP28
63 SV_IP30=""                              #           DO_IP30 == "no",                       IP30
64 SV_IP32=""                              #           DO_IP32 == "no",                       IP32
65
66 DESCRIPTION="Linux-Mips GIT sources for MIPS-based machines, dated ${GITDATE}"
67 SRC_URI="${KERNEL_URI}
68          mirror://gentoo/mipsgit-${BASE_KV}${KVE}-${GITDATE}.diff.xz
69          mirror://gentoo/${PN}-${BASE_KV}-patches-v${GENPATCHREV}.tar.xz"
70
71 UNIPATCH_STRICTORDER="yes"
72 UNIPATCH_LIST="${DISTDIR}/mipsgit-${BASE_KV}${KVE}-${GITDATE}.diff.xz"
73
74 #//------------------------------------------------------------------------------
75
76 err_disabled_mach() {
77         # Get args
78         local m_name="${1}"
79         local m_abbr="${2}"
80         local m_use="${3}"
81         local is_test="${4}"
82
83         # Get stable version, if exists
84         local stable_ver="SV_${m_abbr}"
85         stable_ver="${!stable_ver}"
86
87         # See if this machine needs a USE passed or skip dying
88         local has_use
89         [ ! -z "${m_use}" -a "${m_use}" != "skip" ] && has_use="USE=\"${m_use}\" "
90
91         # Print error && (maybe) die
92         echo -e ""
93         if [ "${is_test}" != "test" ]; then
94                 eerror "${m_name} Support has been disabled in this ebuild"
95                 eerror "revision.  If you wish to merge ${m_name} sources, then"
96                 eerror "run ${has_use}emerge =mips-sources-${stable_ver}"
97                 [ "${m_use}" != "skip" ] && die "${m_name} Support disabled."
98         else
99                 ewarn "${m_name} Support has been marked as needing testing in this"
100                 ewarn "ebuild revision.  This usually means that any patches to support"
101                 ewarn "${m_name} have been forward ported and maybe even compile-tested,"
102                 ewarn "but not yet booted on real hardware, possibly due to a lack of access"
103                 ewarn "to such hardware.  If you happen to boot this kernel and have no"
104                 ewarn "problems at all, then please inform the maintainer.  Otherwise, if"
105                 ewarn "experience a bug, an oops/panic, or some other oddity, then please"
106                 ewarn "file a bug at bugs.gentoo.org, and assign it to the mips team."
107         fi
108
109         return 0
110 }
111
112 err_only_one_mach_allowed() {
113         echo -e ""
114         eerror "A patchset for a specific machine-type has already been selected."
115         eerror "No other patches for machines-types are permitted.  You will need a"
116         eerror "separate copy of the kernel sources for each different machine-type"
117         eerror "you want to build a kernel for."
118         die "Only one machine-type patchset allowed"
119 }
120
121 pkg_postinst() {
122         # Symlink /usr/src/linux as appropriate
123         local my_ksrc="${S##*/}"
124         for x in {ip27,ip28,ip30}; do
125                 use ${x} && my_ksrc="${my_ksrc}.${x}"
126         done
127
128         if [ ! -e "${ROOT}usr/src/linux" ]; then
129                 rm -f "${ROOT}usr/src/linux"
130                 ln -sf "${my_ksrc}" "${ROOT}/usr/src/linux"
131         fi
132 }
133
134 pkg_setup() {
135         local arch_is_selected="no"
136         local m_ip m_enable m_name
137
138         # Exclusive machine patchsets
139         # These are not allowed to be mixed together, thus only one of them may be applied
140         # to a tree per merge.
141         for x in                                                                        \
142                 "ip27 SGI Origin 200/2000"                                              \
143                 "ip28 SGI Indigo2 Impact R10000"                                        \
144                 "ip30 SGI Octane"
145         do
146                 set -- ${x}             # Set positional params
147                 m_ip="${1}"             # Grab the first param (HW IP for SGI)
148                 shift                   # Shift the positions
149                 m_name="${*}"           # Get the rest (Name)
150
151                 if use ${m_ip}; then
152                         # Fetch the value indiciating if the machine is enabled or not
153                         m_enable="DO_${m_ip/ip/IP}"
154                         m_enable="${!m_enable}"
155
156                         # Make sure only one of these exclusive machine patches is selected
157                         [ "${arch_is_selected}" = "no" ]                                \
158                                 && arch_is_selected="yes"                               \
159                                 || err_only_one_mach_allowed
160
161                         # Is the machine support disabled or marked as needing testing?
162                         [ "${m_enable}" = "test" ]                                      \
163                                 && err_disabled_mach "${m_name}" "${m_ip/ip/IP}" "${m_ip}" "test"
164                         [ "${m_enable}" = "no" ]                                        \
165                                 && err_disabled_mach "${m_name}" "${m_ip/ip/IP}" "${m_ip}"
166
167                         # Show relevant information about the machine
168                         show_${m_ip}_info
169                 fi
170         done
171
172         # All other systems that don't have a USE flag go here
173         # These systems have base-line support included in linux-mips git, so
174         # instead of failing, if disabled, we simply warn the user
175         if [ "${arch_is_selected}" = "no" ]; then
176                 [ "${DO_IP22}" = "no" ]                                                 \
177                         && err_disabled_mach "SGI Indy/Indigo2 R4x00" "IP22" "skip"     \
178                         || show_ip22_info
179                 [ "${DO_IP32}" = "no" ]                                                 \
180                         && err_disabled_mach "SGI O2" "IP32" "skip"                     \
181                         || show_ip32_info
182
183         fi
184 }
185
186 show_ip22_info() {
187         echo -e ""
188         einfo "IP22 systems with an R5000 processor should work with this release."
189         einfo "The R4x00 series of processors tend to be rather flaky, especially the"
190         einfo "R4600.  If you have to run an R4x00 processor, then try to use an R4400."
191         einfo ""
192         einfo "Some Notes:"
193         einfo "\t- Supported graphics card right now is Newport (XL)."
194         einfo "\t- A driver for Extreme (XZ) does not exist at present."
195         echo -e ""
196 }
197
198 show_ip27_info() {
199         echo -e ""
200         ewarn "Heavy disk I/O on recent kernels may randomly trigger a VM_BUG_ON_PAGE()"
201         ewarn "in move_freepages() in mm/page_alloc.c.  The exact trigger cause is"
202         ewarn "unknown at this time.  Please report any oops messages from this"
203         ewarn "bug to bugs.gentoo.org (assign to mips@gentoo.org)"
204         echo -e ""
205 }
206
207 show_ip28_info() {
208         echo -e ""
209         einfo "Support for the Indigo2 Impact R10000 is now in the mainline kernel.  However,"
210         einfo "due to the R10000 Speculative Execution issue that exists with this machine,"
211         einfo "nothing is guaranteed to work correctly.  Consider enabling ${HILITE}CONFIG_KALLSYMS${NORMAL}"
212         einfo "in your kernel so that if the machine Oopes, you'll be able to provide valuable"
213         einfo "feedback that can be used to trace down the crash."
214         echo -e ""
215 }
216
217 show_ip30_info() {
218         echo -e ""
219         eerror "Things that DON'T work:"
220         eerror "\t- Do not use CONFIG_SLUB, otherwise, you'll get errors when booting"
221         eerror "\t\040\040regarding duplicate /sys/kernel/slab/* entries in sysfs."
222         eerror "\t- Impact (MGRAS) Xorg driver no longer functions due to severe bitrot."
223         eerror "\t- Octane is limited to a maximum of 2GB of memory right now due to a"
224         eerror "\t\040\040hardware quirk in the BRIDGE PCI chip that limits BRIDGE DMA"
225         eerror "\t\040\040addresses to 31-bits when converted into physical addresses."
226         eerror "\t\040\040Patches that attempt to fix the issue are highly welcome."
227         echo -e ""
228         ewarn "Things that might work, but have problems, or are unknown:"
229         ewarn "\t- CONFIG_TRANSPARENT_HUGEPAGE should work now, but there may still be"
230         ewarn "\t\040\040intermittent issues.  Additionally, CONFIG_HUGETLBFS must also be"
231         ewarn "\t\040\040selected for hugepages to work.  If use of this feature continues"
232         ewarn "\t\040\040to trigger random Instruction Bus Errors (IBEs), then it is best to"
233         ewarn "\t\040\040disable the functionality and perform a cold reset of the machine"
234         ewarn "\t\040\040after powering it down for at least 30 seconds."
235         ewarn "\t- Serial support on the Octane uses a very basic UART driver that drives"
236         ewarn "\t\040\040the 16550A chip on the IOC3 directly.  It does not use interrupts,"
237         ewarn "\t\040\040only a polling routine on a timer, which makes it slow and CPU-"
238         ewarn "\t\040\040intensive.  The baud rate is limited to no more than 38.4kbps on"
239         ewarn "\t\040\040this driver.  Patches for getting the Altix IOC3 serial driver to"
240         ewarn "\t\040\040work (which uses DMA and supports faster baud rates) are welcome."
241         ewarn "\t- UHCI Cards are known to have issues, but should still function."
242         ewarn "\t\040\040This issue primarily manifests itself when using pl2303 USB->Serial"
243         ewarn "\t\040\040adapters."
244         ewarn "\t- MENET boards appear to have the four ethernet ports detected, however"
245         ewarn "\t\040\040the six serial ports don't appear to get picked up by the IOC3"
246         ewarn "\t\040\040UART driver.  The NIC part number is also not read correctly"
247         ewarn "\t\040\040from the four Number-In-a-Cans.  Additional testing would be"
248         ewarn "\t\040\040appreciated and patches welcome."
249         ewarn "\t- Other XIO-based devices, like various Impact addons, remain untested"
250         ewarn "\t\040\040and are not guaranteed to work.  This applies to various digital"
251         ewarn "\t\040\040video conversion boards as well."
252         echo -e ""
253         einfo "Things that DO work:"
254         einfo "\t- SMP works again, celebrate!"
255         einfo "\t- Impact (MGRAS) console only."
256         einfo "\t- VPro (Odyssey) console only (no X driver exists yet)."
257         einfo "\t- PCI Card Cages should work for many devices, except certain types like"
258         einfo "\t\040\040PCI-to-PCI bridges (USB hubs, USB flash card readers for example)."
259         einfo "\t- SCSI, RTC, basic PCI, IOC3 Ethernet, keyboard, and mouse.  Please"
260         einfo "\t\040\040report any problems with these devices."
261         echo -e ""
262 }
263
264 show_ip32_info() {
265         echo -e ""
266         einfo "IP32 systems function well, however there are some notes:"
267         einfo "\t- A sound driver now exists for IP32.  Celebrate!"
268         einfo "\t- Framebuffer console is limited to 4MB.  Anything greater"
269         einfo "\t\040\040specified when building the kernel will likely oops"
270         einfo "\t\040\040or panic the kernel."
271         einfo "\t- X support is limited to the generic fbdev driver.  No X"
272         einfo "\t\040\040gbefb driver exists for O2 yet.  Feel free to submit"
273         einfo "\t\040\040patches!"
274         echo -e ""
275
276         einfo "To Build 64bit kernels for SGI O2 (IP32) or SGI Indy/Indigo2 R4x00 (IP22)"
277         einfo "systems, you need to use the ${GOOD}vmlinux.32${NORMAL} make target."
278         einfo "Once done, boot the ${GOOD}vmlinux.32${NORMAL} file (NOT vmlinux)."
279 }
280
281 src_unpack() {
282         # Unpack the kernel sources, update to the latest rev (if needed),
283         # and apply the latest patch from linux-mips git.
284         kernel-2_src_unpack
285
286         # Unpack the mips-sources patchset to ${WORKDIR}/mips-patches-${BASE_KV}.
287         echo -e ""
288         cd "${WORKDIR}"
289         unpack "${PN}-${BASE_KV}-patches-v${GENPATCHREV}.tar.xz"
290
291         # Create a new folder called  'patch-symlinks' and create symlinks to
292         # all mips-patches in there.  If we want to exclude a patch, we'll
293         # just delete the symlink instead of the actual patch.
294         local psym="patch-symlinks"
295         mkdir "${psym}"
296         cd "${psym}"
297         for x in ../mips-patches-${BASE_KV}/*.patch; do
298                 ln -s "${x}" "${x##../mips-patches-*/}"
299         done
300
301         # With symlinks created, setup the variables referencing external
302         # machine patches and if a machine USE flag is enabled, then unset
303         # its corresponding variable.
304         # See 0000_README for the patch numbers and their meanings.
305         local p_generic="51*"
306         local p_ip27="52*" p_ip28="53*" p_ip30="54*"
307         local p_xp="80*"
308         use ip27 && unset p_generic p_ip27
309         use ip28 && unset p_ip28
310         use ip30 && unset p_generic p_ip30
311         use experimental && unset p_xp
312
313         # Remove symlinks for any patches that we don't want applied.  We
314         # do this by looping through all the above variables, and deleting
315         # matching symlinks that point to the corresponding patches.
316         # The remaining symlinks will be applied to the kernel source.
317         #
318         # $P_EXCLUDE is a new var that can be set in an ebuild to exclude
319         # specific patches by wildcarding the patch number.
320         local patchlist="${p_generic} ${p_ip27} ${p_ip28} ${p_ip30} ${p_xp} ${P_EXCLUDE}"
321         for x in $patchlist;
322                 do rm -f "./${x}"
323         done
324
325         # Rename the source tree to match the linux-mips git checkout date and
326         # machine type.
327         local fkv="${F_KV%-*}"
328         local v="${fkv}-${GITDATE}"
329         for x in {ip27,ip28,ip30}; do
330                 use ${x} && v="${v}.${x}" && break
331         done
332         mv "${WORKDIR}/linux-${fkv/_/-}" "${WORKDIR}/linux-${v}" || die
333         S="${WORKDIR}/linux-${v}"
334
335         # Set the EXTRAVERSION to linux-VERSION-mipsgit-GITDATE
336         EXTRAVERSION="${EXTRAVERSION}-mipsgit-${GITDATE}"
337         unpack_set_extraversion
338 }
339
340 src_prepare() {
341         local psym="patch-symlinks"
342
343         # Now go into the kernel source and patch it.
344         cd "${S}"
345         epatch "${WORKDIR}/${psym}"/*.patch
346
347         eapply_user
348 }
349
350 #//------------------------------------------------------------------------------