Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/genkernel:master commit in: /
Date: Thu, 16 Jul 2020 15:03:29
Message-Id: 1594909755.0b5192921d06797c806bf908a0e88c1269f56794.whissi@gentoo
1 commit: 0b5192921d06797c806bf908a0e88c1269f56794
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jul 14 14:34:22 2020 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Thu Jul 16 14:29:15 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=0b519292
7
8 gen_configkernel.sh: set_initramfs_compression_method() refactored
9
10 - Add handling for compression method "best" and "fastest".
11
12 - Make use of new get_initramfs_compression_method_by_{compression,speed}
13 functions.
14
15 - Set CONFIG_RD_<TYPE>=n or CONFIG_INITRAMFS_COMPRESSION_<TYPE>=n
16 only when required to avoid second `make oldconfig` call due to
17 changed .config file.
18
19 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
20
21 gen_configkernel.sh | 128 +++++++++++++++++++++++++++++++++++----------------
22 gen_determineargs.sh | 2 +
23 2 files changed, 90 insertions(+), 40 deletions(-)
24
25 diff --git a/gen_configkernel.sh b/gen_configkernel.sh
26 index 1a7d3d3..6ee57ed 100755
27 --- a/gen_configkernel.sh
28 +++ b/gen_configkernel.sh
29 @@ -119,63 +119,105 @@ set_initramfs_compression_method() {
30
31 local kernel_config=${1}
32
33 - local compress_config=NONE
34 local -a KNOWN_INITRAMFS_COMPRESSION_TYPES=()
35 KNOWN_INITRAMFS_COMPRESSION_TYPES+=( NONE )
36 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( GZIP )
37 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( BZIP2 )
38 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( LZMA )
39 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( XZ )
40 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( LZO )
41 - KNOWN_INITRAMFS_COMPRESSION_TYPES+=( LZ4 )
42 -
43 - case ${COMPRESS_INITRD_TYPE} in
44 - gz)
45 - compress_config='GZIP'
46 - ;;
47 - bz2)
48 - compress_config='BZIP2'
49 - ;;
50 - lzma)
51 - compress_config='LZMA'
52 - ;;
53 - xz|best|fastest)
54 - compress_config='XZ'
55 - ;;
56 - lzop)
57 - compress_config='LZO'
58 - ;;
59 - lz4)
60 - compress_config='LZ4'
61 - ;;
62 - esac
63 + KNOWN_INITRAMFS_COMPRESSION_TYPES+=( $(get_initramfs_compression_method_by_compression) )
64 +
65 + if [[ "${COMPRESS_INITRD_TYPE}" =~ ^(BEST|FASTEST)$ ]]
66 + then
67 + print_info 5 "Determining '${COMPRESS_INITRD_TYPE}' compression method for initramfs ..."
68 + local ranked_methods
69 + if [[ "${COMPRESS_INITRD_TYPE}" == "BEST" ]]
70 + then
71 + ranked_methods=( $(get_initramfs_compression_method_by_compression) )
72 + else
73 + ranked_methods=( $(get_initramfs_compression_method_by_speed) )
74 + fi
75 +
76 + local ranked_method
77 + for ranked_method in "${ranked_methods[@]}"
78 + do
79 + print_info 5 "Checking if we can use '${ranked_method}' compression ..."
80 +
81 + # Do we have the user space tool?
82 + local compression_tool=${GKICM_LOOKUP_TABLE_CMD[${ranked_method}]/%\ */}
83 + if ! hash ${compression_tool} &>/dev/null
84 + then
85 + print_info 5 "Cannot use '${ranked_method}' compression, the tool '${compression_tool}' to compress initramfs was not found. Is ${GKICM_LOOKUP_TABLE_PKG[${ranked_method}]} installed?"
86 + continue
87 + fi
88 +
89 + # Is the kernel able to decompress?
90 + local koption="CONFIG_RD_${ranked_method}"
91 + local value_koption=$(kconfig_get_opt "${kernel_config}" "${koption}")
92 + if [[ "${value_koption}" != "y" ]]
93 + then
94 + print_info 5 "Cannot use '${ranked_method}' compression, kernel option '${koption}' is not set!"
95 + continue
96 + fi
97 +
98 + print_info 5 "Will use '${ranked_method}' compression -- all requirements are met!"
99 + COMPRESS_INITRD_TYPE=${ranked_method}
100 + break
101 + done
102 + unset ranked_method ranked_methods koption value_koption
103 +
104 + if [[ "${COMPRESS_INITRD_TYPE}" =~ ^(BEST|FASTEST)$ ]]
105 + then
106 + gen_die "None of the initramfs compression methods we tried are supported by your kernel (config file \"${kernel_config}\"), strange!?"
107 + fi
108 + fi
109 +
110 + local KOPTION_PREFIX=CONFIG_RD_
111 + [ ${KV_NUMERIC} -ge 4010 ] && KOPTION_PREFIX=CONFIG_INITRAMFS_COMPRESSION_
112 +
113 + # CONFIG_INITRAMFS_<TYPE> options are only used when CONFIG_INITRAMFS_SOURCE
114 + # is set. However, we cannot just check for INTEGRATED_INITRAMFS option here
115 + # because on first run kernel will still get compiled without
116 + # CONFIG_INITRAMFS_SOURCE set.
117 + local has_initramfs_source=no
118 + local cfg_CONFIG_INITRAMFS_SOURCE=$(kconfig_get_opt "${kernel_config}" "CONFIG_INITRAMFS_SOURCE")
119 + [[ -n "${cfg_CONFIG_INITRAMFS_SOURCE}" && ${#cfg_CONFIG_INITRAMFS_SOURCE} -gt 2 ]] && has_initramfs_source=yes
120
121 local KNOWN_INITRAMFS_COMPRESSION_TYPE
122 - local KOPTION_VALUE
123 + local KOPTION_VALUE KOPTION_CURRENT_VALUE
124 for KNOWN_INITRAMFS_COMPRESSION_TYPE in "${KNOWN_INITRAMFS_COMPRESSION_TYPES[@]}"
125 do
126 KOPTION_VALUE=n
127 - if [[ "${KNOWN_INITRAMFS_COMPRESSION_TYPE}" == "${compress_config}" ]]
128 + if [[ "${KNOWN_INITRAMFS_COMPRESSION_TYPE}" == "${COMPRESS_INITRD_TYPE}" ]]
129 then
130 KOPTION_VALUE=y
131 fi
132
133 - if [ ${KV_NUMERIC} -ge 4010 ]
134 + if isTrue "${has_initramfs_source}"
135 then
136 - kconfig_set_opt "${kernel_config}" "CONFIG_INITRAMFS_COMPRESSION_${KNOWN_INITRAMFS_COMPRESSION_TYPE}" "${KOPTION_VALUE}"
137 + KOPTION_CURRENT_VALUE=$(kconfig_get_opt "${kernel_config}" "${KOPTION_PREFIX}${KNOWN_INITRAMFS_COMPRESSION_TYPE}")
138 + if [[ -n "${KOPTION_CURRENT_VALUE}" ]] \
139 + && [[ "${KOPTION_VALUE}" != "${KOPTION_CURRENT_VALUE}" ]]
140 + then
141 + # We have to ensure that only the initramfs compression
142 + # we want to use is enabled or the last one listed in
143 + # $KERNEL_DIR/usr/Makefile will be used
144 + # However, no need to set =n value when option isn't set
145 + # at all (this will save us one additional "make oldconfig"
146 + # run due to changed kernel options).
147 + kconfig_set_opt "${kernel_config}" "${KOPTION_PREFIX}${KNOWN_INITRAMFS_COMPRESSION_TYPE}" "${KOPTION_VALUE}"
148 + fi
149
150 - if [[ "${KOPTION_VALUE}" == "y" && "${KNOWN_INITRAMFS_COMPRESSION_TYPE}" != "NONE" ]]
151 + if [[ "${KOPTION_VALUE}" == "y" ]]
152 then
153 - # Make sure that the kernel can decompress our initramfs
154 - kconfig_set_opt "${kernel_config}" "CONFIG_RD_${KNOWN_INITRAMFS_COMPRESSION_TYPE}" "${KOPTION_VALUE}"
155 + echo "${KOPTION_PREFIX}${KNOWN_INITRAMFS_COMPRESSION_TYPE}" >> "${KCONFIG_REQUIRED_OPTIONS}" \
156 + || gen_die "Failed to add '${KOPTION_PREFIX}${KNOWN_INITRAMFS_COMPRESSION_TYPE}' to '${KCONFIG_REQUIRED_OPTIONS}'!"
157 fi
158 - else
159 - [[ "${KNOWN_INITRAMFS_COMPRESSION_TYPE}" == "NONE" ]] && continue
160 + fi
161
162 - # In <linux-4.10, to control used initramfs compression, we have to
163 - # disable every supported compression type except compression type
164 - # we want to use, (see $KERNEL_DIR/usr/Makefile).
165 + if [[ "${KOPTION_VALUE}" == "y" && "${KNOWN_INITRAMFS_COMPRESSION_TYPE}" != "NONE" ]]
166 + then
167 + # Make sure that the kernel can always decompress our initramfs
168 kconfig_set_opt "${kernel_config}" "CONFIG_RD_${KNOWN_INITRAMFS_COMPRESSION_TYPE}" "${KOPTION_VALUE}"
169 +
170 + echo "CONFIG_RD_${KNOWN_INITRAMFS_COMPRESSION_TYPE}" >> "${KCONFIG_REQUIRED_OPTIONS}" \
171 + || gen_die "Failed to add 'CONFIG_RD_${KNOWN_INITRAMFS_COMPRESSION_TYPE}' to '${KCONFIG_REQUIRED_OPTIONS}'!"
172 fi
173 done
174 }
175 @@ -965,6 +1007,12 @@ config_kernel() {
176 compile_generic olddefconfig kernel 2>/dev/null
177 fi
178
179 + if [ -f "${KCONFIG_REQUIRED_OPTIONS}" ]
180 + then
181 + # Pick up required options from other functions
182 + required_kernel_options+=( $(cat "${KCONFIG_REQUIRED_OPTIONS}" | sort -u) )
183 + fi
184 +
185 print_info 2 "$(get_indent 1)>> Checking if required kernel options are still present ..."
186 local required_kernel_option=
187 for required_kernel_option in "${required_kernel_options[@]}"
188
189 diff --git a/gen_determineargs.sh b/gen_determineargs.sh
190 index 406d1d5..956e3bf 100755
191 --- a/gen_determineargs.sh
192 +++ b/gen_determineargs.sh
193 @@ -479,6 +479,8 @@ determine_real_args() {
194
195 declare -gr KCONFIG_MODIFIED_MARKER="${TEMP}/.kconfig_modified"
196
197 + declare -gr KCONFIG_REQUIRED_OPTIONS="${TEMP}/.kconfig_required_options"
198 +
199 if [ -n "${CMD_CROSS_COMPILE}" ]
200 then
201 if ! isTrue "$(is_valid_triplet "${CMD_CROSS_COMPILE}")"