greybus: firmware: Update Documentation and sample application
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 25 Jul 2016 21:38:09 +0000 (14:38 -0700)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 26 Jul 2016 23:16:15 +0000 (16:16 -0700)
Update documentation and sample application to capture the 'status' byte
in backend version operation and new error types in backend firmware
update operation.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/Documentation/firmware/firmware-management
drivers/staging/greybus/Documentation/firmware/firmware.c

index 6b7b6d8..77d272c 100644 (file)
@@ -93,12 +93,28 @@ Following are the IOCTLs and their data structures available to the user:
 #define GB_FW_BACKEND_FW_STATUS_FAIL_FETCH     0x03
 #define GB_FW_BACKEND_FW_STATUS_FAIL_WRITE     0x04
 #define GB_FW_BACKEND_FW_STATUS_INT            0x05
+#define GB_FW_BACKEND_FW_STATUS_RETRY          0x06
+#define GB_FW_BACKEND_FW_STATUS_NOT_SUPPORTED  0x07
 
-struct fw_mgmt_ioc_get_fw {
-       __u8                    firmware_tag[GB_FIRMWARE_TAG_MAX_LEN];
-       __u16                   major;
-       __u16                   minor;
-} __packed;
+#define GB_FW_BACKEND_VERSION_STATUS_SUCCESS           0x01
+#define GB_FW_BACKEND_VERSION_STATUS_NOT_AVAILABLE     0x02
+#define GB_FW_BACKEND_VERSION_STATUS_NOT_SUPPORTED     0x03
+#define GB_FW_BACKEND_VERSION_STATUS_RETRY             0x04
+#define GB_FW_BACKEND_VERSION_STATUS_FAIL_INT          0x05
+
+
+struct fw_mgmt_ioc_get_intf_version {
+       __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_LEN];
+       __u16 major;
+       __u16 minor;
+} __attribute__ ((__packed__));
+
+struct fw_mgmt_ioc_get_backend_version {
+       __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_LEN];
+       __u16 major;
+       __u16 minor;
+       __u8 status;
+} __attribute__ ((__packed__));
 
 struct fw_mgmt_ioc_intf_load_and_validate {
        __u8                    firmware_tag[GB_FIRMWARE_TAG_MAX_LEN];
@@ -114,8 +130,8 @@ struct fw_mgmt_ioc_backend_fw_update {
 } __packed;
 
 #define FW_MGMT_IOCTL_BASE                     'S'
-#define FW_MGMT_IOC_GET_INTF_FW                        _IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_fw)
-#define FW_MGMT_IOC_GET_BACKEND_FW             _IOWR(FW_MGMT_IOCTL_BASE, 1, struct fw_mgmt_ioc_get_fw)
+#define FW_MGMT_IOC_GET_INTF_FW                        _IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_intf_version)
+#define FW_MGMT_IOC_GET_BACKEND_FW             _IOWR(FW_MGMT_IOCTL_BASE, 1, struct fw_mgmt_ioc_get_backend_version)
 #define FW_MGMT_IOC_INTF_LOAD_AND_VALIDATE     _IOWR(FW_MGMT_IOCTL_BASE, 2, struct fw_mgmt_ioc_intf_load_and_validate)
 #define FW_MGMT_IOC_INTF_BACKEND_FW_UPDATE     _IOWR(FW_MGMT_IOCTL_BASE, 3, struct fw_mgmt_ioc_backend_fw_update)
 #define FW_MGMT_IOC_SET_TIMEOUT_MS             _IOW(FW_MGMT_IOCTL_BASE, 4, unsigned int)
index c557bf1..5170886 100644 (file)
@@ -71,7 +71,8 @@ static const char *fwdev = FW_DEV_DEFAULT;
 static int fw_update_type = FW_UPDATE_TYPE_DEFAULT;
 static int fw_timeout = FW_TIMEOUT_DEFAULT;
 
-static struct fw_mgmt_ioc_get_fw fw_info;
+static struct fw_mgmt_ioc_get_intf_version intf_fw_info;
+static struct fw_mgmt_ioc_get_backend_version backend_fw_info;
 static struct fw_mgmt_ioc_intf_load_and_validate intf_load;
 static struct fw_mgmt_ioc_backend_fw_update backend_update;
 
@@ -87,7 +88,7 @@ static int update_intf_firmware(int fd)
        /* Get Interface Firmware Version */
        printf("Get Interface Firmware Version\n");
 
-       ret = ioctl(fd, FW_MGMT_IOC_GET_INTF_FW, &fw_info);
+       ret = ioctl(fd, FW_MGMT_IOC_GET_INTF_FW, &intf_fw_info);
        if (ret < 0) {
                printf("Failed to get interface firmware version: %s (%d)\n",
                        fwdev, ret);
@@ -95,7 +96,8 @@ static int update_intf_firmware(int fd)
        }
 
        printf("Interface Firmware tag (%s), major (%d), minor (%d)\n",
-               fw_info.firmware_tag, fw_info.major, fw_info.minor);
+               intf_fw_info.firmware_tag, intf_fw_info.major,
+               intf_fw_info.minor);
 
        /* Try Interface Firmware load over Unipro */
        printf("Loading Interface Firmware\n");
