Repository: archlinux/archinstall

Issue:
Autodetection of certain hardware requirements
I just ran archinstall on a laptop that uses tigerlake audio, which requires you to install sof-firmware in order to have the audio work, it would be nice if tigerlake audio was automatically detected if you choose to setup audio.


Discussion:
What would be the identifying thing we could use for this?
0000:00:1f.3 Multimedia audio controller: Intel Corporation Tiger Lake-LP Smart Sound Technology Audio Controller (rev 20)

this is what the device shows up as with lspci, I hope that is helpful!
I think it would be better with the PCI manufacturer ID and it's associated product ID (Vendor and Product ID).

Can't recall what flag it is to lspaci and i'm on my phone :)
Since `sof-firmware` is provided in the monthly ISO, the output of `lsmod` could be checked for if the SOF driver is in use. That might be better than using `lspci` and verifying vendor ID and device ID.
Are you speculating about a better way of handling this, or are you asking me to check what lsmod outputs? 

I would include the output of lsmod anyway but I don't currently have access to the computer, and won't for a bit
Speculating but the output of `lsmod` would be helpful.
```
Module                  Size  Used by
snd_seq_dummy          16384  0
snd_hrtimer            16384  1
snd_seq               114688  7 snd_seq_dummy
snd_seq_device         16384  1 snd_seq
snd_ctl_led            24576  0
snd_soc_skl_hda_dsp    28672  5
snd_soc_intel_hda_dsp_common    20480  1 snd_soc_skl_hda_dsp
snd_sof_probes         28672  0
snd_soc_hdac_hdmi      45056  1 snd_soc_skl_hda_dsp
snd_hda_codec_hdmi    102400  1
snd_hda_codec_realtek   212992  1
snd_hda_codec_generic   126976  1 snd_hda_codec_realtek
ledtrig_audio          16384  2 snd_ctl_led,snd_hda_codec_generic
ccm                    20480  6
algif_aead             16384  0
cbc                    16384  0
des_generic            16384  0
libdes                 28672  1 des_generic
ecb                    16384  0
algif_skcipher         16384  0
cmac                   16384  0
md4                    16384  0
algif_hash             20480  0
af_alg                 36864  3 algif_hash,algif_skcipher,algif_aead
snd_soc_dmic           16384  1
snd_sof_pci_intel_tgl    16384  2
snd_sof_intel_hda_common   229376  1 snd_sof_pci_intel_tgl
soundwire_intel        61440  1 snd_sof_intel_hda_common
soundwire_generic_allocation    16384  1 soundwire_intel
soundwire_cadence      49152  1 soundwire_intel
snd_sof_intel_hda      24576  1 snd_sof_intel_hda_common
snd_sof_pci            24576  2 snd_sof_intel_hda_common,snd_sof_pci_intel_tgl
snd_sof_xtensa_dsp     20480  1 snd_sof_intel_hda_common
snd_sof               401408  4 snd_sof_pci,snd_sof_intel_hda_common,snd_sof_probes,snd_sof_intel_hda
snd_sof_utils          20480  1 snd_sof
snd_soc_hdac_hda       28672  1 snd_sof_intel_hda_common
snd_hda_ext_core       36864  4 snd_sof_intel_hda_common,snd_soc_hdac_hdmi,snd_soc_hdac_hda,snd_sof_intel_hda
snd_soc_acpi_intel_match    73728  2 snd_sof_intel_hda_common,snd_sof_pci_intel_tgl
snd_soc_acpi           16384  2 snd_soc_acpi_intel_match,snd_sof_intel_hda_common
soundwire_bus         147456  3 soundwire_intel,soundwire_generic_allocation,soundwire_cadence
snd_soc_core          458752  8 soundwire_intel,snd_sof,snd_sof_intel_hda_common,snd_soc_hdac_hdmi,snd_soc_hdac_hda,snd_sof_probes,snd_soc_dmic,snd_soc_skl_hda_dsp
snd_compress           32768  2 snd_soc_core,snd_sof_probes
ac97_bus               16384  1 snd_soc_core
snd_pcm_dmaengine      20480  1 snd_soc_core
intel_tcc_cooling      16384  0
x86_pkg_temp_thermal    20480  0
intel_powerclamp       16384  0
coretemp               20480  0
snd_hda_intel          65536  0
snd_intel_dspcfg       36864  3 snd_hda_intel,snd_sof,snd_sof_intel_hda_common
kvm_intel             471040  0
rtw88_8822ce           16384  0
snd_intel_sdw_acpi     20480  2 snd_sof_intel_hda_common,snd_intel_dspcfg
uvcvideo              180224  4
rtw88_8822c           499712  1 rtw88_8822ce
snd_hda_codec         225280  8 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek,snd_soc_intel_hda_dsp_common,snd_soc_hdac_hda,snd_sof_intel_hda,snd_soc_skl_hda_dsp
kvm                  1400832  1 kvm_intel
videobuf2_vmalloc      20480  1 uvcvideo
rtw88_pci              40960  1 rtw88_8822ce
btusb                  77824  0
snd_hda_core          143360  11 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_ext_core,snd_hda_codec,snd_hda_codec_realtek,snd_soc_intel_hda_dsp_common,snd_sof_intel_hda_common,snd_soc_hdac_hdmi,snd_soc_hdac_hda,snd_sof_intel_hda
uvc                    16384  1 uvcvideo
videobuf2_memops       20480  1 videobuf2_vmalloc
irqbypass              16384  1 kvm
snd_hwdep              20480  1 snd_hda_codec
btrtl                  28672  1 btusb
rtw88_core            331776  2 rtw88_pci,rtw88_8822c
joydev                 28672  0
crct10dif_pclmul       16384  1
mousedev               24576  0
videobuf2_v4l2         40960  1 uvcvideo
crc32c_intel           24576  0
iTCO_wdt               16384  0
snd_pcm               217088  13 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,soundwire_intel,snd_sof,snd_sof_intel_hda_common,snd_soc_hdac_hdmi,snd_compress,snd_soc_core,snd_sof_utils,snd_hda_core,snd_pcm_dmaengine
8250_dw                24576  0
spi_pxa2xx_platform    36864  0
btbcm                  24576  1 btusb
r8169                 131072  0
i915                 4145152  37
polyval_clmulni        16384  0
realtek                40960  1
intel_pmc_bxt          16384  1 iTCO_wdt
hid_multitouch         36864  0
hp_wmi                 32768  0
mei_pxp                20480  0
polyval_generic        16384  1 polyval_clmulni
mei_hdcp               28672  0
dw_dmac                16384  0
videodev              385024  4 videobuf2_v4l2,uvcvideo
btintel                53248  1 btusb
gf128mul               20480  1 polyval_generic
mdio_devres            16384  1 r8169
snd_timer              57344  3 snd_seq,snd_hrtimer,snd_pcm
sparse_keymap          16384  1 hp_wmi
processor_thermal_device_pci_legacy    16384  0
videobuf2_common       90112  4 videobuf2_vmalloc,videobuf2_v4l2,uvcvideo,videobuf2_memops
ghash_clmulni_intel    16384  0
btmtk                  16384  1 btusb
ee1004                 20480  0
sha512_ssse3           57344  0
intel_rapl_msr         20480  0
iTCO_vendor_support    16384  1 iTCO_wdt
mac80211             1589248  2 rtw88_pci,rtw88_core
bluetooth            1126400  6 btrtl,btmtk,btintel,btbcm,btusb
aesni_intel           405504  4
spi_nor               147456  0
mei_me                 61440  2
platform_profile       16384  1 hp_wmi
crypto_simd            16384  1 aesni_intel
wmi_bmof               16384  0
mc                     94208  6 videodev,videobuf2_v4l2,uvcvideo,videobuf2_common
snd                   155648  26 snd_ctl_led,snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek,snd_sof,snd_timer,snd_soc_hdac_hdmi,snd_compress,snd_soc_core,snd_pcm
drm_buddy              20480  1 i915
cryptd                 32768  2 crypto_simd,ghash_clmulni_intel
ecdh_generic           16384  1 bluetooth
crc16                  16384  1 bluetooth
processor_thermal_device    24576  1 processor_thermal_device_pci_legacy
rapl                   20480  0
soundcore              16384  2 snd_ctl_led,snd
libphy                225280  3 r8169,mdio_devres,realtek
processor_thermal_rfim    28672  1 processor_thermal_device
i2c_algo_bit           24576  1 i915
mtd                   106496  3 spi_nor
intel_cstate           24576  0
mei                   196608  5 mei_hdcp,mei_pxp,mei_me
intel_uncore          266240  0
ttm                   106496  1 i915
intel_lpss_pci         28672  2
processor_thermal_mbox    16384  2 processor_thermal_rfim,processor_thermal_device
libarc4                16384  1 mac80211
intel_lpss             16384  1 intel_lpss_pci
pcspkr                 16384  0
idma64                 20480  0
drm_display_helper    221184  1 i915
i2c_i801               45056  0
processor_thermal_rapl    20480  1 processor_thermal_device
i2c_smbus              20480  1 i2c_i801
intel_rapl_common      40960  2 intel_rapl_msr,processor_thermal_rapl
intel_soc_dts_iosf     20480  1 processor_thermal_device_pci_legacy
cec                    98304  2 drm_display_helper,i915
video                  77824  1 i915
i2c_hid_acpi           16384  0
intel_gtt              32768  1 i915
i2c_hid                40960  1 i2c_hid_acpi
int3403_thermal        20480  0
wmi                    45056  3 hp_wmi,video,wmi_bmof
vfat                   24576  1
int340x_thermal_zone    20480  2 int3403_thermal,processor_thermal_device
fat                   106496  1 vfat
int3400_thermal        24576  0
acpi_thermal_rel       16384  1 int3400_thermal
mac_hid                16384  0
soc_button_array       24576  0
cfg80211             1327104  2 rtw88_core,mac80211
wireless_hotkey        16384  0
acpi_pad               24576  0
rfkill                 40960  6 hp_wmi,bluetooth,cfg80211
pkcs8_key_parser       16384  0
fuse                  217088  5
loop                   40960  0
dm_mod                225280  0
zram                   45056  2
ip_tables              36864  0
x_tables               65536  1 ip_tables
f2fs                 1028096  1
crc32_generic          16384  0
lz4hc_compress         24576  1 f2fs
lz4_compress           28672  1 f2fs
nvme                   69632  2
nvme_core             245760  3 nvme
nvme_common            24576  1 nvme_core
serio_raw              20480  0
atkbd                  40960  0
libps2                 24576  1 atkbd
vivaldi_fmap           16384  1 atkbd
spi_intel_pci          16384  0
crc32_pclmul           16384  1
xhci_pci               24576  0
spi_intel              36864  1 spi_intel_pci
vmd                    28672  0
xhci_pci_renesas       24576  1 xhci_pci
i8042                  53248  0
serio                  28672  4 serio_raw,atkbd,i8042

```
So if `snd_sof` is found in the output. Here is the important information:

