You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/06/14 04:23:42 UTC

[GitHub] [incubator-nuttx] anchao opened a new pull request, #6427: wireless/bcm43xxx: load nvram from file system

anchao opened a new pull request, #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427

   ## Summary
   
   wireless/bcm43xxx: load nvram from file system
   
   added an option to load nvram from file system, which will help developers
   easily to tuning the firmware parameters without compile firmware.
   
   Signed-off-by: chao.an <an...@xiaomi.com>
   
   ## Impact
   
   N/A
   
   ## Testing
   
   bcm43013 nvram load


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896531681


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;

Review Comment:
   Done



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896539801


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);

Review Comment:
   allocated buffer need align to the 64 for upload binary request



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r897015976


##########
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
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char tmp[128];

Review Comment:
   tmp can be removed



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896534268


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r897562992


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,107 @@ 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 = sbus->chip->nvram_image;
+  uint32_t nvram_sz = *sbus->chip->nvram_image_size;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  bool skipline = false;
+  struct file finfo;
+  struct stat stat;
+  FAR uint8_t *buf;
+  int i;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  ret = file_fstat(&finfo, &stat);
+  if (ret < 0 || stat.st_size <= 0)
+    {
+      goto out;
+    }
+
+  /* Round up the ram buffer size */
+
+  stat.st_size = (stat.st_size + 63) & (-63);

Review Comment:
   Done



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,107 @@ 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 = sbus->chip->nvram_image;
+  uint32_t nvram_sz = *sbus->chip->nvram_image_size;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  bool skipline = false;
+  struct file finfo;
+  struct stat stat;
+  FAR uint8_t *buf;
+  int i;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  ret = file_fstat(&finfo, &stat);
+  if (ret < 0 || stat.st_size <= 0)
+    {
+      goto out;
+    }
+
+  /* Round up the ram buffer size */
+
+  stat.st_size = (stat.st_size + 63) & (-63);
+
+  buf = (FAR uint8_t *)kmm_malloc(stat.st_size);
+  if (buf == NULL)
+    {
+      goto out;
+    }
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  ret = file_read(&finfo, buf, stat.st_size);
+  if (ret <= 0)
+    {
+      kmm_free(buf);
+      goto out;
+    }
+
+  nvram_buf = buf;
+
+  for (i = 0; i < ret; i++)
+    {
+      if (nvram_buf[i] == '\n')
+        {
+          if (buf != nvram_buf && *(buf - 1) != '\0')
+            {
+              *buf++ = '\0';
+            }
+
+          skipline = false;
+        }
+      else if (nvram_buf[i] == '#')
+        {
+          skipline = true;
+        }
+      else if (!skipline && (nvram_buf + i) != buf)
+        {
+          *buf++ = nvram_buf[i];
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out:
+  file_close(&finfo);
+#endif
 
   /* Round up the size of the image */
 
-  nvram_sz = (*sbus->chip->nvram_image_size + 63) & (-64);
+  nvram_sz = (nvram_sz + 63) & (-63);

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r897208843


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,107 @@ 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 = sbus->chip->nvram_image;
+  uint32_t nvram_sz = *sbus->chip->nvram_image_size;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  bool skipline = false;
+  struct file finfo;
+  struct stat stat;
+  FAR uint8_t *buf;
+  int i;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  ret = file_fstat(&finfo, &stat);
+  if (ret < 0 || stat.st_size <= 0)
+    {
+      goto out;
+    }
+
+  /* Round up the ram buffer size */
+
+  stat.st_size = (stat.st_size + 63) & (-63);

Review Comment:
   ```suggestion
     stat.st_size = (stat.st_size + 63) & (~63);
   ```
   



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,107 @@ 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 = sbus->chip->nvram_image;
+  uint32_t nvram_sz = *sbus->chip->nvram_image_size;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  bool skipline = false;
+  struct file finfo;
+  struct stat stat;
+  FAR uint8_t *buf;
+  int i;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  ret = file_fstat(&finfo, &stat);
+  if (ret < 0 || stat.st_size <= 0)
+    {
+      goto out;
+    }
+
+  /* Round up the ram buffer size */
+
+  stat.st_size = (stat.st_size + 63) & (-63);
+
+  buf = (FAR uint8_t *)kmm_malloc(stat.st_size);
+  if (buf == NULL)
+    {
+      goto out;
+    }
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  ret = file_read(&finfo, buf, stat.st_size);
+  if (ret <= 0)
+    {
+      kmm_free(buf);
+      goto out;
+    }
+
+  nvram_buf = buf;
+
+  for (i = 0; i < ret; i++)
+    {
+      if (nvram_buf[i] == '\n')
+        {
+          if (buf != nvram_buf && *(buf - 1) != '\0')
+            {
+              *buf++ = '\0';
+            }
+
+          skipline = false;
+        }
+      else if (nvram_buf[i] == '#')
+        {
+          skipline = true;
+        }
+      else if (!skipline && (nvram_buf + i) != buf)
+        {
+          *buf++ = nvram_buf[i];
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out:
+  file_close(&finfo);
+#endif
 
   /* Round up the size of the image */
 
-  nvram_sz = (*sbus->chip->nvram_image_size + 63) & (-64);
+  nvram_sz = (nvram_sz + 63) & (-63);

Review Comment:
   ```suggestion
     nvram_sz = (nvram_sz + 63) & (~63);
   ```
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896469823


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;

Review Comment:
   merge into line 334-335



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;

Review Comment:
   sbuf->stat



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)

Review Comment:
   remove



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;

Review Comment:
   finfo->file



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;

Review Comment:
   merge into line 345



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else

Review Comment:
   else if (!bskipline)



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];

Review Comment:
   swap[32] to
   tmp[256]



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else
+            {
+              *buf++ = swap[i];
+            }
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out_ramload_with_file:
+  file_close(&finfo);
+out_ramload:
+  if (nvram_buf == NULL || nvram_sz == 0)

Review Comment:
   remove nvram_buf == NULL



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else
+            {
+              *buf++ = swap[i];
+            }
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out_ramload_with_file:
+  file_close(&finfo);
+out_ramload:
+  if (nvram_buf == NULL || nvram_sz == 0)
+#endif
+    {
+      nvram_buf = sbus->chip->nvram_image;

Review Comment:
   free nvram_buf before the assignment



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);

Review Comment:
   why change  sbuf.st_size



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;

Review Comment:
   skipline



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896539021


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else
+            {
+              *buf++ = swap[i];
+            }
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out_ramload_with_file:
+  file_close(&finfo);
+out_ramload:
+  if (nvram_buf == NULL || nvram_sz == 0)

Review Comment:
   Done



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)
+            {
+            }
+          else if (swap[i] == '#')
+            {
+              bskipline = true;
+            }
+          else
+            {
+              *buf++ = swap[i];
+            }
+        }
+    }
+
+  nvram_sz = buf - nvram_buf;
+
+out_ramload_with_file:
+  file_close(&finfo);
+out_ramload:
+  if (nvram_buf == NULL || nvram_sz == 0)
+#endif
+    {
+      nvram_buf = sbus->chip->nvram_image;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896992246


##########
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:
   Done



##########
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:
   Done



##########
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:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896540264


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;

Review Comment:
   Done



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;
+  int i;
+
+  nvram_buf = NULL;
+  nvram_sz = 0;
+
+  if (strlen(nvfile) <= 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_open(&finfo, nvfile, O_RDONLY);
+  if (ret < 0)
+    {
+      goto out_ramload;
+    }
+
+  ret = file_fstat(&finfo, &sbuf);
+  if (ret < 0 || sbuf.st_size <= 0)
+    {
+      goto out_ramload_with_file;
+    }
+
+  /* Round up the ram buffer size */
+
+  sbuf.st_size = (sbuf.st_size + 63) & (-64);
+
+  nvram_buf = buf = (FAR uint8_t *)kmm_malloc(sbuf.st_size);
+  if (nvram_buf == NULL)
+    {
+      goto out_ramload_with_file;
+    }
+
+  bskipline = false;
+
+  /* Convert text pattern:
+   *  1. Remove the comment line (Prefix with '#')
+   *  2. Convert LF('\n') to NULL'\0'
+   */
+
+  while ((ret = file_read(&finfo, swap, sizeof(swap))) > 0)
+    {
+      for (i = 0; i < ret; i++)
+        {
+          if (swap[i] == '\n')
+            {
+              if (buf != nvram_buf && *(buf - 1) != '\0')
+                {
+                  *buf++ = '\0';
+                }
+
+              bskipline = false;
+            }
+          else if (bskipline)

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896536326


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;

Review Comment:
   style same with bcmf_upload_file
   
   ```
   int bcmf_upload_file(FAR struct bcmf_sdio_dev_s *sbus, uint32_t address,
                        FAR const char *path)
   {
     struct file finfo;
   ```
   



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896535318


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r897017423


##########
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
+  FAR const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char tmp[128];

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6427: wireless/bcm43xxx: load nvram from file system

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #6427:
URL: https://github.com/apache/incubator-nuttx/pull/6427#discussion_r896532186


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c:
##########
@@ -328,24 +331,114 @@ 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;
+  FAR uint8_t *nvram_buf;
   uint32_t nvram_sz;
   uint32_t token;
+  int ret;
+
+#ifdef CONFIG_IEEE80211_BROADCOM_FWFILES
+  const char *nvfile = CONFIG_IEEE80211_BROADCOM_NVFILENAME;
+  unsigned char swap[32];
+  struct file finfo;
+  struct stat sbuf;
+  FAR uint8_t *buf;
+  bool bskipline;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org