7#include "porting_assistant.h"
11#define PACKED __attribute__((packed))
17 FIELD_TYPE_MAGIC = 0x8000,
18 FIELD_TYPE_EOF = 0x8f00,
22#define MBIN_FW_MAGIC_NUMBER (0x57464d4d)
24#define MBIN_BCF_MAGIC_NUMBER (0x43424d4d)
49 memset(robuf, 0,
sizeof(*robuf));
53typedef void (*file_read_fn_t)(uint32_t offset, uint32_t requested_len,
struct mmhal_robuf *robuf);
55static enum test_result execute_fw_bcf_test(file_read_fn_t file_read_fn,
56 const char *file_read_fn_name,
58 uint32_t expected_magic_number,
65 for (num_tlvs = 0; num_tlvs < MAX_TLVS; num_tlvs++)
69 file_read_fn(offset,
sizeof(hdr), &robuf);
74 "%s invalid or ended too soon (EOF marker not found)\n"
75 "Check that you have provided a valid %s file and review your implementation\n"
80 return TEST_FAILED_NON_CRITICAL;
83 if (robuf.
buf == NULL)
85 TEST_LOG_APPEND(
"%s returned NULL buffer but non-zero length\n", file_read_fn_name);
86 TEST_LOG_APPEND(
"Review your implementation of %s().\n", file_read_fn_name);
87 return TEST_FAILED_NON_CRITICAL;
90 if (robuf.
len <
sizeof(hdr))
92 TEST_LOG_APPEND(
"The length of data returned by %s() was too short\n"
93 "%s() is required to return a minimum of "
94 "MMWLAN_FW_BCF_MIN_READ_LENGTH (%u) bytes.\n",
98 return TEST_FAILED_NON_CRITICAL;
103 robuf_cleanup(&robuf);
105 if (num_tlvs == 0 && hdr.type != FIELD_TYPE_MAGIC)
108 "The firware was corrupt (did not start with a magic number). \n"
109 "Possible causes include using invalid (e.g., outdated) firmware, or a bug in\n"
112 return TEST_FAILED_NON_CRITICAL;
115 if (hdr.type == FIELD_TYPE_EOF)
120 offset +=
sizeof(hdr);
123 uint32_t remaining_len = hdr.len;
124 while (remaining_len > 0)
126 file_read_fn(offset, remaining_len, &robuf);
129 TEST_LOG_APPEND(
"%s ended too soon.\n"
130 "Check that you have provided a valid firmware file and review "
131 "your implementation of\n%s().\n",
134 return TEST_FAILED_NON_CRITICAL;
137 if (robuf.
len > remaining_len)
139 TEST_LOG_APPEND(
"The length of data returned by %s() was too great\n"
140 "%s() should not return more than `requested_len` bytes.\n",
143 return TEST_FAILED_NON_CRITICAL;
148 if (robuf.
len <
sizeof(uint32_t))
150 TEST_LOG_APPEND(
"The length of data returned by %s() was too short\n"
151 "%s() is required to return a minimum of "
152 "MMWLAN_FW_BCF_MIN_READ_LENGTH %u) bytes\n",
156 return TEST_FAILED_NON_CRITICAL;
159 uint32_t magic = (robuf.
buf[0]) |
160 (robuf.
buf[1] << 8) |
161 (robuf.
buf[2] << 16) |
162 (robuf.
buf[3] << 24);
163 if (magic != expected_magic_number)
166 "The %s was corrupt (did not contain the correct magic number -- "
167 "expect 0x%08lx, got 0x%08lx).\n"
168 "This is likey caused by using an invalid (e.g., outdated) version.\n",
170 expected_magic_number,
172 return TEST_FAILED_NON_CRITICAL;
177 remaining_len -= robuf.
len;
178 robuf_cleanup(&robuf);
182 TEST_LOG_APPEND(
"%s invalid or ended too soon (EOF marker not found after %u TLVs).\n"
183 "Check that you have provided a valid %s file and review your implementation\n"
189 return TEST_FAILED_NON_CRITICAL;
195 "mmhal_wlan_read_fw_file",
205 "mmhal_wlan_read_bcf_file",
#define MBIN_FW_MAGIC_NUMBER
Expected value of the magic field for a firmware image MMFW.
#define PACKED
Macro for the compiler packed attribute.
#define MBIN_BCF_MAGIC_NUMBER
Expected value of the magic field for a BCF MMBC.
#define MMHAL_WLAN_FW_BCF_MIN_READ_LENGTH
Minimum length of data to be returned by mmhal_wlan_read_bcf_file() and mmhal_wlan_read_fw_file().
void mmhal_wlan_read_bcf_file(uint32_t offset, uint32_t requested_len, struct mmhal_robuf *robuf)
Retrieves the content of the Morse Micro Board Configuration File and places it into the given buffer...
void mmhal_wlan_read_fw_file(uint32_t offset, uint32_t requested_len, struct mmhal_robuf *robuf)
Retrieves the content of the Morse Micro Chip Firmware and places it into the given buffer.
const struct test_step test_step_mmhal_wlan_validate_bcf
Test definition.
const struct test_step test_step_mmhal_wlan_validate_fw
Test definition.
Read-only buffer data structure.
const uint8_t * buf
Pointer to the start of the read-only buffer.
uint32_t len
Length of the buffer contents.
void * free_arg
Optional argument to free_cb.
void(* free_cb)(void *arg)
Optional callback to be invoked by the consumer to release the buffer when it is no longer required.