Просмотр исходного кода

[btstack/file] add file name check and length get

li.tao 9 месяцев назад
Родитель
Сommit
f276cb1ea7
1 измененных файлов с 12 добавлено и 1 удалено
  1. 12 1
      chipset/bcm/btstack_chipset_bcm.c

+ 12 - 1
chipset/bcm/btstack_chipset_bcm.c

@@ -134,7 +134,7 @@ static const uint8_t download_command[] = {0x2e, 0xfc, 0x00};
 static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
     static int hcd_file_length;
     if (hcd_fd < 0){
-        const struct fal_partition *hcd_part = fal_partition_find("bt_image");
+        
         log_info("chipset-bcm: hcd_file_path open file %s", hcd_file_path);
         hcd_fd = open(hcd_file_path, O_RDONLY);
         if (hcd_fd < 0){
@@ -142,7 +142,18 @@ static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
             return BTSTACK_CHIPSET_NO_INIT_SCRIPT;
         }
 #ifdef ART_PI_USING_OTA_LIB
+        const struct fal_partition *hcd_part = fal_partition_find("bt_image");
         hcd_file_length = rt_ota_get_raw_fw_size(hcd_part);
+#else
+				struct stat file_stat;
+				if (fstat(hcd_fd, &file_stat) < 0) {
+						log_error("chipset-bcm: can't get file size for %s", hcd_file_path);
+						close(hcd_fd);
+						return BTSTACK_CHIPSET_NO_INIT_SCRIPT;
+				}
+
+				hcd_file_length = file_stat.st_size; 
+				log_info("\r\n patch file len :%d", hcd_file_length);
 #endif
         if(hcd_file_path <= 0){
              return BTSTACK_CHIPSET_NO_INIT_SCRIPT;