@@ -143,34 +145,51 @@ static int update_backend_firmware(int fd)
        /* Get Backend Firmware Version */
        printf("Getting Backend Firmware Version\n");
 
-       fw_info.major = 0;
-       fw_info.minor = 0;
-       strncpy((char *)&fw_info.firmware_tag, firmware_tag,
+       strncpy((char *)&backend_fw_info.firmware_tag, firmware_tag,
                GB_FIRMWARE_U_TAG_MAX_LEN);
 
-       ret = ioctl(fd, FW_MGMT_IOC_GET_BACKEND_FW, &fw_info);
+retry_fw_version:
+       ret = ioctl(fd, FW_MGMT_IOC_GET_BACKEND_FW, &backend_fw_info);
        if (ret < 0) {
                printf("Failed to get backend firmware version: %s (%d)\n",
                        fwdev, ret);
                return -1;
        }
 
-       printf("Backend Firmware tag (%s), major (%d), minor (%d)\n",
-               fw_info.firmware_tag, fw_info.major, fw_info.minor);
+       printf("Backend Firmware tag (%s), major (%d), minor (%d), status (%d)\n",
+               backend_fw_info.firmware_tag, backend_fw_info.major,
+               backend_fw_info.minor, backend_fw_info.status);
+
+       if (backend_fw_info.status == GB_FW_U_BACKEND_VERSION_STATUS_RETRY)
+               goto retry_fw_version;
+
+       if ((backend_fw_info.status != GB_FW_U_BACKEND_VERSION_STATUS_SUCCESS)
+           && (backend_fw_info.status != GB_FW_U_BACKEND_VERSION_STATUS_NOT_AVAILABLE)) {
+               printf("Failed to get backend firmware version: %s (%d)\n",
+                       fwdev, backend_fw_info.status);
+               return -1;
+       }
 
        /* Try Backend Firmware Update over Unipro */
        printf("Updating Backend Firmware\n");
 
-       backend_update.status = 0;
        strncpy((char *)&backend_update.firmware_tag, firmware_tag,
                GB_FIRMWARE_U_TAG_MAX_LEN);
 
+retry_fw_update:
+       backend_update.status = 0;
+
        ret = ioctl(fd, FW_MGMT_IOC_INTF_BACKEND_FW_UPDATE, &backend_update);
        if (ret < 0) {
                printf("Failed to load backend firmware: %s (%d)\n", fwdev, ret);
                return -1;
        }
 
+       if (backend_update.status == GB_FW_U_BACKEND_FW_STATUS_RETRY) {
+               printf("Retrying firmware update: %d\n", backend_update.status);
+               goto retry_fw_update;
+       }
+
        if (backend_update.status != GB_FW_U_BACKEND_FW_STATUS_SUCCESS) {
                printf("Load status says loading failed: %d\n",
                        backend_update.status);