struct tfm_interface *intf;
const char *part_table = "/usr/share/partition.info";
char *opt_table = NULL;
+ char *opt_serial = NULL;
int ret, opt;
supported_interfaces = tfm_interface_init();
goto out;
}
- while ((opt = getopt(argc, argv, "p:i:")) != -1) {
+ while ((opt = getopt(argc, argv, "p:i:s:")) != -1) {
switch (opt) {
case 'i':
if (optarg) {
} else {
fprintf(stderr, "Out of memory\n");
ret = -1;
- goto out_intfexit;
+ goto out_optfree;
}
} else {
fprintf(stderr,
"path should be specified with '-i'\n");
ret = -1;
- goto out_intfexit;
+ goto out_optfree;
}
break;
case 'p':
"net", (void *)val);
break;
}
+ case 's':
+ if (!tfm_interface_is_available(supported_interfaces,
+ "usb")) {
+ fprintf(stderr,
+ "'-s' option is ignored since usb interface is not available.\n");
+ continue;
+ }
+
+ if (optarg) {
+ if (opt_serial)
+ free(opt_serial);
+ opt_serial = strdup(optarg);
+ if (!opt_serial) {
+ fprintf(stderr, "Out of memory\n");
+ ret = -1;
+ goto out_optfree;
+ }
+ } else {
+ fprintf(stderr,
+ "serial should be specified with '-s'\n");
+ ret = -1;
+ goto out_optfree;
+ }
+ tfm_interface_set_private(supported_interfaces,
+ "usb", opt_serial);
+ break;
default:
ret = -1;
goto out_optfree;
out_optfree:
if (opt_table)
free(opt_table);
-out_intfexit:
+ if (opt_serial)
+ free(opt_serial);
+
tfm_interface_exit(supported_interfaces);
out:
#define TFMFFS_BIND_LINK "tfm.ffs"
#define TFMFFS_VID 0x04e8
#define TFMFFS_PID 0x685d
+#define TFMFFS_DEFAULT_SERIAL "Unavailable"
+#define TFMFFS_PRODUCT "USB download gadget"
+#define TFMFFS_MANUFACTURER "Tizen"
enum {
TFMFFS_EP0,
};
struct usbg_gadget_strs g_strs = {
- .serial = "Unavailable", /* Serial number */
- .manufacturer = "Tizen", /* Manufacturer */
- .product = "iot-refboard" /* Product string */
+ .serial = TFMFFS_DEFAULT_SERIAL,
+ .manufacturer = TFMFFS_MANUFACTURER,
+ .product = TFMFFS_PRODUCT
};
struct usbg_config_strs c_strs = {
goto err_freectx;
}
+ /* If serial is provided as argument, set it to g_strs */
+ if (intf->priv)
+ g_strs.serial = intf->priv;
+
ret = usbg_create_gadget(s, TFMFFS_GADGET, &g_attrs, &g_strs, &g);
+ /*
+ * In order to prevent that g_strs.serial has dangling pointer
+ * after the provided string is freed, we set g_strs.serial as
+ * default here.
+ * Since g_strs is accessed by only usbg_create_gadget() once,
+ * we can change it safely here.
+ */
+ if (intf->priv) {
+ g_strs.serial = TFMFFS_DEFAULT_SERIAL;
+ intf->priv = NULL;
+ }
if (ret < 0) {
fprintf(stderr, "Failed to create USB gadget\n");
goto err_cleanup;