Tools: const-ify pci-ids data.

This moves ~620 kBytes of data into the read-only data section.
This commit is contained in:
Darius Davis 2024-01-25 18:23:24 +10:00 committed by AndersBroman
parent 864c212b51
commit f5f8a574b1
2 changed files with 3095 additions and 2559 deletions

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,7 @@ typedef struct
uint16_t did;
uint16_t svid;
uint16_t ssid;
char *name;
const char *name;
} pci_id_t;
@ -52,14 +52,14 @@ typedef struct
{
uint16_t vid;
uint16_t count;
pci_id_t *ids_ptr;
pci_id_t const *ids_ptr;
} pci_vid_index_t;
"""
CODE_POSTFIX = """
static pci_vid_index_t *get_vid_index(uint16_t vid)
static pci_vid_index_t const *get_vid_index(uint16_t vid)
{
uint32_t start_index = 0;
uint32_t end_index = 0;
@ -96,9 +96,9 @@ static pci_vid_index_t *get_vid_index(uint16_t vid)
const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid)
{
unsigned int i;
static char *not_found = \"Not found\";
pci_vid_index_t *index_ptr;
pci_id_t *ids_ptr;
static const char *not_found = \"Not found\";
pci_vid_index_t const *index_ptr;
pci_id_t const *ids_ptr;
index_ptr = get_vid_index(vid);
@ -184,7 +184,7 @@ def main():
did = -1
svid = -1
ssid = -1
out_lines += "pci_id_t pci_vid_%04X[] = {\n" % (vid)
out_lines += "static pci_id_t const pci_vid_%04X[] = {\n" % (vid)
out_lines += "{0x%04X, 0xFFFF, 0xFFFF, 0xFFFF, \"%s(0x%04X)\"},\n" % (vid, words[1].strip(), vid)
id_list.append(vid)
continue
@ -227,7 +227,7 @@ def main():
out_lines += "}; /* pci_vid_%04X[] */\n" % (vid)
count_list.append(entries)
out_lines += "\npci_vid_index_t pci_vid_index[] = {\n"
out_lines += "\nstatic pci_vid_index_t const pci_vid_index[] = {\n"
vendor_count = len(id_list)
device_count = 0
@ -240,10 +240,10 @@ def main():
out_lines += CODE_POSTFIX
if vendor_count < MIN_VENDOR_COUNT:
exit_msg(f'Too view vendors. Wanted {MIN_VENDOR_COUNT}, got {vendor_count}.')
exit_msg(f'Too few vendors. Wanted {MIN_VENDOR_COUNT}, got {vendor_count}.')
if device_count < MIN_DEVICE_COUNT:
exit_msg(f'Too view devices. Wanted {MIN_DEVICE_COUNT}, got {device_count}.')
exit_msg(f'Too few devices. Wanted {MIN_DEVICE_COUNT}, got {device_count}.')
with open(OUTPUT_FILE, "w", encoding="utf-8") as pci_ids_f:
pci_ids_f.write(out_lines)