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,
const char *type,
57 uint32_t expected_magic_number,
58 char *log_buf,
size_t log_buf_len)
63 for (num_tlvs = 0; num_tlvs < MAX_TLVS; num_tlvs++)
67 file_read_fn(offset,
sizeof(hdr), &robuf);
72 "%s invalid or ended too soon (EOF marker not found)\n"
73 "Check that you have provided a valid %s file and review your implementation\n"
74 "of %s().\n",
type,
type, file_read_fn_name);
75 return TEST_FAILED_NON_CRITICAL;
78 if (robuf.
buf == NULL)
80 TEST_LOG_APPEND(
"%s returned NULL buffer but non-zero length\n", file_read_fn_name);
81 TEST_LOG_APPEND(
"Review your implementation of %s().\n", file_read_fn_name);
82 return TEST_FAILED_NON_CRITICAL;
85 if (robuf.
len <
sizeof(hdr))
88 "The length of data returned by %s() was too short\n"
89 "%s() is required to return a minimum of "
90 "MMWLAN_FW_BCF_MIN_READ_LENGTH (%u) bytes.\n",
92 return TEST_FAILED_NON_CRITICAL;
97 robuf_cleanup(&robuf);
99 if (num_tlvs == 0 && hdr.type != FIELD_TYPE_MAGIC)
102 "The firware was corrupt (did not start with a magic number). \n"
103 "Possible causes include using invalid (e.g., outdated) firmware, or a bug in\n"
104 "%s()\n", file_read_fn_name);
105 return TEST_FAILED_NON_CRITICAL;
108 if (hdr.type == FIELD_TYPE_EOF)
113 offset +=
sizeof(hdr);
116 uint32_t remaining_len = hdr.len;
117 while (remaining_len > 0)
119 file_read_fn(offset, remaining_len, &robuf);
123 "%s ended too soon.\n"
124 "Check that you have provided a valid firmware file and review "
125 "your implementation of\n%s().\n",
type, file_read_fn_name);
126 return TEST_FAILED_NON_CRITICAL;
129 if (robuf.
len > remaining_len)
132 "The length of data returned by %s() was too great\n"
133 "%s() should not return more than `requested_len` bytes.\n",
134 file_read_fn_name, file_read_fn_name);
135 return TEST_FAILED_NON_CRITICAL;
140 if (robuf.
len <
sizeof(uint32_t))
143 "The length of data returned by %s() was too short\n"
144 "%s() is required to return a minimum of "
145 "MMWLAN_FW_BCF_MIN_READ_LENGTH %u) bytes\n",
147 return TEST_FAILED_NON_CRITICAL;
150 uint32_t magic = (robuf.
buf[0]) |
151 (robuf.
buf[1] << 8) |
152 (robuf.
buf[2] << 16) |
153 (robuf.
buf[3] << 24);
154 if (magic != expected_magic_number)
157 "The %s was corrupt (did not contain the correct magic number -- "
158 "expect 0x%08lx, got 0x%08lx).\n"
159 "This is likey caused by using an invalid (e.g., outdated) version.\n",
160 type, expected_magic_number, magic);
161 return TEST_FAILED_NON_CRITICAL;
166 remaining_len -= robuf.
len;
167 robuf_cleanup(&robuf);
172 "%s invalid or ended too soon (EOF marker not found after %u TLVs).\n"
173 "Check that you have provided a valid %s file and review your implementation\n"
174 "of %s().\n",
type, num_tlvs,
type, file_read_fn_name);
175 return TEST_FAILED_NON_CRITICAL;
#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.