1 Star 0 Fork 61

李双全/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
20001-hwdb-parse_hwdb_dot_py.patch 13.31 KB
一键复制 编辑 原始数据 按行查看 历史
zhongling.h 提交于 2023-10-30 15:54 +08:00 . Add optimized patches (hwdb,cgroup)
From: rpm-build <rpm-build>
Date: Thu, 28 Apr 2022 01:49:39 +0000
Subject: [PATCH] Update upstream parse_hwdb.py to fix parse-hwdb error
This patch does not correspond to a specific commit from upstream. Instead, it
is directly taken from
https://github.com/systemd/systemd/blob/f2c36c0e2445fa95ba109017d4b768b2fd825c43/hwdb.d/parse_hwdb.py.
This patch allows systemd-udev to parse newer hwdb. Hwdb is updated mostly
because of new hardware. Therefore, this patch allows systemd-udev to recongnize
these new hardware.
---
diff -uNrp systemd-239.orig/hwdb/parse_hwdb.py systemd-239/hwdb/parse_hwdb.py
--- systemd-239.orig/hwdb/parse_hwdb.py 2022-04-28 11:32:08.740731756 +0800
+++ systemd-239/hwdb/parse_hwdb.py 2022-04-28 11:32:08.741731786 +0800
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
-# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
-# SPDX-License-Identifier: MIT
+# SPDX-License-Identifier: MIT
#
# This file is distributed under the MIT license, see below.
#
@@ -30,12 +29,11 @@ import sys
import os
try:
- from pyparsing import (Word, White, Literal, ParserElement, Regex,
- LineStart, LineEnd,
+ from pyparsing import (Word, White, Literal, ParserElement, Regex, LineEnd,
OneOrMore, Combine, Or, Optional, Suppress, Group,
nums, alphanums, printables,
- stringEnd, pythonStyleComment, QuotedString,
- ParseBaseException)
+ stringEnd, pythonStyleComment,
+ ParseBaseException, __diag__)
except ImportError:
print('pyparsing is not available')
sys.exit(77)
@@ -52,33 +50,61 @@ except ImportError:
# don't do caching on old python
lru_cache = lambda: (lambda f: f)
+__diag__.warn_multiple_tokens_in_named_alternation = True
+__diag__.warn_ungrouped_named_tokens_in_collection = True
+__diag__.warn_name_set_on_empty_Forward = True
+__diag__.warn_on_multiple_string_args_to_oneof = True
+__diag__.enable_debug_on_named_expressions = True
+
EOL = LineEnd().suppress()
EMPTYLINE = LineEnd()
COMMENTLINE = pythonStyleComment + EOL
INTEGER = Word(nums)
-STRING = QuotedString('"')
REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER))
SIGNED_REAL = Combine(Optional(Word('-+')) + REAL)
UDEV_TAG = Word(string.ascii_uppercase, alphanums + '_')
+# Those patterns are used in type-specific matches
TYPES = {'mouse': ('usb', 'bluetooth', 'ps2', '*'),
'evdev': ('name', 'atkbd', 'input'),
+ 'fb': ('pci'),
'id-input': ('modalias'),
'touchpad': ('i8042', 'rmi', 'bluetooth', 'usb'),
'joystick': ('i8042', 'rmi', 'bluetooth', 'usb'),
'keyboard': ('name', ),
'sensor': ('modalias', ),
+ 'ieee1394-unit-function' : ('node', ),
+ 'camera': ('usb'),
}
+# Patterns that are used to set general properties on a device
+GENERAL_MATCHES = {'acpi',
+ 'bluetooth',
+ 'usb',
+ 'pci',
+ 'sdio',
+ 'vmbus',
+ 'OUI',
+ 'ieee1394',
+ }
+
+def upperhex_word(length):
+ return Word(nums + 'ABCDEF', exact=length)
+
@lru_cache()
def hwdb_grammar():
ParserElement.setDefaultWhitespaceChars('')
prefix = Or(category + ':' + Or(conn) + ':'
for category, conn in TYPES.items())
- matchline = Combine(prefix + Word(printables + ' ' + '®')) + EOL
+
+ matchline_typed = Combine(prefix + Word(printables + ' ' + '®'))
+ matchline_general = Combine(Or(GENERAL_MATCHES) + ':' + Word(printables + ' ' + '®'))
+ matchline = (matchline_typed | matchline_general) + EOL
+
propertyline = (White(' ', exact=1).suppress() +
- Combine(UDEV_TAG - '=' - Word(alphanums + '_=:@*.!-;, "') - Optional(pythonStyleComment)) +
+ Combine(UDEV_TAG - '=' - Optional(Word(alphanums + '_=:@*.!-;, "/'))
+ - Optional(pythonStyleComment)) +
EOL)
propertycomment = White(' ', exact=1) + pythonStyleComment + EOL
@@ -87,7 +113,7 @@ def hwdb_grammar():
(EMPTYLINE ^ stringEnd()).suppress())
commentgroup = OneOrMore(COMMENTLINE).suppress() - EMPTYLINE.suppress()
- grammar = OneOrMore(group('GROUPS*') ^ commentgroup) + stringEnd()
+ grammar = OneOrMore(Group(group)('GROUPS*') ^ commentgroup) + stringEnd()
return grammar
@@ -95,39 +121,57 @@ def hwdb_grammar():
def property_grammar():
ParserElement.setDefaultWhitespaceChars(' ')
- dpi_setting = (Optional('*')('DEFAULT') + INTEGER('DPI') + Suppress('@') + INTEGER('HZ'))('SETTINGS*')
+ dpi_setting = Group(Optional('*')('DEFAULT') + INTEGER('DPI') + Optional(Suppress('@') + INTEGER('HZ')))('SETTINGS*')
mount_matrix_row = SIGNED_REAL + ',' + SIGNED_REAL + ',' + SIGNED_REAL
- mount_matrix = (mount_matrix_row + ';' + mount_matrix_row + ';' + mount_matrix_row)('MOUNT_MATRIX')
+ mount_matrix = Group(mount_matrix_row + ';' + mount_matrix_row + ';' + mount_matrix_row)('MOUNT_MATRIX')
+ xkb_setting = Optional(Word(alphanums + '+-/@._'))
+
+ # Although this set doesn't cover all of characters in database entries, it's enough for test targets.
+ name_literal = Word(printables + ' ')
props = (('MOUSE_DPI', Group(OneOrMore(dpi_setting))),
('MOUSE_WHEEL_CLICK_ANGLE', INTEGER),
('MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL', INTEGER),
('MOUSE_WHEEL_CLICK_COUNT', INTEGER),
('MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL', INTEGER),
- ('ID_INPUT', Literal('1')),
- ('ID_INPUT_ACCELEROMETER', Literal('1')),
- ('ID_INPUT_JOYSTICK', Literal('1')),
- ('ID_INPUT_KEY', Literal('1')),
- ('ID_INPUT_KEYBOARD', Literal('1')),
- ('ID_INPUT_MOUSE', Literal('1')),
- ('ID_INPUT_POINTINGSTICK', Literal('1')),
- ('ID_INPUT_SWITCH', Literal('1')),
- ('ID_INPUT_TABLET', Literal('1')),
- ('ID_INPUT_TABLET_PAD', Literal('1')),
- ('ID_INPUT_TOUCHPAD', Literal('1')),
- ('ID_INPUT_TOUCHSCREEN', Literal('1')),
- ('ID_INPUT_TRACKBALL', Literal('1')),
- ('MOUSE_WHEEL_TILT_HORIZONTAL', Literal('1')),
- ('MOUSE_WHEEL_TILT_VERTICAL', Literal('1')),
+ ('ID_AUTOSUSPEND', Or((Literal('0'), Literal('1')))),
+ ('ID_AV_PRODUCTION_CONTROLLER', Or((Literal('0'), Literal('1')))),
+ ('ID_PERSIST', Or((Literal('0'), Literal('1')))),
+ ('ID_PDA', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_ACCELEROMETER', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_JOYSTICK', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_KEY', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_KEYBOARD', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_MOUSE', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_POINTINGSTICK', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_SWITCH', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_TABLET', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_TABLET_PAD', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_TOUCHPAD', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_TOUCHSCREEN', Or((Literal('0'), Literal('1')))),
+ ('ID_INPUT_TRACKBALL', Or((Literal('0'), Literal('1')))),
+ ('ID_SIGNAL_ANALYZER', Or((Literal('0'), Literal('1')))),
('POINTINGSTICK_SENSITIVITY', INTEGER),
('POINTINGSTICK_CONST_ACCEL', REAL),
('ID_INPUT_JOYSTICK_INTEGRATION', Or(('internal', 'external'))),
('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))),
- ('XKB_FIXED_LAYOUT', STRING),
- ('XKB_FIXED_VARIANT', STRING),
+ ('XKB_FIXED_LAYOUT', xkb_setting),
+ ('XKB_FIXED_VARIANT', xkb_setting),
+ ('XKB_FIXED_MODEL', xkb_setting),
('KEYBOARD_LED_NUMLOCK', Literal('0')),
('KEYBOARD_LED_CAPSLOCK', Literal('0')),
('ACCEL_MOUNT_MATRIX', mount_matrix),
+ ('ACCEL_LOCATION', Or(('display', 'base'))),
+ ('PROXIMITY_NEAR_LEVEL', INTEGER),
+ ('IEEE1394_UNIT_FUNCTION_MIDI', Or((Literal('0'), Literal('1')))),
+ ('IEEE1394_UNIT_FUNCTION_AUDIO', Or((Literal('0'), Literal('1')))),
+ ('IEEE1394_UNIT_FUNCTION_VIDEO', Or((Literal('0'), Literal('1')))),
+ ('ID_VENDOR_FROM_DATABASE', name_literal),
+ ('ID_MODEL_FROM_DATABASE', name_literal),
+ ('ID_TAG_MASTER_OF_SEAT', Literal('1')),
+ ('ID_INFRARED_CAMERA', Or((Literal('0'), Literal('1')))),
+ ('ID_CAMERA_DIRECTION', Or(('front', 'rear'))),
)
fixed_props = [Literal(name)('NAME') - Suppress('=') - val('VALUE')
for name, val in props]
@@ -165,8 +209,29 @@ def parse(fname):
return []
return [convert_properties(g) for g in parsed.GROUPS]
-def check_match_uniqueness(groups):
+def check_matches(groups):
matches = sum((group[0] for group in groups), [])
+
+ # This is a partial check. The other cases could be also done, but those
+ # two are most commonly wrong.
+ grammars = { 'usb' : 'v' + upperhex_word(4) + Optional('p' + upperhex_word(4) + Optional(':')) + '*',
+ 'pci' : 'v' + upperhex_word(8) + Optional('d' + upperhex_word(8) + Optional(':')) + '*',
+ }
+
+ for match in matches:
+ prefix, rest = match.split(':', maxsplit=1)
+ gr = grammars.get(prefix)
+ if gr:
+ # we check this first to provide an easy error message
+ if rest[-1] not in '*:':
+ error('pattern {} does not end with "*" or ":"', match)
+
+ try:
+ gr.parseString(rest)
+ except ParseBaseException as e:
+ error('Pattern {!r} is invalid: {}', rest, e)
+ continue
+
matches.sort()
prev = None
for match in matches:
@@ -196,15 +261,25 @@ def check_one_mount_matrix(prop, value):
def check_one_keycode(prop, value):
if value != '!' and ecodes is not None:
key = 'KEY_' + value.upper()
- if key not in ecodes:
- key = value.upper()
- if key not in ecodes:
- error('Keycode {} unknown', key)
+ if not (key in ecodes or
+ value.upper() in ecodes or
+ # new keys added in kernel 5.5
+ 'KBD_LCD_MENU' in key):
+ error('Keycode {} unknown', key)
+
+def check_wheel_clicks(properties):
+ pairs = (('MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL', 'MOUSE_WHEEL_CLICK_COUNT'),
+ ('MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL', 'MOUSE_WHEEL_CLICK_ANGLE'),
+ ('MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL', 'MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL'),
+ ('MOUSE_WHEEL_CLICK_COUNT', 'MOUSE_WHEEL_CLICK_ANGLE'))
+ for pair in pairs:
+ if pair[0] in properties and pair[1] not in properties:
+ error('{} requires {} to be specified', *pair)
def check_properties(groups):
grammar = property_grammar()
for matches, props in groups:
- prop_names = set()
+ seen_props = {}
for prop in props:
# print('--', prop)
prop = prop.partition('#')[0].rstrip()
@@ -214,30 +289,35 @@ def check_properties(groups):
error('Failed to parse: {!r}', prop)
continue
# print('{!r}'.format(parsed))
- if parsed.NAME in prop_names:
+ if parsed.NAME in seen_props:
error('Property {} is duplicated', parsed.NAME)
- prop_names.add(parsed.NAME)
+ seen_props[parsed.NAME] = parsed.VALUE
if parsed.NAME == 'MOUSE_DPI':
check_one_default(prop, parsed.VALUE.SETTINGS)
elif parsed.NAME == 'ACCEL_MOUNT_MATRIX':
check_one_mount_matrix(prop, parsed.VALUE)
elif parsed.NAME.startswith('KEYBOARD_KEY_'):
- check_one_keycode(prop, parsed.VALUE)
+ val = parsed.VALUE if isinstance(parsed.VALUE, str) else parsed.VALUE[0]
+ check_one_keycode(prop, val)
+
+ check_wheel_clicks(seen_props)
def print_summary(fname, groups):
+ n_matches = sum(len(matches) for matches, props in groups)
+ n_props = sum(len(props) for matches, props in groups)
print('{}: {} match groups, {} matches, {} properties'
- .format(fname,
- len(groups),
- sum(len(matches) for matches, props in groups),
- sum(len(props) for matches, props in groups)))
+ .format(fname, len(groups), n_matches, n_props))
+
+ if n_matches == 0 or n_props == 0:
+ error('{}: no matches or props'.format(fname))
if __name__ == '__main__':
- args = sys.argv[1:] or glob.glob(os.path.dirname(sys.argv[0]) + '/[67]0-*.hwdb')
+ args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[678][0-9]-*.hwdb'))
for fname in args:
groups = parse(fname)
print_summary(fname, groups)
- check_match_uniqueness(groups)
+ check_matches(groups)
check_properties(groups)
sys.exit(ERROR)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shqli/systemd.git
git@gitee.com:shqli/systemd.git
shqli
systemd
systemd
a8

搜索帮助