| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
import os |
| 5 |
import sys |
| 6 |
from pathlib import Path |
| 7 |
|
| 8 |
# We import ukify.py, which is a template file. But only __version__ is |
| 9 |
# substituted, which we don't care about here. Having the .py suffix makes it |
| 10 |
# easier to import the file. |
| 11 |
sys.path.append(os.path.dirname(__file__) + '/../ukify') |
| 12 |
import ukify |
| 13 |
|
| 14 |
BYTES_PER_LINE = 16 |
| 15 |
|
| 16 |
hwids = ukify.parse_hwid_dir(Path(sys.argv[1])) |
| 17 |
|
| 18 |
print( |
| 19 |
'''/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 20 |
#include <stddef.h> |
| 21 |
#include <stdint.h> |
| 22 |
|
| 23 |
// NOLINTNEXTLINE(misc-use-internal-linkage) |
| 24 |
const uint8_t hwids_section_data[] = { |
| 25 |
''', |
| 26 |
end='', |
| 27 |
) |
| 28 |
|
| 29 |
for i, b in enumerate(hwids): |
| 30 |
print(f'0x{b:02X}, ', end='') |
| 31 |
if i % BYTES_PER_LINE == BYTES_PER_LINE - 1: |
| 32 |
print('\n ', end='') |
| 33 |
elif i == len(hwids) - 1: |
| 34 |
print('') |
| 35 |
|
| 36 |
print( |
| 37 |
'''}; |
| 38 |
|
| 39 |
// NOLINTNEXTLINE(misc-use-internal-linkage) |
| 40 |
const size_t hwids_section_len =''', |
| 41 |
f'{len(hwids)};', |
| 42 |
) |