tools/hciattach_ath3k: Load BT board data based on country code
authorSonny Sasaka <sonnysasaka@chromium.org>
Tue, 31 Mar 2020 00:33:55 +0000 (17:33 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:48 +0000 (14:30 +0530)
BT board data file PS_ASIC-<country-code>.pst is loaded based
on country code. If not exist, default BT board data file
PS_ASIC.pst would be loaded.

This patch doesn't define how to get the country code at the moment, but
future patches can supply the country code in the region parameter of
get_ps_file_name.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/hciattach_ath3k.c

index a76b448..89c12ec 100755 (executable)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <time.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/param.h>
@@ -572,20 +573,33 @@ static int ps_config_download(int fd, int tag_count)
        return 0;
 }
 
-#define PS_ASIC_FILE                   "PS_ASIC.pst"
-#define PS_FPGA_FILE                   "PS_FPGA.pst"
+#define PS_ASIC_FILE_PREFIX            "PS_ASIC"
+#define PS_FPGA_FILE_PREFIX            "PS_FPGA"
 
-static void get_ps_file_name(uint32_t devtype, uint32_t rom_version,
-                                                       char *path)
+static void get_ps_file_name(uint32_t devtype, uint32_t rom_version, char *path,
+                                                               char *region)
 {
-       char *filename;
+       char *file_prefix;
+       struct stat st;
 
        if (devtype == 0xdeadc0de)
-               filename = PS_ASIC_FILE;
+               file_prefix = PS_ASIC_FILE_PREFIX;
        else
-               filename = PS_FPGA_FILE;
+               file_prefix = PS_FPGA_FILE_PREFIX;
 
-       snprintf(path, MAXPATHLEN, "%s%x/%s", FW_PATH, rom_version, filename);
+       if (!region)
+               goto default_ps_file;
+
+       snprintf(path, MAXPATHLEN, "%s%x/%s-%s.pst", FW_PATH, rom_version,
+                       file_prefix, region);
+       if (stat(path, &st) == 0)
+               return;
+
+       perror("PS file with region code not exist, use default PS file\n");
+
+default_ps_file:
+       snprintf(path, MAXPATHLEN, "%s%x/%s.pst", FW_PATH, rom_version,
+                       file_prefix);
 }
 
 #define PATCH_FILE        "RamPatch.txt"
@@ -822,7 +836,7 @@ static int ath_ps_download(int fd)
                goto download_cmplete;
        }
 
-       get_ps_file_name(dev_type, rom_version, ps_file);
+       get_ps_file_name(dev_type, rom_version, ps_file, NULL);
        get_patch_file_name(dev_type, rom_version, build_version, patch_file);
 
        stream = fopen(ps_file, "r");