Skip to content

Commit 4fbd41e

Browse files
authored
Merge pull request #23 from tmobile/CFSPDK-859-add-configuration-options-dfu
TMO_SHELL: DFU: Allow user entered file names
2 parents 0bc668c + aa52134 commit 4fbd41e

File tree

6 files changed

+120
-45
lines changed

6 files changed

+120
-45
lines changed

samples/tmo_shell/src/dfu_gecko.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ const struct dfu_file_t dfu_files_mcu[] = {
2727
{
2828
"Gecko MCU 1/4",
2929
"/tmo/zephyr.slot0.bin",
30-
"tmo_shell.tmo_dev_edge.slot0.v1.15.0.bin",
30+
"tmo_shell.tmo_dev_edge.slot0.bin",
3131
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
3232
},
3333
{
3434
"Gecko MCU 2/4",
3535
"/tmo/zephyr.slot1.bin",
36-
"tmo_shell.tmo_dev_edge.slot1.v1.15.0.bin",
36+
"tmo_shell.tmo_dev_edge.slot1.bin",
3737
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
3838
},
3939
{
4040
"Gecko MCU 3/4",
4141
"/tmo/zephyr.slot0.bin.sha1",
42-
"tmo_shell.tmo_dev_edge.slot0.v1.15.0.bin.sha1",
42+
"tmo_shell.tmo_dev_edge.slot0.bin.sha1",
4343
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
4444
},
4545
{
4646
"Gecko MCU 4/4",
4747
"/tmo/zephyr.slot1.bin.sha1",
48-
"tmo_shell.tmo_dev_edge.slot1.v1.15.0.bin.sha1",
48+
"tmo_shell.tmo_dev_edge.slot1.bin.sha1",
4949
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
5050
},
5151

samples/tmo_shell/src/dfu_murata_1sc.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,20 @@
3232
* between two "sample" images. The last two below are for testing
3333
* between "golden" images.
3434
*/
35-
const struct dfu_file_t dfu_files_modem[] = {
35+
struct dfu_file_t dfu_files_modem[] = {
3636
{
3737
"Murata 1SC: 20351 to 20161 Sample",
3838
"/tmo/update1.ua",
39-
"update3.2.20351_20161_dis.ua",
39+
"",
4040
// sha1sum for update3.2.20351_20161_dis.ua - a56cac18f64452aa166b1c20ac7db9a7a96a7eb0
4141
{ 0xa5, 0x6c, 0xac, 0x18, 0xf6, 0x44, 0x52, 0xaa, 0x16, 0x6b, 0x1c, 0x20, 0xac, 0x7d, 0xb9, 0xa7, 0xa9, 0x6a, 0x7e, 0xb0 }
4242
},
4343
{
44-
"Murata 1SC: 20161 to 20351 Sample",
45-
"/tmo/update2.ua",
46-
"update3.2.20161_20351_dis.ua",
47-
// sha1sum for update3.2.20161_20351_dis.ua - 11aea75585fb8f259916b87a5474bdb86e2a6636
48-
{ 0x11, 0xae, 0xa7, 0x55, 0x85, 0xfb, 0x8f, 0x25, 0x99, 0x16, 0xb8, 0x7a, 0x54, 0x74, 0xbd, 0xb8, 0x6e, 0x2a, 0x66, 0x36 }
49-
},
50-
{
51-
"Murata 1SC: 20351 to 20161 Golden",
52-
"/tmo/update3.ua",
53-
"update20351_20161_801_test.ua",
54-
// sha1sum for update20351_20161_801.ua - 4c8b2f798b2c7047a83569565cf8dfddabc8b562
55-
{ 0x4c, 0x8b, 0x2f, 0x79, 0x8b, 0x2c, 0x70, 0x47, 0xa8, 0x35, 0x69, 0x56, 0x5c, 0xf8, 0xdf, 0xdd, 0xab, 0xc8, 0xb5, 0x62 }
56-
},
57-
{
58-
"Murata 1SC: 20161 to 20351 Golden",
59-
"/tmo/update4.ua",
60-
"update20161_20351_801_test.ua",
61-
// sha1sum for update20161_20351_801.ua - 490fb943f24c86fa55f8b989f2ee41ab7cae0411
62-
{ 0x49, 0x0f, 0xb9, 0x43, 0xf2, 0x4c, 0x86, 0xfa, 0x55, 0xf8, 0xb9, 0x89, 0xf2, 0xee, 0x41, 0xab, 0x7c, 0xae, 0x04, 0x11 }
44+
"Murata 1SC: 20351 to 20161 Sample - SHA1" ,
45+
"/tmo/update1.ua.sha1",
46+
"",
47+
// sha1sum for update3.2.20351_20161_dis.ua - a56cac18f64452aa166b1c20ac7db9a7a96a7eb0
48+
{ 0xa5, 0x6c, 0xac, 0x18, 0xf6, 0x44, 0x52, 0xaa, 0x16, 0x6b, 0x1c, 0x20, 0xac, 0x7d, 0xb9, 0xa7, 0xa9, 0x6a, 0x7e, 0xb0 }
6349
},
6450
{"","","",""}
6551
};

samples/tmo_shell/src/dfu_rs9116w.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@
2121
#include "dfu_rs9116w.h"
2222
#include "tmo_dfu_download.h"
2323

24-
const struct dfu_file_t dfu_files_rs9116w[] = {
24+
struct dfu_file_t dfu_files_rs9116w[] = {
2525
{
2626
"SiLabs RS9116W",
2727
"/tmo/rs9116_file.rps",
2828
// "RS9116W.2.4.0.36.rps",
2929
// { 0x81, 0x7d, 0x22, 0x14, 0x2b, 0xcb, 0x03, 0x84, 0x29, 0x5d, 0x4f, 0xb6, 0x95, 0x3d, 0xb9, 0x2e, 0xa7, 0xbd, 0xd6, 0xb6 }
3030
// "RS9116W.2.5.2.0.4.rps",
3131
// { 0x4b, 0xb8, 0xf8, 0x48, 0x04, 0x36, 0xa5, 0xa8, 0xed, 0x66, 0x50, 0x30, 0x87, 0xfe, 0xe5, 0xef, 0x99, 0x0d, 0x81, 0xa2 }
32-
"RS9116W.2.6.0.0.34.rps",
32+
"",
33+
{ 0xfb, 0x3b, 0xc5, 0x71, 0xe5, 0xa3, 0x9a, 0xc6, 0x14, 0x5e, 0xda, 0x90, 0xd3, 0xc0, 0xff, 0xf9, 0x5b, 0x06, 0x9c, 0xe8 }
34+
},
35+
{
36+
"SiLabs RS9116W - SHA1",
37+
"/tmo/rs9116_file.rps.sha1",
38+
"",
3339
{ 0xfb, 0x3b, 0xc5, 0x71, 0xe5, 0xa3, 0x9a, 0xc6, 0x14, 0x5e, 0xda, 0x90, 0xd3, 0xc0, 0xff, 0xf9, 0x5b, 0x06, 0x9c, 0xe8 }
3440
},
3541
{"","","",""}

samples/tmo_shell/src/tmo_dfu_download.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ static char base_url_s[MAX_BASE_URL_LEN] = "https://devkit.devedge.t-mobile.com/
4141

4242
static int iface_s = WIFI_ID; // Default iface is wifi
4343

44-
int dfu_download(const struct dfu_file_t *dfu_file)
44+
char *dfu_target_str(enum dfu_tgts dfu_tgt) {
45+
switch(dfu_tgt) {
46+
case DFU_GECKO: return "MCU";
47+
case DFU_MODEM: return "Modem";
48+
default:
49+
return "WiFi";
50+
}
51+
}
52+
53+
int dfu_download(const struct dfu_file_t *dfu_file, enum dfu_tgts dfu_tgt)
4554
{
4655
int ret;
4756
unsigned char sha1_output[20];
@@ -52,7 +61,7 @@ int dfu_download(const struct dfu_file_t *dfu_file)
5261
printf("URL was truncated\n");
5362
}
5463

55-
printf("\nDownloading firmware for %s\n", dfu_file->desc);
64+
printf("\nDownloading %s firmware %s\n", dfu_target_str(dfu_tgt), dfu_file->desc);
5665
printf("from url: %s\n", url);
5766
printf("to file : %s\n", dfu_file->lfile);
5867

@@ -140,21 +149,53 @@ int dfu_download(const struct dfu_file_t *dfu_file)
140149
return totalbytes;
141150
}
142151

143-
int tmo_dfu_download(enum dfu_tgts dfu_tgt)
152+
void generate_mcu_filename(struct dfu_file_t *dfu_files_mcu, char *base, char *version, int slots) {
153+
for (int i = 0; i < slots; i++) {
154+
/* BIN */
155+
sprintf(dfu_files_mcu[i].desc, "%s %d/%d", base ,i+1, slots*2);
156+
sprintf(dfu_files_mcu[i].lfile, "/tmo/zephyr.slot%d.bin", i);
157+
sprintf(dfu_files_mcu[i].rfile, "%s.slot%d.%s.bin",base, i, version);
158+
memset(dfu_files_mcu[i].sha1, 0, DFU_SHA1_LEN);
159+
160+
/* SHA1 */
161+
sprintf(dfu_files_mcu[i+slots].desc, "%s %d/%d", base, i + (1+slots), slots*2);
162+
sprintf(dfu_files_mcu[i+slots].lfile, "%s.sha1", dfu_files_mcu[i].lfile);
163+
sprintf(dfu_files_mcu[i+slots].rfile, "%s.sha1",dfu_files_mcu[i].rfile);
164+
memset(dfu_files_mcu[i+slots].sha1, 0, DFU_SHA1_LEN);
165+
}
166+
}
167+
168+
int tmo_dfu_download(const struct shell *shell, enum dfu_tgts dfu_tgt, char *base, char *version)
144169
{
145170
mbedtls_sha1_init(&sha1_ctx);
146171
const struct dfu_file_t *dfu_files = NULL;
172+
struct dfu_file_t dfu_files_mcu_gen[5];
173+
174+
memset(dfu_files_mcu_gen,0,sizeof(struct dfu_file_t) * 5);
147175

148176
switch (dfu_tgt) {
149177
case DFU_GECKO:
150-
dfu_files = dfu_files_mcu;
178+
if (base == NULL)
179+
dfu_files = dfu_files_mcu;
180+
else {
181+
generate_mcu_filename(dfu_files_mcu_gen,base,version,2);
182+
dfu_files = dfu_files_mcu_gen;
183+
}
151184
break;
152185

153186
case DFU_MODEM:
187+
sprintf((char *)dfu_files_modem[0].desc, "%s 1/2",base);
188+
sprintf((char *)dfu_files_modem[0].rfile, "%s.ua",base);
189+
sprintf((char *)dfu_files_modem[1].desc, "%s 2/2 ",base);
190+
sprintf((char *)dfu_files_modem[1].rfile, "%s.sha1",dfu_files_modem[0].rfile);
154191
dfu_files = dfu_files_modem;
155192
break;
156193

157194
case DFU_9116W:
195+
sprintf((char *)dfu_files_rs9116w[0].desc, "%s 1/2",base);
196+
sprintf((char *)dfu_files_rs9116w[0].rfile, "%s.rps",base);
197+
sprintf((char *)dfu_files_rs9116w[1].desc, "%s 2/2",base);
198+
sprintf((char *)dfu_files_rs9116w[1].rfile, "%s.sha1",dfu_files_rs9116w[0].rfile);
158199
dfu_files = dfu_files_rs9116w;
159200
break;
160201

@@ -170,7 +211,7 @@ int tmo_dfu_download(enum dfu_tgts dfu_tgt)
170211
int total = 0;
171212
int idx = 0;
172213
while (strlen(dfu_files[idx].desc)) {
173-
total += dfu_download(&dfu_files[idx++]);
214+
total += dfu_download(&dfu_files[idx++], dfu_tgt);
174215
}
175216
printf("\nTotal size downloaded: %d\n", total);
176217
printf("Done!\n");

samples/tmo_shell/src/tmo_dfu_download.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "dfu_murata_1sc.h"
1111
#include "dfu_rs9116w.h"
1212
#include "dfu_gecko.h"
13+
#include "tmo_shell.h"
14+
#include <shell/shell.h>
1315

1416
enum dfu_tgts {
1517
DFU_GECKO = 0,
@@ -29,10 +31,10 @@ struct dfu_file_t {
2931
char sha1[DFU_SHA1_LEN];
3032
};
3133

32-
int tmo_dfu_download(enum dfu_tgts dfu_tgt);
34+
int tmo_dfu_download(const struct shell *shell, enum dfu_tgts dfu_tgt, char *filename, char *version);
3335
int set_dfu_base_url(char *base_url);
3436
const char *get_dfu_base_url(void);
3537
int set_dfu_iface_type(int iface);
3638
int get_dfu_iface_type(void);
3739

38-
#endif
40+
#endif

samples/tmo_shell/src/tmo_shell.c

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,11 +1704,33 @@ int cmd_dfu_download(const struct shell *shell, size_t argc, char **argv)
17041704
{
17051705
if (argc < 2) {
17061706
shell_error(shell, "Missing required arguments");
1707-
shell_print(shell, "Usage: tmo dfu download <target>\n"
1708-
" target: 0 for mcu, 1 for modem, 2 for wifi");
1707+
shell_print(shell, "Usage: tmo dfu download <target> [filename]\n"
1708+
" target: 0 for mcu, 1 for modem, 2 for wifi\n"
1709+
" filename(optional): base filename e.g tmo_shell.tmo_dev_edge");
1710+
return -EINVAL;
1711+
}
1712+
int target = (int) strtol(argv[1], NULL, 10);
1713+
if (target > 2) {
1714+
shell_error(shell, "Only 3 targets supported (0-2)");
17091715
return -EINVAL;
17101716
}
1711-
return tmo_dfu_download( (int) strtol(argv[1], NULL, 10));
1717+
1718+
if (argv[2] == NULL && target > 0) {
1719+
shell_error(shell, "There are no updates at this time");
1720+
return -EINVAL;
1721+
}
1722+
1723+
return tmo_dfu_download(shell, target, argv[2], argv[3]);
1724+
}
1725+
1726+
int cmd_dfu_get_slot(const struct shell *shell, size_t argc, char **argv)
1727+
{
1728+
#ifdef BOOT_SLOT
1729+
shell_print(shell, "Slot %s", BOOT_SLOT);
1730+
#else
1731+
shell_print(shell, "Slot Undefined");
1732+
#endif
1733+
return 0;
17121734
}
17131735

17141736
int cmd_dfu_get_version(const struct shell *shell, size_t argc, char **argv)
@@ -1767,22 +1789,39 @@ int cmd_dfu_get_version(const struct shell *shell, size_t argc, char **argv)
17671789

17681790
int cmd_dfu_update(const struct shell *shell, size_t argc, char **argv)
17691791
{
1770-
if (argc < 3){
1792+
int firmware_target = (int) strtol(argv[1], NULL, 10);
1793+
int delta_firmware_target = (int) strtol(argv[2], NULL, 10);
1794+
1795+
if (((argc < 2) && (firmware_target != DFU_GECKO)) ||
1796+
((argc != 3) && (firmware_target == DFU_GECKO))) {
17711797
shell_error(shell, "Missing required arguments");
1772-
shell_print(shell, "Usage: tmo dfu update <target> <modem delta file>\n"
1773-
" target : 0 for mcu, 1 for modem, 2 for wifi/ble\n"
1774-
" modem delta file: SAMPLE: 0 for update3.2.20351_20161_dis.ua, 1 for update3.2.20161_20351_dis.ua\n"
1775-
" GOLDEN: 2 for update20351_20161_801_test.ua, 3 for update20161_20351_801_test.ua\n");
1798+
shell_print(shell, "Usage: tmo dfu update <target>\n"
1799+
" target : 0 for mcu, 1 for modem, 2 for wifi/ble\n"
1800+
" mcu_slot(optional): slot to update. Applicable only to mcu target\n"
1801+
" Usage (mcu): \n"
1802+
" tmo dfu update 0 [slot]\n"
1803+
" Usage (modem): \n"
1804+
" tmo dfu update 1 [modem_delta_file]\n"
1805+
" Usage (wifi/ble): \n"
1806+
" tmo dfu update 2\n");
17761807
return -EINVAL;
17771808
}
17781809

1779-
int firmware_target = (int) strtol(argv[1], NULL, 10);
1780-
int delta_firmware_target = (int) strtol(argv[2], NULL, 10);
1781-
17821810
switch (firmware_target)
17831811
{
17841812
case DFU_GECKO:
17851813
{
1814+
#ifdef BOOT_SLOT
1815+
if ((strcmp(BOOT_SLOT, "0") || strcmp(BOOT_SLOT, "1"))) {
1816+
if (atoi(BOOT_SLOT) == delta_firmware_target) {
1817+
shell_error(shell,"Can't program slot you are running from");
1818+
return -EINVAL;
1819+
}
1820+
}
1821+
#else
1822+
shell_error(shell,"Can't program over currently running firmware");
1823+
return -EINVAL;
1824+
#endif
17861825
shell_print(shell,"\nStarting the FW update for SiLabs Pearl Gecko");
17871826
int status;
17881827
status = dfu_mcu_firmware_upgrade(delta_firmware_target);
@@ -2120,6 +2159,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(tmo_dfu_sub,
21202159
SHELL_CMD(settings, NULL, "Print DFU settings", cmd_dfu_print_settings),
21212160
SHELL_CMD(update, NULL, "Update FW", cmd_dfu_update),
21222161
SHELL_CMD(version, NULL, "Get current FW version", cmd_dfu_get_version),
2162+
SHELL_CMD(slot, NULL, "Get current slot", cmd_dfu_get_slot),
21232163
SHELL_SUBCMD_SET_END
21242164
);
21252165

0 commit comments

Comments
 (0)