```
Module                  Size  Used by
snd_sof               401408  4 snd_sof_pci,snd_sof_intel_hda_common,snd_sof_probes,snd_sof_intel_hda
```


I assume #1801 will be merged in time and after that we could do something like the following.

- `archinstall/lib/hardware.py`

  Add to the `_SysInfo` class:
  
  ```python
  @cached_property
  def loaded_modules(self) -> List[str]:
  	"""
  	Returns loaded modules
  	"""
  	modules_path = Path('/proc/modules')
  	modules: List[str] = []

  	with modules_path.open() as file:
  		for line in file:
  			modules.append(line.split()[0])

  	return modules
  ```

  Add to the `SysInfo` class:

  ```python
  @staticmethod
  def requires_sof() -> bool:
  	return 'snd_sof' in _sys_info.loaded_modules
  ```
- `archinstall/lib/installer.py`

  Add inside the `Installer.minimal_installation()` function:
  
  ```python
  if SysInfo.requires_sof():
  	self.base_packages.append('sof-firmware')
  ```
  
  The above would install `sof-firmware` regardless of the audio config. If this should depend on the audio config, here is another way.
  
  `archinstall/scripts/guided.py`
  `examples/interactive_installation.py`

  Add inside the `perform_installation()` function, within the `if audio := archinstall.arguments.get('audio', None):` conditional:
  
  ```python
  if SysInfo.requires_sof():
  	installation.add_additional_packages('sof-firmware')
  ```
@codefiles looks like a good approach. I'll try to merge that one during the day

Resolving patch:
diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py
--- a/archinstall/lib/hardware.py
+++ b/archinstall/lib/hardware.py
@@ -1,7 +1,7 @@
 import os
 from functools import cached_property
 from pathlib import Path
-from typing import Optional, Dict
+from typing import Optional, Dict, List
 
 from .general import SysCommand
 from .networking import list_interfaces, enrich_iface_types
@@ -169,3 +169,22 @@ def is_vm() -> bool:
 			debug(f"System is not running in a VM: {err}")
 
 		return False
+
+	@staticmethod
+	def _loaded_modules() -> List[str]:
+		"""
+		Returns loaded kernel modules
+		"""
+		modules_path = Path('/proc/modules')
+		modules: List[str] = []
+
+		with modules_path.open() as file:
+			for line in file:
+				module = line.split(maxsplit=1)[0]
+				modules.append(module)
+
+		return modules
+
+	@staticmethod
+	def requires_sof() -> bool:
+		return 'snd_sof' in SysInfo._loaded_modules()
diff --git a/archinstall/scripts/guided.py b/archinstall/scripts/guided.py
--- a/archinstall/scripts/guided.py
+++ b/archinstall/scripts/guided.py
@@ -182,6 +182,9 @@ def perform_installation(mountpoint: Path):
 				PipewireProfile().install(installation)
 			elif audio == 'pulseaudio':
 				installation.add_additional_packages("pulseaudio")
+
+			if SysInfo.requires_sof():
+				installation.add_additional_packages('sof-firmware')
 		else:
 			info("No audio server will be installed")
 
diff --git a/examples/interactive_installation.py b/examples/interactive_installation.py
--- a/examples/interactive_installation.py
+++ b/examples/interactive_installation.py
@@ -161,6 +161,9 @@ def perform_installation(mountpoint: Path):
 				PipewireProfile().install(installation)
 			elif audio == 'pulseaudio':
 				installation.add_additional_packages("pulseaudio")
+
+			if SysInfo.requires_sof():
+				installation.add_additional_packages('sof-firmware')
 		else:
 			info("No audio server will be installed.")
 


Test patch: