Skip to content

Commit 78f1b16

Browse files
committed
Review feedback
Add copyright headers Put ptinfo buffer on the stack, and break when partition is found Improve function description
1 parent d690e3e commit 78f1b16

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/rp2_common/pico_cyw43_driver/cyw43_driver.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ static void cyw43_sleep_timeout_reached(async_context_t *context, __unused async
121121

122122
bool cyw43_driver_init(async_context_t *context) {
123123
#if CYW43_USE_PARTITION_FIRMWARE
124-
const int buf_words = (16 * 4) + 1; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1
125-
uint32_t* buffer = malloc(buf_words * 4);
126-
int ret = rom_get_partition_table_info(buffer, buf_words, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID);
124+
uint32_t buffer[(16 * 4) + 1] = {}; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1
125+
int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID);
127126

128127
assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID));
129128

@@ -141,6 +140,7 @@ bool cyw43_driver_init(async_context_t *context) {
141140
id |= ((uint64_t)(buffer[i++]) << 32ull);
142141
if (id == CYW43_WIFI_FW_PARTITION_ID) {
143142
picked_p = p;
143+
break;
144144
}
145145
}
146146

@@ -162,7 +162,7 @@ bool cyw43_driver_init(async_context_t *context) {
162162
}
163163

164164
CYW43_DEBUG("Chosen CYW43 firmware in partition %d\n", picked_p);
165-
int ret = rom_get_partition_table_info(buffer, buf_words, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24));
165+
int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24));
166166
assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION));
167167
assert(ret == 3);
168168

@@ -179,9 +179,7 @@ bool cyw43_driver_init(async_context_t *context) {
179179
cyw43_clm_len = *(uint32_t*)(XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 4);
180180
fw_data = XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 8;
181181
}
182-
free(buffer);
183182
} else {
184-
free(buffer);
185183
CYW43_DEBUG("No partition table, so cannot get firmware from partition - get_partition_table_info returned %d\n", ret);
186184
return false;
187185
}

src/rp2_common/pico_cyw43_driver/cyw43_firmware.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
17
import sys
28

39
with open(sys.argv[1], "r") as f:

src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
16

27
extern int cyw43_wifi_fw_len;
38
extern int cyw43_clm_len;

src/rp2_common/pico_cyw43_driver/wifi_firmware.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include "boot/picobin.h"
28

39
#if PICO_CRT0_IMAGE_TYPE_TBYB

0 commit comments

Comments
 (0)