pkarashchenko commented on code in PR #6427: URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896984526
########## drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c: ########## @@ -328,24 +331,111 @@ int bcmf_upload_file(FAR struct bcmf_sdio_dev_s *sbus, uint32_t address, int bcmf_upload_nvram(FAR struct bcmf_sdio_dev_s *sbus) { - int ret; - uint32_t nvram_sz; + FAR uint8_t *nvram_buf = NULL; + uint32_t nvram_sz = 0; uint32_t token; + int ret; + +#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES + const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME; + unsigned char tmp[128]; + bool skipline = false; + struct file finfo; + struct stat stat; + FAR uint8_t *buf; + int i; + + if (strlen(nvfile) <= 0) + { + goto out_ramload; + } + + ret = file_open(&finfo, nvfile, O_RDONLY); + if (ret < 0) + { + goto out_ramload; + } + + ret = file_fstat(&finfo, &stat); + if (ret < 0 || stat.st_size <= 0) + { + goto out_ramload_with_file; + } + + /* Round up the ram buffer size */ + + stat.st_size = (stat.st_size + 63) & (-64); Review Comment: Should this work? ```suggestion stat.st_size = (stat.st_size + 63) & (~63); ``` ########## drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c: ########## @@ -328,24 +331,111 @@ int bcmf_upload_file(FAR struct bcmf_sdio_dev_s *sbus, uint32_t address, int bcmf_upload_nvram(FAR struct bcmf_sdio_dev_s *sbus) { - int ret; - uint32_t nvram_sz; + FAR uint8_t *nvram_buf = NULL; + uint32_t nvram_sz = 0; uint32_t token; + int ret; + +#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES + const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME; Review Comment: ```suggestion FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME; ``` ########## drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c: ########## @@ -328,24 +331,111 @@ int bcmf_upload_file(FAR struct bcmf_sdio_dev_s *sbus, uint32_t address, int bcmf_upload_nvram(FAR struct bcmf_sdio_dev_s *sbus) { - int ret; - uint32_t nvram_sz; + FAR uint8_t *nvram_buf = NULL; + uint32_t nvram_sz = 0; uint32_t token; + int ret; + +#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES + const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME; + unsigned char tmp[128]; + bool skipline = false; + struct file finfo; + struct stat stat; + FAR uint8_t *buf; + int i; + + if (strlen(nvfile) <= 0) + { + goto out_ramload; + } + + ret = file_open(&finfo, nvfile, O_RDONLY); + if (ret < 0) + { + goto out_ramload; + } + + ret = file_fstat(&finfo, &stat); + if (ret < 0 || stat.st_size <= 0) + { + goto out_ramload_with_file; + } + + /* Round up the ram buffer size */ + + stat.st_size = (stat.st_size + 63) & (-64); + + nvram_buf = buf = (FAR uint8_t *)kmm_malloc(stat.st_size); + if (nvram_buf == NULL) + { + goto out_ramload_with_file; + } + + /* Convert text pattern: + * 1. Remove the comment line (Prefix with '#') + * 2. Convert LF('\n') to NULL'\0' + */ + + while ((ret = file_read(&finfo, tmp, sizeof(tmp))) > 0) + { + for (i = 0; i < ret; i++) + { + if (tmp[i] == '\n') + { + if (buf != nvram_buf && *(buf - 1) != '\0') + { + *buf++ = '\0'; + } + + skipline = false; + } + else if (tmp[i] == '#') + { + skipline = true; + } + else if (!skipline) + { + *buf++ = tmp[i]; + } + } + } + + nvram_sz = buf - nvram_buf; + +out_ramload_with_file: + file_close(&finfo); +out_ramload: + if (nvram_sz == 0) +#endif + { + if (nvram_buf) + { + kmm_free(nvram_buf); + } + + nvram_buf = sbus->chip->nvram_image; + nvram_sz = *sbus->chip->nvram_image_size; + } /* Round up the size of the image */ - nvram_sz = (*sbus->chip->nvram_image_size + 63) & (-64); + nvram_sz = (nvram_sz + 63) & (-64); Review Comment: ditto -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org