Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to safely compile kernel myself install and use it.
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Sat Mar 01, 2025 1:42 am    Post subject: Reply with quote

I think that we must copy some files local file system to the kernel source code.

In your tutorial you specified the word INTO.

Now my question is which files are to be copied from local file system to the kernel source code.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5687
Location: Bavaria

PostPosted: Sat Mar 01, 2025 2:30 am    Post subject: Reply with quote

rupeshforu3 wrote:
[...] In your tutorial you specified the word INTO. [...]

I have specified this word because it is technical not quite correct. Yes, the fiirmware files (and also the CPU microcode) are part of the kernel IMAGE ... but not IN the kernel.

rupeshforu3 wrote:
[...] Now my question is which files are to be copied from local file system to the kernel source code.

Okay ... you dont want to read this:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_kernel_configuration#Before_you_start
so I must tell you:
1. Boot your computer with our GentooLiveCD (either CD or copied to USB stick)
2. Change with CTRL-ALT-F1 to the console (and login as root)
3. do this command: dmesg | grep "Loading firmware"

For my INTEL system I have:
Code:
# dmesg | grep "Loading firmware"
[    8.895831] Loading firmware: i915/adls_dmc_ver2_01.bin
[    8.910450] Loading firmware: i915/tgl_guc_70.bin
[    8.910552] Loading firmware: i915/tgl_huc.bin
[   14.504934] Loading firmware: rtl_nic/rtl8125b-2.fw
# grep "EXTRA_FIRMWARE" /usr/src/linux/.config
CONFIG_EXTRA_FIRMWARE="i915/adls_dmc_ver2_01.bin intel-ucode/06-b7-01 rtl_nic/rtl8125b-2.fw i915/tgl_guc_70.bin i915/tgl_huc.bin"
CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"

If you ask who (or how) copies this files "INTO" the kernel IMAGE, the answer is: This is done automatically when you compile the kernel with "make".
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Sat Mar 01, 2025 4:09 am    Post subject: Reply with quote

Is it possible to run dmesg directly in the current Gentoo Linux.

At present I have Fedora 41 Live image so can I use it to obtain the modules loaded information.

If you say no then I must download Gentoo Linux live image and make usb and boot into it and run the commands you specified.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 55281
Location: 56N 3W

PostPosted: Sat Mar 01, 2025 10:18 am    Post subject: Reply with quote

rupeshforu3,

If your running kernel lists firmware as it's loaded, that is all that's needed.
Check your dmesg.
If not, you need a kernel that does.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Sat Mar 01, 2025 1:40 pm    Post subject: Reply with quote

Hi in the current Gentoo Linux with kernel version 6.12.16 I ran dmesg command I have seen the firmware loaded.

Another request is yesterday I have downloaded the book "Linux kernel in a nutshell" book at free of cost from the author and kernel developer Greg Kraoh website.

It consists of everything related to how to compile kernel myself but it was written and released in 2006.

Can you suggest whether it's enough to know how to compile kernel.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 55281
Location: 56N 3W

PostPosted: Sat Mar 01, 2025 2:01 pm    Post subject: Reply with quote

rupeshforu3,

The current print edition is dated 2009. Its a whole desktop reference too. Not just about the kernel.
A lot has changed over the last 20 years.

There are no shortcuts, Do it, get it wrong, learn from the error(s), fix the errors, try again.
Rinse and repeat until it works. You cannot learn about it by reading.
The good thing is that you do not start over every time. Just change what you already have.

It really is like this old post.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Sat Mar 01, 2025 3:21 pm    Post subject: Reply with quote

Thanks for your suggestions.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 512
Location: North~Sea~Coa~s~~t~~~

PostPosted: Mon Mar 03, 2025 5:02 am    Post subject: Reply with quote

Please be aware that KCLAGS=" -march=znver3", or native, may reset kernel configurations like CONFIG_MITIGATION_RETPOLINE, as it's appended.
In this case the kernel adds: -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix (can be seen with: KBUILD_VERBOSE=1 make -j, etc).

... but zenver3 has:
Code:
# gcc -Q --help=target -march=znver3 | grep mindirect
  -mindirect-branch-cs-prefix           [disabled]
  -mindirect-branch-register            [disabled]
  -mindirect-branch=                    keep
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2249

PostPosted: Mon Mar 03, 2025 9:00 am    Post subject: Reply with quote

