Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

greybus: firmware: Update Documentation and sample application

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>

authored by

Viresh Kumar and committed by
Greg Kroah-Hartman
6136cce8 5e10f004

+52 -17
+23 -7
drivers/staging/greybus/Documentation/firmware/firmware-management
··· 93 93 #define GB_FW_BACKEND_FW_STATUS_FAIL_FETCH 0x03 94 94 #define GB_FW_BACKEND_FW_STATUS_FAIL_WRITE 0x04 95 95 #define GB_FW_BACKEND_FW_STATUS_INT 0x05 96 + #define GB_FW_BACKEND_FW_STATUS_RETRY 0x06 97 + #define GB_FW_BACKEND_FW_STATUS_NOT_SUPPORTED 0x07 96 98 97 - struct fw_mgmt_ioc_get_fw { 98 - __u8 firmware_tag[GB_FIRMWARE_TAG_MAX_LEN]; 99 - __u16 major; 100 - __u16 minor; 101 - } __packed; 99 + #define GB_FW_BACKEND_VERSION_STATUS_SUCCESS 0x01 100 + #define GB_FW_BACKEND_VERSION_STATUS_NOT_AVAILABLE 0x02 101 + #define GB_FW_BACKEND_VERSION_STATUS_NOT_SUPPORTED 0x03 102 + #define GB_FW_BACKEND_VERSION_STATUS_RETRY 0x04 103 + #define GB_FW_BACKEND_VERSION_STATUS_FAIL_INT 0x05 104 + 105 + 106 + struct fw_mgmt_ioc_get_intf_version { 107 + __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_LEN]; 108 + __u16 major; 109 + __u16 minor; 110 + } __attribute__ ((__packed__)); 111 + 112 + struct fw_mgmt_ioc_get_backend_version { 113 + __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_LEN]; 114 + __u16 major; 115 + __u16 minor; 116 + __u8 status; 117 + } __attribute__ ((__packed__)); 102 118 103 119 struct fw_mgmt_ioc_intf_load_and_validate { 104 120 __u8 firmware_tag[GB_FIRMWARE_TAG_MAX_LEN]; ··· 130 114 } __packed; 131 115 132 116 #define FW_MGMT_IOCTL_BASE 'S' 133 - #define FW_MGMT_IOC_GET_INTF_FW _IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_fw) 134 - #define FW_MGMT_IOC_GET_BACKEND_FW _IOWR(FW_MGMT_IOCTL_BASE, 1, struct fw_mgmt_ioc_get_fw) 117 + #define FW_MGMT_IOC_GET_INTF_FW _IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_intf_version) 118 + #define FW_MGMT_IOC_GET_BACKEND_FW _IOWR(FW_MGMT_IOCTL_BASE, 1, struct fw_mgmt_ioc_get_backend_version) 135 119 #define FW_MGMT_IOC_INTF_LOAD_AND_VALIDATE _IOWR(FW_MGMT_IOCTL_BASE, 2, struct fw_mgmt_ioc_intf_load_and_validate) 136 120 #define FW_MGMT_IOC_INTF_BACKEND_FW_UPDATE _IOWR(FW_MGMT_IOCTL_BASE, 3, struct fw_mgmt_ioc_backend_fw_update) 137 121 #define FW_MGMT_IOC_SET_TIMEOUT_MS _IOW(FW_MGMT_IOCTL_BASE, 4, unsigned int)
+29 -10
drivers/staging/greybus/Documentation/firmware/firmware.c
··· 71 71 static int fw_update_type = FW_UPDATE_TYPE_DEFAULT; 72 72 static int fw_timeout = FW_TIMEOUT_DEFAULT; 73 73 74 - static struct fw_mgmt_ioc_get_fw fw_info; 74 + static struct fw_mgmt_ioc_get_intf_version intf_fw_info; 75 + static struct fw_mgmt_ioc_get_backend_version backend_fw_info; 75 76 static struct fw_mgmt_ioc_intf_load_and_validate intf_load; 76 77 static struct fw_mgmt_ioc_backend_fw_update backend_update; 77 78 ··· 88 87 /* Get Interface Firmware Version */ 89 88 printf("Get Interface Firmware Version\n"); 90 89 91 - ret = ioctl(fd, FW_MGMT_IOC_GET_INTF_FW, &fw_info); 90 + ret = ioctl(fd, FW_MGMT_IOC_GET_INTF_FW, &intf_fw_info); 92 91 if (ret < 0) { 93 92 printf("Failed to get interface firmware version: %s (%d)\n", 94 93 fwdev, ret); ··· 96 95 } 97 96 98 97 printf("Interface Firmware tag (%s), major (%d), minor (%d)\n", 99 - fw_info.firmware_tag, fw_info.major, fw_info.minor); 98 + intf_fw_info.firmware_tag, intf_fw_info.major, 99 + intf_fw_info.minor); 100 100 101 101 /* Try Interface Firmware load over Unipro */ 102 102 printf("Loading Interface Firmware\n"); ··· 145 143 /* Get Backend Firmware Version */ 146 144 printf("Getting Backend Firmware Version\n"); 147 145 148 - fw_info.major = 0; 149 - fw_info.minor = 0; 150 - strncpy((char *)&fw_info.firmware_tag, firmware_tag, 146 + strncpy((char *)&backend_fw_info.firmware_tag, firmware_tag, 151 147 GB_FIRMWARE_U_TAG_MAX_LEN); 152 148 153 - ret = ioctl(fd, FW_MGMT_IOC_GET_BACKEND_FW, &fw_info); 149 + retry_fw_version: 150 + ret = ioctl(fd, FW_MGMT_IOC_GET_BACKEND_FW, &backend_fw_info); 154 151 if (ret < 0) { 155 152 printf("Failed to get backend firmware version: %s (%d)\n", 156 153 fwdev, ret); 157 154 return -1; 158 155 } 159 156 160 - printf("Backend Firmware tag (%s), major (%d), minor (%d)\n", 161 - fw_info.firmware_tag, fw_info.major, fw_info.minor); 157 + printf("Backend Firmware tag (%s), major (%d), minor (%d), status (%d)\n", 158 + backend_fw_info.firmware_tag, backend_fw_info.major, 159 + backend_fw_info.minor, backend_fw_info.status); 160 + 161 + if (backend_fw_info.status == GB_FW_U_BACKEND_VERSION_STATUS_RETRY) 162 + goto retry_fw_version; 163 + 164 + if ((backend_fw_info.status != GB_FW_U_BACKEND_VERSION_STATUS_SUCCESS) 165 + && (backend_fw_info.status != GB_FW_U_BACKEND_VERSION_STATUS_NOT_AVAILABLE)) { 166 + printf("Failed to get backend firmware version: %s (%d)\n", 167 + fwdev, backend_fw_info.status); 168 + return -1; 169 + } 162 170 163 171 /* Try Backend Firmware Update over Unipro */ 164 172 printf("Updating Backend Firmware\n"); 165 173 166 - backend_update.status = 0; 167 174 strncpy((char *)&backend_update.firmware_tag, firmware_tag, 168 175 GB_FIRMWARE_U_TAG_MAX_LEN); 176 + 177 + retry_fw_update: 178 + backend_update.status = 0; 169 179 170 180 ret = ioctl(fd, FW_MGMT_IOC_INTF_BACKEND_FW_UPDATE, &backend_update); 171 181 if (ret < 0) { 172 182 printf("Failed to load backend firmware: %s (%d)\n", fwdev, ret); 173 183 return -1; 184 + } 185 + 186 + if (backend_update.status == GB_FW_U_BACKEND_FW_STATUS_RETRY) { 187 + printf("Retrying firmware update: %d\n", backend_update.status); 188 + goto retry_fw_update; 174 189 } 175 190 176 191 if (backend_update.status != GB_FW_U_BACKEND_FW_STATUS_SUCCESS) {