diff mbox series

[v2,03/35] brcmfmac: firmware: Handle per-board clm_blob files

Message ID 20220104072658.69756-4-marcan@marcan.st
State New
Headers show
Series brcmfmac: Support Apple T2 and M1 platforms | expand

Commit Message

Hector Martin Jan. 4, 2022, 7:26 a.m. UTC
Teach brcm_alt_fw_paths to correctly split off variable length
extensions, and enable alt firmware lookups for the CLM blob firmware
requests.

Apple platforms have per-board CLM blob files.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hector Martin <marcan@marcan.st>
---
 .../broadcom/brcm80211/brcmfmac/firmware.c       | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Arend van Spriel Jan. 6, 2022, 10:19 a.m. UTC | #1
On 1/4/2022 8:26 AM, Hector Martin wrote:
> Teach brcm_alt_fw_paths to correctly split off variable length
> extensions, and enable alt firmware lookups for the CLM blob firmware
> requests.
> 
> Apple platforms have per-board CLM blob files.

Are you sure? I am not involved in development for Apple platforms, but 
in general we build a CLM blob specific for a chip revision. As always 
with the blobs they are created at a certain point in time and that is 
mostly why you need another one for a newer platform. Apple tends to do 
things a bit different so you could be right though. Anyway, despite my 
doubts on this it does not change the need for per-board firmware files.

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> ---
>   .../broadcom/brcm80211/brcmfmac/firmware.c       | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> index 0eb13e5df517..0497b721136a 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> @@ -595,16 +595,16 @@ static int brcmf_fw_complete_request(const struct firmware *fw,
>   static char *brcm_alt_fw_path(const char *path, const char *board_type)
>   {
>   	char alt_path[BRCMF_FW_NAME_LEN];
> -	char suffix[5];
> +	const char *suffix;
>   
> -	strscpy(alt_path, path, BRCMF_FW_NAME_LEN);
> -	/* At least one character + suffix */
> -	if (strlen(alt_path) < 5)
> +	suffix = strrchr(path, '.');
> +	if (!suffix || suffix == path)
>   		return NULL;
>   
> -	/* strip .txt or .bin at the end */
> -	strscpy(suffix, alt_path + strlen(alt_path) - 4, 5);
> -	alt_path[strlen(alt_path) - 4] = 0;
> +	/* strip extension at the end */
> +	strscpy(alt_path, path, BRCMF_FW_NAME_LEN);
> +	alt_path[suffix - path] = 0;
> +
>   	strlcat(alt_path, ".", BRCMF_FW_NAME_LEN);
>   	strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN);
>   	strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN);
> @@ -619,7 +619,7 @@ static int brcmf_fw_request_firmware(const struct firmware **fw,
>   	int ret;
>   
>   	/* Files can be board-specific, first try a board-specific path */
> -	if (cur->type == BRCMF_FW_TYPE_NVRAM && fwctx->req->board_type) {
> +	if (fwctx->req->board_type) {
>   		char *alt_path;
>   
>   		alt_path = brcm_alt_fw_path(cur->path, fwctx->req->board_type);

So all firmware files are attempted with board-specific path now.
Hector Martin Jan. 6, 2022, 10:59 a.m. UTC | #2
On 2022/01/06 19:19, Arend van Spriel wrote:
> On 1/4/2022 8:26 AM, Hector Martin wrote:
>> Teach brcm_alt_fw_paths to correctly split off variable length
>> extensions, and enable alt firmware lookups for the CLM blob firmware
>> requests.
>>
>> Apple platforms have per-board CLM blob files.
> 
> Are you sure? I am not involved in development for Apple platforms, but 
> in general we build a CLM blob specific for a chip revision. As always 
> with the blobs they are created at a certain point in time and that is 
> mostly why you need another one for a newer platform. Apple tends to do 
> things a bit different so you could be right though. Anyway, despite my 
> doubts on this it does not change the need for per-board firmware files.

Yup, I'm sure. The 2021 MacBook Pro 14" and the MacBook Pro 16", both
using BCM4387 and both released simultaneously, have different CLM
blobs; they're even a significantly different size. Running `strings` on
the files yields:

CLM DATA
Oly.Maldives
1.61.4
ClmImport: 1.63.1
v3 Final 210923

CLM DATA
Oly.Madagascar
1.61.4
ClmImport: 1.63.1
v4 Final 210923

The data shows significant differences and since the file format is
opaque I can't know what's going on. Even if it's safe to use one file
for both, unless there is some way for me to programmatically identify
this fact so I can incorporate that logic into my firmware copier, I
would much rather just keep them separate like Apple does.

> So all firmware files are attempted with board-specific path now.

Yes, I figured I'd keep things uniform. Technically for Apple platforms
the CLM blob and firmware are only per-board and possibly per-antenna
(they don't need the module variants, those are for nvram only), but
there's no real harm in unifying it and using the same firmware naming
alt path list for everything.
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
index 0eb13e5df517..0497b721136a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
@@ -595,16 +595,16 @@  static int brcmf_fw_complete_request(const struct firmware *fw,
 static char *brcm_alt_fw_path(const char *path, const char *board_type)
 {
 	char alt_path[BRCMF_FW_NAME_LEN];
-	char suffix[5];
+	const char *suffix;
 
-	strscpy(alt_path, path, BRCMF_FW_NAME_LEN);
-	/* At least one character + suffix */
-	if (strlen(alt_path) < 5)
+	suffix = strrchr(path, '.');
+	if (!suffix || suffix == path)
 		return NULL;
 
-	/* strip .txt or .bin at the end */
-	strscpy(suffix, alt_path + strlen(alt_path) - 4, 5);
-	alt_path[strlen(alt_path) - 4] = 0;
+	/* strip extension at the end */
+	strscpy(alt_path, path, BRCMF_FW_NAME_LEN);
+	alt_path[suffix - path] = 0;
+
 	strlcat(alt_path, ".", BRCMF_FW_NAME_LEN);
 	strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN);
 	strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN);
@@ -619,7 +619,7 @@  static int brcmf_fw_request_firmware(const struct firmware **fw,
 	int ret;
 
 	/* Files can be board-specific, first try a board-specific path */
-	if (cur->type == BRCMF_FW_TYPE_NVRAM && fwctx->req->board_type) {
+	if (fwctx->req->board_type) {
 		char *alt_path;
 
 		alt_path = brcm_alt_fw_path(cur->path, fwctx->req->board_type);