lost+found, thanks, I was unaware of this. It might explain the confusing output I get from spectre-meltdown-checker!
_________________
Greybeard
Back to top
View user's profile Send private message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Mon Mar 03, 2025 12:46 pm    Post subject: Reply with quote

lost+found wrote:
Please be aware that KCLAGS=" -march=znver3", or native, may reset kernel configurations like CONFIG_MITIGATION_RETPOLINE, as it's appended.
In this case the kernel adds: -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix (can be seen with: KBUILD_VERBOSE=1 make -j, etc).

... but zenver3 has:
Code:
# gcc -Q --help=target -march=znver3 | grep mindirect
  -mindirect-branch-cs-prefix           [disabled]
  -mindirect-branch-register            [disabled]
  -mindirect-branch=                    keep


So can I use march=znver3 or not.

I want all the code present in the kernel to be compiled specifically for my CPU or APU.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 512
Location: North~Sea~Coa~s~~t~~~

PostPosted: Mon Mar 03, 2025 4:41 pm    Post subject: Reply with quote

@rupeshforu3

Well, yes and no. :wink:

Generally the kernel will run fine on march=native, probably slightly faster, but here at the cost of an important security setting. Probably not worth it.

This happened on an Intel machine trying to re-add the mitigation:

Code:
#export KCFLAGS=" -march=native -mindirect-branch=thunk-extern "
#export KCPPFLAGS="${KCFLAGS}"
(...)
  MKPIGGY arch/x86/boot/compressed/piggy.S
  AS      arch/x86/boot/compressed/piggy.o
  LD      arch/x86/boot/compressed/vmlinux
ld: Unexpected GOT/PLT entries detected!
ld: Unexpected run-time procedure linkages detected!
ld: Unexpected run-time relocations (.rela) detected!
ld: arch/x86/boot/compressed/misc.o: in function `__putstr.part.0':
misc.c:(.text+0x27c): undefined reference to `__x86_indirect_thunk_rax'
ld: misc.c:(.text+0x2a0): undefined reference to `__x86_indirect_thunk_rax'
ld: misc.c:(.text+0x2b8): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/misc.o: in function `decompress_kernel':
misc.c:(.text+0x2f2f): undefined reference to `__x86_indirect_thunk_r12'
ld: misc.c:(.text+0x325b): undefined reference to `__x86_indirect_thunk_r12'
ld: misc.c:(.text+0x3270): undefined reference to `__x86_indirect_thunk_r12'
ld: misc.c:(.text+0x32e8): undefined reference to `__x86_indirect_thunk_r12'
ld: misc.c:(.text+0x3300): undefined reference to `__x86_indirect_thunk_r12'
ld: arch/x86/boot/compressed/misc.o:misc.c:(.text+0x334b): more undefined references to `__x86_indirect_thunk_r12' follow
ld: arch/x86/boot/compressed/misc.o: in function `__putstr.part.0':
misc.c:(.text+0x2db): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/kaslr.o: in function `kaslr_get_random_long':
kaslr.c:(.text+0x2ea): undefined reference to `__x86_indirect_thunk_rax'
ld: kaslr.c:(.text+0x2f7): undefined reference to `__x86_indirect_thunk_rax'
ld: kaslr.c:(.text+0x307): undefined reference to `__x86_indirect_thunk_rax'
ld: kaslr.c:(.text+0x318): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/ident_map_64.o:ident_map_64.c:(.text+0x8e): more undefined references to `__x86_indirect_thunk_rax' follow
ld: arch/x86/boot/compressed/ident_map_64.o: in function `kernel_ident_mapping_free':
ident_map_64.c:(.text+0x45e): undefined reference to `__x86_indirect_thunk_r9'
ld: ident_map_64.c:(.text+0x479): undefined reference to `__x86_indirect_thunk_rax'
ld: ident_map_64.c:(.text+0x494): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/ident_map_64.o: in function `kernel_ident_mapping_init':
ident_map_64.c:(.text+0x530): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/ident_map_64.o: in function `kernel_ident_mapping_free':
ident_map_64.c:(.text+0x4ca): undefined reference to `__x86_indirect_thunk_rax'
ld: arch/x86/boot/compressed/pgtable_64.o: in function `configure_5level_paging':
pgtable_64.c:(.text+0x14b): undefined reference to `__x86_indirect_thunk_rbx'
  CC [M]  lib/math/rational.mod.o
