|
| 1 | +# Kernel Config Checker |
| 2 | + |
| 3 | +A robust kernel configuration validation system using Pydantic v2 schemas. Supports default configurations and per-kernel overrides with architecture-specific settings. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Schema-based validation** - Uses Pydantic v2 for robust config validation |
| 8 | +- **Multi-architecture support** - Handles x86_64 and arm64 architectures |
| 9 | +- **Flexible overrides** - Default configs with per-kernel overrides |
| 10 | +- **Interactive config management** - Add new configs with guided prompts |
| 11 | +- **Config querying** - Check config values across all kernels/architectures |
| 12 | +- **Legacy conversion** - Tools to migrate existing configurations |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +From the repo root, install the Python dependencies: |
| 17 | + |
| 18 | +```bash |
| 19 | +pip install -r toolkit/scripts/requirements.txt |
| 20 | +``` |
| 21 | + |
| 22 | +All commands below should be run from `toolkit/scripts/`: |
| 23 | + |
| 24 | +```bash |
| 25 | +cd toolkit/scripts |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +### Check Kernel Config |
| 31 | + |
| 32 | +Validate a `.config` file against intentional configurations: |
| 33 | + |
| 34 | +```bash |
| 35 | +python -m kernel_config_checker.check_config /path/to/.config kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json kernel-name architecture |
| 36 | +``` |
| 37 | + |
| 38 | +Example: |
| 39 | + |
| 40 | +```bash |
| 41 | +python -m kernel_config_checker.check_config kernel.config kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json kernel x86_64 |
| 42 | +``` |
| 43 | + |
| 44 | +### Add New Config |
| 45 | + |
| 46 | +Interactively add a new kernel configuration: |
| 47 | + |
| 48 | +```bash |
| 49 | +python -m kernel_config_checker.check_config --add-config kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json |
| 50 | +``` |
| 51 | + |
| 52 | +Features: |
| 53 | + |
| 54 | +- Add to default or override sections |
| 55 | +- Support for single or multiple architectures |
| 56 | +- Leave architectures blank to omit them from JSON |
| 57 | +- Create new override sections or use existing ones |
| 58 | + |
| 59 | +### Query Config Values |
| 60 | + |
| 61 | +Check a config value across all architectures and kernels: |
| 62 | + |
| 63 | +```bash |
| 64 | +python -m kernel_config_checker.check_config --check-all kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json CONFIG_NAME |
| 65 | +``` |
| 66 | + |
| 67 | +Example: |
| 68 | + |
| 69 | +```bash |
| 70 | +python -m kernel_config_checker.check_config --check-all kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json CONFIG_DRM |
| 71 | +``` |
| 72 | + |
| 73 | +## Configuration Schema |
| 74 | + |
| 75 | +The system uses a structured JSON schema with default and override sections: |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "default": { |
| 80 | + "kernel_configs": [ |
| 81 | + { |
| 82 | + "name": "CONFIG_EXAMPLE", |
| 83 | + "values": [ |
| 84 | + { |
| 85 | + "architecture": "x86_64", |
| 86 | + "value": "y" |
| 87 | + }, |
| 88 | + { |
| 89 | + "architecture": "arm64", |
| 90 | + "value": "m" |
| 91 | + } |
| 92 | + ], |
| 93 | + "justification": "Explanation for this config" |
| 94 | + } |
| 95 | + ] |
| 96 | + }, |
| 97 | + "overrides": [ |
| 98 | + { |
| 99 | + "name": "kernel-64k", |
| 100 | + "kernel_configs": [ |
| 101 | + { |
| 102 | + "name": "CONFIG_ARM64_64K_PAGES", |
| 103 | + "values": [ |
| 104 | + { |
| 105 | + "architecture": "arm64", |
| 106 | + "value": "y" |
| 107 | + } |
| 108 | + ], |
| 109 | + "justification": "needed for 64k page size" |
| 110 | + } |
| 111 | + ] |
| 112 | + } |
| 113 | + ] |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### Architecture Support |
| 118 | + |
| 119 | +- Configs can specify values for `x86_64`, `arm64`, or both |
| 120 | +- When adding configs, leaving an architecture blank omits it from the JSON |
| 121 | +- At least one architecture must be specified |
| 122 | + |
| 123 | +### Value Types |
| 124 | + |
| 125 | +- `y` - Built into kernel |
| 126 | +- `m` - Built as module |
| 127 | +- `n` - Disabled ("is not set" or missing) |
| 128 | +- Custom values supported for specific configs |
| 129 | + |
| 130 | +## Project Structure |
| 131 | + |
| 132 | +```text |
| 133 | +toolkit/scripts/kernel_config_checker/ |
| 134 | +├── schema/ |
| 135 | +│ ├── __init__.py # Package init |
| 136 | +│ ├── schema.py # Pydantic schema definitions |
| 137 | +│ └── print_schema.py # Schema utility |
| 138 | +├── kernel_configs_json/ |
| 139 | +│ └── azl3-os-required-kernel-configs.json # Main config file |
| 140 | +├── __init__.py # Package init |
| 141 | +├── check_config.py # Main checker and utilities |
| 142 | +└── README.md # This file |
| 143 | +``` |
| 144 | + |
| 145 | +## Examples |
| 146 | + |
| 147 | +### Adding a Config for Single Architecture |
| 148 | + |
| 149 | +```bash |
| 150 | +$ python -m kernel_config_checker.check_config --add-config test.json |
| 151 | +Adding new kernel configuration... |
| 152 | +Enter config name (e.g., CONFIG_EXAMPLE): CONFIG_X86_ONLY |
| 153 | +Enter values for each architecture (y/n/m or specific value, leave blank to skip): |
| 154 | +x86_64 value: y |
| 155 | +arm64 value: |
| 156 | +Enter justification: Only needed on x86_64 |
| 157 | +Add to [d]efault or [o]verride? [d]: d |
| 158 | +✓ Added CONFIG_X86_ONLY to default section |
| 159 | +``` |
| 160 | + |
| 161 | +Results in: |
| 162 | + |
| 163 | +```json |
| 164 | +{ |
| 165 | + "name": "CONFIG_X86_ONLY", |
| 166 | + "values": [ |
| 167 | + { |
| 168 | + "architecture": "x86_64", |
| 169 | + "value": "y" |
| 170 | + } |
| 171 | + ], |
| 172 | + "justification": "Only needed on x86_64" |
| 173 | +} |
| 174 | +``` |
| 175 | + |
| 176 | +### Querying Config Values |
| 177 | + |
| 178 | +```bash |
| 179 | +$ python -m kernel_config_checker.check_config --check-all kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json CONFIG_DRM |
| 180 | +Config: CONFIG_DRM |
| 181 | + arm64: default=m, kernel-hwe=y |
| 182 | + x86_64: default=m |
| 183 | + ⚠️ Conflicts in: arm64 |
| 184 | + Reason: amdgpu - https://github.com/microsoft/azurelinux/pull/10612 |
| 185 | +``` |
| 186 | + |
| 187 | +## Contributing |
| 188 | + |
| 189 | +1. Ensure all configs have proper justifications |
| 190 | +2. Test schema validation after changes |
| 191 | +3. Use the add-config command for consistency |
| 192 | +4. Validate configs against actual kernel .config files |
| 193 | + |
| 194 | +## License |
| 195 | + |
| 196 | +This project follows the same licensing as the Azure Linux project. |
0 commit comments