diff options
Diffstat (limited to 'utils/nwztools/plattools/dest_tool.c')
-rw-r--r-- | utils/nwztools/plattools/dest_tool.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/utils/nwztools/plattools/dest_tool.c b/utils/nwztools/plattools/dest_tool.c index 7b6c0a4ff6..d137239f7f 100644 --- a/utils/nwztools/plattools/dest_tool.c +++ b/utils/nwztools/plattools/dest_tool.c | |||
@@ -21,10 +21,11 @@ | |||
21 | #include "nwz_lib.h" | 21 | #include "nwz_lib.h" |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include "nwz_plattools.h" | ||
24 | 25 | ||
25 | extern char **environ; | 26 | extern char **environ; |
26 | 27 | ||
27 | const char *white_list[] = | 28 | static const char *white_list[] = |
28 | { | 29 | { |
29 | "NWZ-E463", "NWZ-E464", "NWZ-E465", | 30 | "NWZ-E463", "NWZ-E464", "NWZ-E465", |
30 | "NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867", | 31 | "NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867", |
@@ -32,7 +33,7 @@ const char *white_list[] = | |||
32 | }; | 33 | }; |
33 | 34 | ||
34 | /* get model id from ICX_MODEL_ID environment variable */ | 35 | /* get model id from ICX_MODEL_ID environment variable */ |
35 | unsigned long find_model_id(void) | 36 | static unsigned long find_model_id(void) |
36 | { | 37 | { |
37 | const char *mid = getenv("ICX_MODEL_ID"); | 38 | const char *mid = getenv("ICX_MODEL_ID"); |
38 | if(mid == NULL) | 39 | if(mid == NULL) |
@@ -45,12 +46,12 @@ unsigned long find_model_id(void) | |||
45 | return v; | 46 | return v; |
46 | } | 47 | } |
47 | 48 | ||
48 | unsigned long read32(unsigned char *buf) | 49 | static unsigned long read32(unsigned char *buf) |
49 | { | 50 | { |
50 | return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; | 51 | return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; |
51 | } | 52 | } |
52 | 53 | ||
53 | void write32(unsigned char *buf, unsigned long value) | 54 | static void write32(unsigned char *buf, unsigned long value) |
54 | { | 55 | { |
55 | buf[0] = value & 0xff; | 56 | buf[0] = value & 0xff; |
56 | buf[1] = (value >> 8) & 0xff; | 57 | buf[1] = (value >> 8) & 0xff; |
@@ -58,7 +59,7 @@ void write32(unsigned char *buf, unsigned long value) | |||
58 | buf[3] = (value >> 24) & 0xff; | 59 | buf[3] = (value >> 24) & 0xff; |
59 | } | 60 | } |
60 | 61 | ||
61 | struct | 62 | static struct |
62 | { | 63 | { |
63 | unsigned long dest; | 64 | unsigned long dest; |
64 | const char *name; | 65 | const char *name; |
@@ -84,7 +85,7 @@ struct | |||
84 | 85 | ||
85 | #define NR_DEST (sizeof(g_dest_list) / sizeof(g_dest_list[0])) | 86 | #define NR_DEST (sizeof(g_dest_list) / sizeof(g_dest_list[0])) |
86 | 87 | ||
87 | int get_dest_index(unsigned long dest) | 88 | static int get_dest_index(unsigned long dest) |
88 | { | 89 | { |
89 | for(size_t i = 0; i < NR_DEST; i++) | 90 | for(size_t i = 0; i < NR_DEST; i++) |
90 | if(g_dest_list[i].dest == dest) | 91 | if(g_dest_list[i].dest == dest) |
@@ -92,16 +93,16 @@ int get_dest_index(unsigned long dest) | |||
92 | return -1; | 93 | return -1; |
93 | } | 94 | } |
94 | 95 | ||
95 | const char *get_dest_name(unsigned long dest) | 96 | static const char *get_dest_name(unsigned long dest) |
96 | { | 97 | { |
97 | int index = get_dest_index(dest); | 98 | int index = get_dest_index(dest); |
98 | return index < 0 ? "NG" : g_dest_list[index].name; | 99 | return index < 0 ? "NG" : g_dest_list[index].name; |
99 | } | 100 | } |
100 | 101 | ||
101 | int main(int argc, char **argv) | 102 | int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv) |
102 | { | 103 | { |
103 | /* clear screen and display welcome message */ | 104 | /* clear screen and display welcome message */ |
104 | nwz_lcdmsg(true, 0, 0, "destination tool"); | 105 | nwz_lcdmsg(true, 0, 0, "dest_tool"); |
105 | /* open input device */ | 106 | /* open input device */ |
106 | int input_fd = nwz_key_open(); | 107 | int input_fd = nwz_key_open(); |
107 | if(input_fd < 0) | 108 | if(input_fd < 0) |
@@ -113,6 +114,7 @@ int main(int argc, char **argv) | |||
113 | unsigned long model_id = find_model_id(); | 114 | unsigned long model_id = find_model_id(); |
114 | if(model_id == 0) | 115 | if(model_id == 0) |
115 | { | 116 | { |
117 | nwz_key_close(input_fd); | ||
116 | nwz_lcdmsg(false, 3, 4, "Cannot get model ID"); | 118 | nwz_lcdmsg(false, 3, 4, "Cannot get model ID"); |
117 | sleep(2); | 119 | sleep(2); |
118 | return 1; | 120 | return 1; |
@@ -214,5 +216,6 @@ int main(int argc, char **argv) | |||
214 | } | 216 | } |
215 | } | 217 | } |
216 | /* finish nicely */ | 218 | /* finish nicely */ |
219 | nwz_key_close(input_fd); | ||
217 | return 0; | 220 | return 0; |
218 | } | 221 | } |