make[3]: *** [arch/x86/boot/compressed/Makefile:112: arch/x86/boot/compressed/vmlinux] Error 1
make[2]: *** [arch/x86/boot/Makefile:100: arch/x86/boot/compressed/vmlinux] Error 2
make[1]: *** [arch/x86/Makefile:312: bzImage] Error 2
make[1]: *** Waiting for unfinished jobs....


So, I gave up for now.

UPDATE: LOL no ... KCFLAGS=" -mtune=native" for me.
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 512
Location: North~Sea~Coa~s~~t~~~

PostPosted: Wed Mar 05, 2025 4:45 pm    Post subject: Reply with quote

Goverp wrote:
(...)It might explain the confusing output I get from spectre-meltdown-checker!

The script also uses the old config name...
Code:
# sed -i~ 's/RETPOLINE/MITIGATION_RETPOLINE/' /usr/bin/spectre-meltdown-checker

After changing -v --explain made more sense to me.

Cheers
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2249

PostPosted: Thu Mar 06, 2025 8:26 am    Post subject: Reply with quote

Yup, the -9999 git version is up to date, AFAIR.
_________________
Greybeard
Back to top
View user's profile Send private message
rupeshforu3
n00b
n00b


Joined: 19 Aug 2024
Posts: 73

PostPosted: Tue Mar 11, 2025 2:51 am    Post subject: Reply with quote

Hi my main aim is I want to build a monolithic kernel ie., all the binaries to run the system must be in a single file.

I don't want modules to load.

In Linux there are a number of tools to obtain hardware information ie.,

1) hwinfo
2) lspci
3) lshw
4) lsmod
5) dmesg

Greg Kraoh who is kernel maintainer written two scripts to obtain modules information but I am using only one of them.

I ran all of the above mentioned commands and script and I have sorted out finally I got about 200 entries.

I used the commands in the following way.
Code:

rm modules* temp*
lspci -nnk > modules.txt
sudo lshw >> modules.txt
hwinfo >> modules.txt
cp modules.txt modules_original_full.txt
cat modules.txt | grep -i modules > temp1.txt
cat modules.txt | grep -i driver > temp2.txt
sudo dmesg | grep -i firmware > temp3_dmesg.txt
sudo lsmod > temp4_lsmod.txt
sudo ./find_all_modules.sh > temp5_greg.txt


Greg Kraoh script is as follows.
Code:

#!/bin/bash
for i in `find /sys/ -name modalias -exec cat {} \;`; do
 sudo   /sbin/modprobe --config /dev/null --show-depends $i ;
done | rev | cut -f 1 -d '/' | rev | sort -u


The final list of models or drivers are as follows.
Code:

Generic FE-GE Realtek PHY
acpi-cpufreq.ko
acpi-wmi
ahci
alarmtimer
amd64_edac.ko
amd_atl
amd_atl.ko
amd_gpio
amdgpu
amdgpu,drm_ttm_helper
amdgpu.ko
amdgpu/green_sardine_asd.bin
amdgpu/green_sardine_ce.bin
amdgpu/green_sardine_dmcub.bin
amdgpu/green_sardine_me.bin
amdgpu/green_sardine_mec.bin
amdgpu/green_sardine_pfp.bin
amdgpu/green_sardine_rlc.bin
amdgpu/green_sardine_sdma.bin
amdgpu/green_sardine_ta.bin
amdgpu/green_sardine_vcn.bin
amdxcp
amdxcp.ko
asus-wmi.ko
asus_wmi
asus_wmi,amdgpu
asus_wmi,cfg80211
builtin efi_pstore
button
ccp
cec
cec.ko
cfg80211
cfg80211.ko
crc32-pclmul.ko
crc32_pclmul
crc32c-intel.ko
crc32c_intel
crct10dif-pclmul.ko
crct10dif_pclmul
ctrl
drm_buddy
drm_buddy.ko
drm_display_helper
drm_display_helper.ko
drm_exec
drm_exec.ko
drm_suballoc_helper
drm_suballoc_helper.ko
drm_ttm_helper
drm_ttm_helper.ko
dummy
edac_mce_amd
edac_mce_amd.ko
ee1004
ee1004.ko
eeepc-wmi
eeepc-wmi.ko
eeepc_wmi
exfat
fat
fjes.ko
fmpm.ko
fuse
ghash-clmulni-intel.ko
ghash_clmulni_intel
gpio-amdpt.ko
gpio-generic.ko
gpio_amdpt
gpio_generic
gpu-sched.ko
gpu_sched
hid-generic
hub
i2c-algo-bit.ko
i2c-piix4.ko
i2c-smbus.ko
i2c_algo_bit
i2c_piix4
i2c_piix4, sp5100_tco
i2c_smbus
intel_rapl_common
intel_rapl_common.ko
intel_rapl_msr
intel_rapl_msr.ko
joydev
joydev.ko
k10temp
k10temp.ko
kgdboc
kvm
kvm-amd.ko
kvm.ko
kvm_amd
libarc4
libarc4.ko
loop
mac80211
mac80211,rtl8xxxu
mac80211.ko
nfnetlink
nvme
nvme-auth.ko
nvme-core.ko
nvme.ko
nvme_auth
nvme_core
pcieport
pcspkr
pcspkr.ko
piix4_smbus
pkcs8_key_parser
platform_profile
platform_profile.ko
polyval-clmulni.ko
polyval-generic.ko
polyval_clmulni
polyval_generic
port
processor
pt-gpio
r8169
r8169.ko
rapl
rapl.ko
realtek
realtek.ko
reg-dummy
regulatory.db
regulatory.db.p7s
rfkill
rfkill.ko
rtc_cmos
rtl8xxxu
rtl8xxxu.ko
rtl_nic/rtl8168h-2.fw
rtlwifi/rtl8192eu_nic.bin
serial
serial8250
sha1-ssse3.ko
sha1_ssse3
sha256-ssse3.ko
sha256_ssse3
sha512-ssse3.ko
sha512_ssse3
snd
snd-hda-codec-generic.ko
snd-hda-codec-hdmi.ko
snd-hda-codec-realtek.ko
snd-hda-codec.ko
snd-hda-core.ko
snd-hda-intel.ko
snd-hda-scodec-component.ko
snd-hwdep.ko
snd-intel-dspcfg.ko
snd-intel-sdw-acpi.ko
snd-pcm.ko
snd-pcsp.ko
snd-timer.ko
snd.ko
snd_hda_codec
snd_hda_codec_generic
snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek
snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_pcm
snd_hda_codec_hdmi
snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core
snd_hda_codec_realtek
snd_hda_core
snd_hda_intel
snd_hda_scodec_component
snd_hwdep
snd_intel_dspcfg
snd_intel_sdw_acpi
snd_pcm
snd_timer
soundcore
soundcore.ko
sp5100-tco
sp5100_tco
sp5100_tco.ko
sparse-keymap.ko
sparse_keymap
system
tpm_crb
ttm
ttm.ko
usb
usbhid
vfat
video
video,asus_wmi,wmi_bmof
video.ko
wmi
wmi-bmof
wmi-bmof.ko
wmi.ko
wmi_bmof
xhci_hcd


If you examaine the above list some entries end with .ko and these are obtained from greg script. some enries end with .bin and these are obtained from dmesg and remaining are obtained from hwino, lshw, lspci, lshw, lsmod.

Now my question is "Is there any need to search 200 entries in the kernel source code and enable them through extra firmware entry.".

Peitinger suggested to run the following command to obtain driver information and enter them into configuration file of kernel.

dmesg | grep -i "loading firmware"

Upon running the above command I got just 9 entries.

Can you suggest how to enter all the drivers to be compiled into kernel configuration.
_________________
Regards,
Rupesh.
Back to top
View user's profile Send private message
sublogic
Guru
Guru


Joined: 21 Mar 2022
Posts: 334
Location: Pennsylvania, USA

PostPosted: Tue Mar 11, 2025 11:01 pm    Post subject: Reply with quote

Have you considered doing a make localyesconfig , followed by a make menuconfig where you turn off CONFIG_MODULES and add the required EXTRA_FIRMWARE by hand ? With a Gentoo-patched kernel, you get the firmware list from just
Code:
dmesg | grep 'Loading firmware'

Alternatively, if you really want to do this by hand, the workhorse of localyesconfig is a perl script in scripts/kconfig/streamline_config.pl. It parses all the Kconfig's and Makefile's to find what option builds what module. You would have to reproduce that work yourself. If this is your first encounter with perl, I would consider this "jumping in the deep end of the pool".

Either way, you will have to rebuild your kernel after every sys-kernel/linux-firmware update. Also if you acquire a new device that requires a new driver.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum