Added kernel-config, gamepad.xml, and qol.

This commit is contained in:
Zeckmathederg 2024-06-10 00:59:36 -06:00
parent fb3205b3c0
commit b5598f98cd
24 changed files with 510 additions and 1 deletions

2
kernel-config/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__
s-kernel-version

29
kernel-config/Makefile Normal file
View File

@ -0,0 +1,29 @@
INPUT = $(wildcard */*.toml */*/*.toml */*/*/*.toml)
OUTPUT = $(patsubst %.toml, ../%-kernel.xml, $(INPUT))
ifeq ($(KERNEL_TREE),)
$(error "must set KERNEL_TREE=/path/to/kernel/source")
endif
all: $(OUTPUT) ../introduction/welcome/conventions-kernel.xml
kernel.version: s-kernel-version; @true
.PHONY: s-kernel-version
s-kernel-version:
./kernel_version.py $(KERNEL_TREE) > tmp-kernel.version
if ! diff tmp-kernel.version kernel.version ; then \
mv tmp-kernel.version kernel.version; \
else \
rm tmp-kernel.version; \
fi
touch s-kernel-version
%-kernel.xml.tmp: %.toml kernel-config.py kernel_version.py kernel.version
./kernel-config.py $(KERNEL_TREE) $< > $@
../%-kernel.xml: %-kernel.xml.tmp
mv $< $@
../introduction/welcome/conventions-kernel.xml: kernel-config.py testdata/Kconfig testdata/config.toml.example
./kernel-config.py testdata testdata/config.toml.example > $@

8
kernel-config/NEEDED Normal file
View File

@ -0,0 +1,8 @@
introduction/important/cgroup
shareddeps/audio/alsa-lib
shareddeps/drivers/gpuconfig
shareddeps/drivers/nvidia (DRM only)
shareddeps/dps/x/xorg-server
shareddeps/dps/x/libevdev
shareddeps/dps/x/x7driver-wacom
qol/gamepad

306
kernel-config/kernel-config.py Executable file
View File

@ -0,0 +1,306 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# Copyright 2023 The LFS Editors
# Stupid script to render "mconf"-style kernel configuration
# Usage: kernel-config.py [path to kernel tree] [needed config].toml
# The toml file should be like:
# for bool and tristate:
# EXT4="*"
# DRM="*M"
# EXPERT=" "
# DRM_I915="*M"
# for choice:
# HIGHMEM64G="X"
# an entry with comment:
# DRM_I915 = { value = " *M", comment = "for i915, crocus, or iris" }
choice_bit = 1 << 30
ind0 = 0
ind1 = 0
menu_id = 1
stack = []
if_stack = []
expand_var_mp = { 'SRCARCH': 'x86' }
main_dep = {}
def expand_var(s):
for k in expand_var_mp:
s = s.replace('$(' + k + ')', expand_var_mp[k])
return s
def pop_stack(cond):
global ind0, ind1, stack
assert(cond(stack[-1][0]))
s, i0, i1, _ = stack[-1]
stack = stack[:-1]
ind0 -= i0
ind1 -= i1
def pop_stack_while(cond):
while stack and cond(stack[-1][0]):
pop_stack(cond)
def cur_menu():
global stack
return stack[-1][3] if stack else 0
def cur_if():
global if_stack
return if_stack[-1][:] if if_stack else []
def clean_dep(d):
d = d.strip()
if d.endswith('=y') or d.endswith('=M'):
d = d[:-2]
elif d.endswith(' != ""'):
d = d[:-6]
return d
def parse_config(buf):
global ind0, ind1, stack, menu_id
is_choice = buf[0].strip() == 'choice'
is_menu = buf[0].startswith('menu') or is_choice
is_nonconfig_menu = buf[0].startswith('menu ') or is_choice
key = None if is_nonconfig_menu else buf[0].split()[1].strip()
title = buf[0][len('menu '):] if is_nonconfig_menu else None
deps = ['menu'] + cur_if()
klass = None
for line in buf[1:]:
line = line.strip()
if line.startswith('depends on '):
new_deps = line[len('depends on '):].split('&&')
deps += [clean_dep(x) for x in new_deps]
elif line.startswith('prompt'):
title = line[len('prompt '):]
else:
for prefix in ['tristate', 'bool', 'string']:
if line.startswith(prefix + ' '):
title = line[len(prefix) + 1:]
klass = prefix
elif line == prefix:
klass = prefix
elif line.startswith('def_' + prefix + ' '):
klass = prefix
else:
continue
if '"' in line:
tail = line[line.rfind('"') + 1:].strip()
if tail[:3] == 'if ':
deps += [clean_dep(x) for x in tail[3:].split('&&')]
pop_stack_while(lambda x: x not in deps)
menu_id += is_menu
internal_key = key or menu_id
if stack:
fa = stack[-1][0]
if fa == 'menu':
fa = cur_menu() & ~choice_bit
main_dep[internal_key] = fa
val = known_config.get(key)
comment = None
forced = None
if type(val) == dict:
comment = val.get('comment')
forced = val.get('forced')
val = val['value']
klass = klass or 'string'
if title:
title = title.strip().lstrip('"')
title = title[:title.find('"')]
if not val:
pass
elif klass == 'string':
val = '(' + val + ')'
else:
assert((val == 'X') == bool(cur_menu() & choice_bit))
if (val == 'X'):
val = '(X)'
else:
val = list(val)
val.sort()
for c in val:
if c not in 'M* ' or (c == 'M' and klass != 'tristate'):
raise Exception('unknown setting %s for %s' % (c, key))
bracket = None
if klass == 'tristate' and forced != '*' :
bracket = '{}' if forced else '<>'
else:
bracket = '--' if forced else '[]'
val = bracket[0] + '/'.join(val) + bracket[1]
arrow = ' --->' if is_menu else ''
r = [ind0, val, ind1, title, arrow, internal_key, cur_menu(), comment]
# Don't indent for untitled (internal) entries
x = 2 if title else 0
key = key or 'menu'
menu = (menu_id if is_menu else cur_menu())
menu |= choice_bit if is_choice else 0
stack_ent = (key, 2, 0, menu) if is_menu else (key, 0, x, menu)
ind0 += stack_ent[1]
ind1 += stack_ent[2]
stack += [stack_ent]
return r
def load_kconfig(file):
global ind0, ind1, stack, path, menu_id, if_stack
r = []
config_buf = []
with open(path + file) as f:
for line in f:
if config_buf:
if not (line.startswith('\t') or line.startswith(' ')):
r += [parse_config(config_buf)]
config_buf = []
else:
config_buf += [line]
continue
if line.startswith('source') or line.startswith('\tsource'):
sub = expand_var(line.strip().split()[1].strip('"'))
r += load_kconfig(sub)
elif line.startswith('config') or line.startswith('menu'):
config_buf = [line]
elif line.startswith('choice'):
config_buf = [line]
elif line.startswith('endmenu') or line.startswith('endchoice'):
pop_stack_while(lambda x: x != 'menu')
pop_stack(lambda x: x == 'menu')
elif line.startswith('if '):
line = line[3:]
top = cur_if()
top += [x.strip() for x in line.split("&&")]
if_stack += [top]
elif line.startswith('endif'):
if_stack = if_stack[:-1]
if config_buf:
r += [parse_config(config_buf)]
return r
known_config = {}
def escape(x):
return x.replace('<', '&lt;').replace('>', '&gt;')
from sys import argv
import tomllib
path = argv[1]
if path[-1] != '/':
path += '/'
with open(argv[2], 'rb') as f:
known_config = tomllib.load(f)
r = load_kconfig('Kconfig')
# Refcount all menus
index_ikey = {}
for i in reversed(range(len(r))):
index_ikey[r[i][5]] = i
for i in reversed(range(len(r))):
if r[i][1] != None:
key = r[i][5]
fa = main_dep.get(key)
if not fa:
continue
j = index_ikey[fa]
if type(fa) == int or not r[j][3]:
# The main dependency is a menu or untitled magic entry,
# just mark it used
r[j][1] = ''
if r[j][1] is None:
raise Exception('[%s] needs unselected [%s]' % (key, fa))
r = [i for i in r if i[1] != None and i[3]]
# Now we are going to pretty-print r
## Calculate the maximum value length for each menu
max_val_len = {}
for _, val, _, _, _, _, menu, _ in r:
x = max_val_len.get(menu) or 0
max_val_len[menu] = max(x, len(val))
## Output
max_line = 80
buf = []
done = [x[5] for x in r] + ['revision']
for i in known_config:
if i not in done:
raise Exception("%s seems not exist" % i)
sep = known_config.get('separate_toplevel_menu')
for i0, val, i1, title, arrow, key, menu, comment in r:
rem = max_line
is_choice = (val == '(X)')
if val:
val += (max_val_len[menu] - len(val)) * ' '
rem -= i0 + i1 + bool(val) + len(val)
line = i0 * ' ' + escape(val) + (i1 + bool(val)) * ' '
rem -= len(arrow)
if len(title) > rem:
title = title[:rem - 3] + '...'
b = title
if not is_choice:
while not (b[0].isalpha() and b[0] not in 'YyMmNnHh'):
b = b[1:]
a = title[:len(title) - len(b)]
b0 = "<emphasis role='blue'>" + escape(b[0]) + "</emphasis>"
line += escape(a) + b0 + escape(b[1:]) + escape(arrow)
rem -= len(title)
key = ' [' + key + ']' if type(key) == str else ''
if len(key) <= rem:
line += (rem - len(key)) * ' ' + key
else:
key = '... ' + key
line += '\n' + ' ' * (max_line - len(key)) + key
if type(comment) == str:
comment = [comment]
if comment:
comment = '\n'.join([' ' * i0 + '# ' + line for line in comment])
buf += [escape(comment) + ':']
if not menu and buf:
buf += ['']
buf += [line.rstrip()]
from jinja2 import Template
t = Template('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- Automatically generated by kernel-config.py
DO NOT EDIT! -->
<screen{{ rev }}>{{ '\n'.join(buf) }}</screen>''')
rev = known_config.get('revision')
rev = ' revision="%s"' % rev if rev else ''
print(t.render(rev = rev, buf = buf))

View File

@ -0,0 +1 @@
6.8.9

27
kernel-config/kernel_version.py Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
def kernel_version(path):
version = None
patchlevel = None
sublevel = None
with open(path + 'Makefile') as f:
for line in f:
if line.startswith('VERSION ='):
version = line[len('VERSION ='):].strip()
elif line.startswith('PATCHLEVEL ='):
patchlevel = line[len('PATCHLEVEL ='):].strip()
elif line.startswith('SUBLEVEL ='):
sublevel = line[len('SUBLEVEL ='):].strip()
assert(version and patchlevel and sublevel)
return '.'.join([version, patchlevel, sublevel])
if __name__ == '__main__':
from sys import argv
path = argv[1]
if path[:-1] != '/':
path += '/'
print(kernel_version(path))

View File

@ -0,0 +1,4 @@
HID_SUPPORT="*"
HID="*M"
HID_NINTENDO= { value = " *", comment = "For Nintendo gamepad support" }
NINTENDO_FF="* "

View File

@ -0,0 +1,8 @@
SOUND = '*M'
[SND]
value = '*M'
comment = [
'Select settings and drivers appropriate for your hardware',
'in the submenu',
]

View File

@ -0,0 +1,3 @@
INPUT_MISC="*"
INPUT_UINPUT="*M"
INPUT = { value = '*', forced = '*' }

View File

@ -0,0 +1,3 @@
# forced by VT && TTY, with !EXPERT VT and TTY are always set
INPUT = { value = "*", forced = "*" }
INPUT_EVDEV="*M"

View File

@ -0,0 +1,7 @@
HID_SUPPORT="*"
# forced by USB_HID && HID_SUPPORT && USB && INPUT
HID = { value = "*M", forced = true }
USB_HID = "*M"
USB_SUPPORT="*"
USB = "*M"
HID_WACOM = "*M"

View File

@ -0,0 +1,3 @@
SYSFB_SIMPLEFB="*"
DRM="*"
DRM_SIMPLEDRM="*"

View File

@ -0,0 +1,4 @@
DRM="*M"
DRM_VMWGFX="*M "
DRM_BOCHS="*M "
DRM_VBOXVIDEO="*M "

View File

@ -0,0 +1,10 @@
DRM="*M"
DRM_RADEON = { value = " *M", comment = "For r300 or r600" }
DRM_AMDGPU = { value = " *M", comment = "For radeonsi" }
DRM_AMDGPU_SI="*"
DRM_AMDGPU_CIK="*"
DRM_AMD_DC="*"
DRM_NOUVEAU = { value = " *M", comment = "For nouveau" }
DRM_I915 = { value = " *M", comment = "For i915, crocus, or iris" }
DRM_VMWGFX = { value = " *M", comment = "For svga" }
DRM_VGEM = { value = " *M", comment = "For swrast" }

View File

@ -0,0 +1 @@
DRM="*M"

31
kernel-config/testdata/Kconfig vendored Normal file
View File

@ -0,0 +1,31 @@
menu "Master section"
menu "Subsection"
config REQU_PAR
bool "Required parameter"
config REQU_PAR_NMOD
tristate "Required parameter (not as module)"
config REQU_PAR_MOD
tristate "Required parameter (could be a module)"
config REQU_PAR_MOD_ONLY
tristate "Required parameter (as a module)"
config OPT_PAR
tristate "Optional parameter"
config OPT_PAR_MOD_ONLY
tristate "Optional parameter (as a module if enabled)"
config INCOMP_PAR
bool "Incompatible parameter"
config INCOMP_PAR_MOD
tristate "Incompatible parameter (even as module)"
endmenu # subsection
endmenu # master section

View File

@ -0,0 +1,8 @@
REQU_PAR='*'
REQU_PAR_NMOD='*'
REQU_PAR_MOD='*M'
OPT_PAR='*M '
INCOMP_PAR=' '
INCOMP_PAR_MOD=' '
REQU_PAR_MOD_ONLY='M'
OPT_PAR_MOD_ONLY=' M'

12
qol/gamepad-kernel.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- Automatically generated by kernel-config.py
DO NOT EDIT! -->
<screen><emphasis role='blue'>D</emphasis>evice Drivers ---&gt;
[*] H<emphasis role='blue'>I</emphasis>D bus support ---&gt; [HID_SUPPORT]
&lt;*/M&gt; H<emphasis role='blue'>I</emphasis>D bus core support [HID]
<emphasis role='blue'>S</emphasis>pecial HID drivers ---&gt;
# For Nintendo gamepad support:
&lt; /*&gt; N<emphasis role='blue'>i</emphasis>ntendo Joy-Con, NSO, and Pro Controller support [HID_NINTENDO]
[ /*] N<emphasis role='blue'>i</emphasis>ntendo Switch controller force feedback support [NINTENDO_FF]</screen>

33
qol/gamepad.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % general-entities SYSTEM "../../general.ent">
%general-entities;
]>
<sect1 id="gamepad" xreflabel="Gamepad Support">
<?dbhtml filename="gamepad.html"?>
<title>Gamepad Support</title>
<para>
Gamepads, or more widely known as game controllers, can be used with many
applications and games. However if you compiled the kernel yourself, the
kernel drivers for gamepads are not enabled. Go ahead and enable the kernel
options below and recompile the kernel if necessary.
</para>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="gamepad-kernel.xml"/>
<para>
Now you should be able to plug in your gamepad and play. If you want to use
the gamepad wirelessly, you will need to connect in via Bluetooth. You can
enable Bluetooth by following the BLFS page <ulink
url="&blfs-svn;/general/bluez.html">BlueZ</ulink> if you haven't already
compiled it. If you have chosen to install a desktop environment, if not
already done, you can likely install a bluetooth application specific to
the desktop environment.
</para>
</sect1>

0
qol/qol.xml Normal file
View File

0
qol/qolintro.xml Normal file
View File

View File

@ -27,7 +27,7 @@
Enable the ones you need and recompile the kernel if necessary.
</para>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="gpu-kernel.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="gpuconfig-kernel.xml"/>
<note>
<para>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- Automatically generated by kernel-config.py
DO NOT EDIT! -->
<screen><emphasis role='blue'>D</emphasis>evice Drivers ---&gt;
<emphasis role='blue'>G</emphasis>raphics support ---&gt;
&lt;*/M&gt; <emphasis role='blue'>D</emphasis>irect Rendering Manager (XFree86 4.1.0 and higher DRI support) ---&gt;
... [DRM]</screen>