Skip to content

Commit 257a8a4

Browse files
committed
add cmdline option to retrieve storage device info
1 parent e1ec7b4 commit 257a8a4

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

firehose.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void firehose_response_log(xmlNode *node)
101101
xmlChar *value;
102102

103103
value = xmlGetProp(node, (xmlChar*)"value");
104-
dbg("LOG: %s", value);
104+
printf("[LOG] %s\n", value);
105105
}
106106

107107
static int firehose_wait(int fd, int timeout)
@@ -573,7 +573,7 @@ static int firehose_set_bootable(int fd, int part)
573573
return 0;
574574
}
575575

576-
static int firehose_reset(int fd)
576+
int firehose_reset(int fd)
577577
{
578578
xmlNode *root;
579579
xmlNode *node;
@@ -595,9 +595,8 @@ static int firehose_reset(int fd)
595595
return firehose_read(fd, -1, firehose_nop_parser);
596596
}
597597

598-
int firehose_run(int fd)
598+
int firehose_init(int fd)
599599
{
600-
int bootable;
601600
int ret;
602601

603602
ret = firehose_wait(fd, 10000);
@@ -607,11 +606,47 @@ int firehose_run(int fd)
607606
while (firehose_read(fd, 100, NULL) != -ETIMEDOUT)
608607
;
609608

610-
ret = firehose_nop(fd);
609+
return 0;
610+
}
611+
612+
int firehose_get_storage_info(int fd, int part)
613+
{
614+
xmlNode *root;
615+
xmlNode *node;
616+
xmlDoc *doc;
617+
int ret;
618+
619+
ret = firehose_configure(fd, false);
611620
if (ret)
612621
return ret;
613622

614-
if(ufs_need_provisioning()) {
623+
doc = xmlNewDoc((xmlChar*)"1.0");
624+
root = xmlNewNode(NULL, (xmlChar*)"data");
625+
xmlDocSetRootElement(doc, root);
626+
627+
node = xmlNewChild(root, NULL, (xmlChar*)"getstorageinfo", NULL);
628+
xml_setpropf(node, "physical_partition_number", "%d", part);
629+
630+
ret = firehose_write(fd, doc);
631+
xmlFreeDoc(doc);
632+
if (ret < 0)
633+
return ret;
634+
635+
ret = firehose_read(fd, -1, firehose_nop_parser);
636+
if (ret) {
637+
warnx("failed to mark partition %d as bootable", part);
638+
return -1;
639+
}
640+
641+
return 0;
642+
}
643+
644+
int firehose_provision(int fd)
645+
{
646+
int bootable;
647+
int ret;
648+
649+
if (ufs_need_provisioning()) {
615650
ret = firehose_configure(fd, true);
616651
if (ret)
617652
return ret;

qdl.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ enum {
6161
};
6262

6363
bool qdl_debug;
64+
bool qdl_get_info;
6465
const char **qdl_search_path;
6566

6667
static int detect_type(const char *xml_file)
@@ -266,9 +267,11 @@ int main(int argc, char **argv)
266267
int fd;
267268
int opt;
268269
bool qdl_finalize_provisioning = false;
270+
bool qdl_get_info = false;
269271

270272
static struct option options[] = {
271273
{"debug", no_argument, 0, 'd'},
274+
{"info", no_argument, 0, 'i'},
272275
{"finalize-provisioning", no_argument, 0, 'l'},
273276
{"search-path", required_argument, 0, 's'},
274277
{0, 0, 0, 0}
@@ -279,6 +282,9 @@ int main(int argc, char **argv)
279282
case 'd':
280283
qdl_debug = true;
281284
break;
285+
case 'i':
286+
qdl_get_info = true;
287+
break;
282288
case 'l':
283289
qdl_finalize_provisioning = true;
284290
break;
@@ -291,19 +297,18 @@ int main(int argc, char **argv)
291297
}
292298
}
293299

294-
/* at least 2 non optional args required */
295-
if ((optind + 2) > argc) {
300+
if ((optind + 1) > argc) {
296301
print_usage();
297302
return 1;
298303
}
299304

300-
prog_mbn = argv[optind++];
305+
prog_mbn = argv[optind];
301306

302307
/* default to cwd as search path */
303308
if (!qdl_search_path)
304309
add_search_path(".");
305310

306-
do {
311+
while (++optind < argc) {
307312
type = detect_type(argv[optind]);
308313
if (type < 0 || type == QDL_FILE_UNKNOWN)
309314
errx(1, "failed to detect file type of %s\n", argv[optind]);
@@ -328,7 +333,7 @@ int main(int argc, char **argv)
328333
errx(1, "%s type not yet supported", argv[optind]);
329334
break;
330335
}
331-
} while (++optind < argc);
336+
}
332337

333338
fd = tty_open(&tios);
334339
if (fd < 0)
@@ -338,7 +343,21 @@ int main(int argc, char **argv)
338343
if (ret < 0)
339344
goto out;
340345

341-
ret = firehose_run(fd);
346+
ret = firehose_init(fd);
347+
if (ret < 0)
348+
goto out;
349+
350+
if (qdl_get_info) {
351+
ret = firehose_get_storage_info(fd, 65210);
352+
if (ret < 0)
353+
goto out;
354+
} else {
355+
ret = firehose_provision(fd);
356+
if (ret < 0)
357+
goto out;
358+
359+
firehose_reset(fd);
360+
}
342361

343362
out:
344363
ret = tcsetattr(fd, TCSANOW, &tios);

qdl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include "patch.h"
77
#include "program.h"
88

9-
int firehose_run(int fd);
9+
int firehose_init(int fd);
10+
int firehose_reset(int fd);
11+
int firehose_get_storage_info(int fd, int part);
12+
int firehose_provision(int fd);
1013
int sahara_run(int fd, char *prog_mbn);
1114
void print_hex_dump(const char *prefix, const void *buf, size_t len);
1215
int open_in_search_path(const char *filename, int flags);

0 commit comments

Comments
 (0)