Debian Codegraph @

src/scarlett4-firmware.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2023-2025 Geoffrey D. Bennett <[email protected]>
2 // SPDX-License-Identifier: GPL-3.0-or-later
3
4 #pragma once
5
6 #include <stdint.h>
7
8 #include "alsa.h"
9
10 // Firmware directory for big Gen 4 devices
11 #define SCARLETT4_FIRMWARE_DIR "/usr/lib/firmware/scarlett4"
12
13 enum scarlett4_firmware_type {
14 SCARLETT4_FIRMWARE_CONTAINER,
15 SCARLETT4_FIRMWARE_APP,
16 SCARLETT4_FIRMWARE_ESP,
17 SCARLETT4_FIRMWARE_LEAPFROG,
18 SCARLETT4_FIRMWARE_TYPE_COUNT
19 };
20
21 extern const char *scarlett4_firmware_type_magic[SCARLETT4_FIRMWARE_TYPE_COUNT];
22
23 /* On-disk format of the firmware container header and the firmware
24 * header. These are preceded by the 8-byte magic string identifying
25 * the type of the following header.
26 */
27 struct scarlett4_firmware_container_header_disk {
28 uint16_t usb_vid; // Big-endian
29 uint16_t usb_pid; // Big-endian
30 uint32_t firmware_version[4]; // Big-endian
31 uint32_t num_sections; // Big-endian
32 } __attribute__((packed));
33
34 struct scarlett4_firmware_header_disk {
35 uint16_t usb_vid; // Big-endian
36 uint16_t usb_pid; // Big-endian
37 uint32_t firmware_version[4]; // Big-endian
38 uint32_t firmware_length; // Big-endian
39 uint8_t sha256[32];
40 } __attribute__((packed));
41
42 /* In-memory representation of the firmware */
43 struct scarlett4_firmware {
44 enum scarlett4_firmware_type type;
45 uint16_t usb_vid;
46 uint16_t usb_pid;
47 uint32_t firmware_version[4];
48 uint32_t firmware_length;
49 uint8_t sha256[32];
50 uint8_t md5[16];
51 uint8_t *firmware_data;
52 };
53
54 /* In-memory representation of the firmware container */
55 struct scarlett4_firmware_container {
56 uint16_t usb_vid;
57 uint16_t usb_pid;
58 uint32_t firmware_version[4];
59 uint32_t num_sections;
60 struct scarlett4_firmware **sections;
61 };
62
63 /* Read just the firmware container header from a file */
64 struct scarlett4_firmware_container *scarlett4_read_firmware_header(const char *fn);
65
66 /* Read all sections of a firmware container from a file */
67 struct scarlett4_firmware_container *scarlett4_read_firmware_file(const char *fn);
68
69 void scarlett4_free_firmware_container(struct scarlett4_firmware_container *container);
70
71 const char *scarlett4_firmware_type_to_string(enum scarlett4_firmware_type type);
72
73 /* Enumerate firmware files in the firmware directory */
74 void scarlett4_enum_firmware(void);
75
76 /* Get the best firmware version for a device (4-valued), or NULL if none */
77 uint32_t *scarlett4_get_best_firmware_version(uint32_t pid);
78
79 /* Get the best firmware container for a device, or NULL if none */
80 struct scarlett4_firmware_container *scarlett4_get_best_firmware(uint32_t pid);
81
82 /* Check if device is in mid-upgrade state (leapfrog loaded, ESP needs update)
83 * Returns 1 if mid-upgrade, 0 otherwise */
84 int scarlett4_is_mid_upgrade(struct alsa_card *card);