mkii: Unfinished code for image flashing
This commit is contained in:
1 parent
3dc90e643c
commit
ea9f9d5a69
1 file changed
+136
-2
+136
-2
@@ -141,11 +141,145 @@ enum device mkii_get_device(struct usb_device_info * dev) {
|
|||||||
|
|
||||||
int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
|
int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
char buf1[512];
|
||||||
|
char buf[2048];
|
||||||
|
struct mkii_message * msg1;
|
||||||
|
struct mkii_message * msg;
|
||||||
|
char * ptr;
|
||||||
|
const char * type;
|
||||||
|
uint8_t len;
|
||||||
|
uint16_t hash;
|
||||||
|
uint32_t size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
ERROR("Not implemented yet");
|
ERROR("Not implemented yet");
|
||||||
(void)dev;
|
|
||||||
(void)image;
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
msg = (struct mkii_message *)buf;
|
||||||
|
msg1 = (struct mkii_message *)buf1;
|
||||||
|
ptr = msg->data;
|
||||||
|
|
||||||
|
/* Signature */
|
||||||
|
memcpy(ptr, "\x2E\x19\x01\x01", 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Space */
|
||||||
|
memcpy(ptr, "\x00", 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
/* Hash */
|
||||||
|
hash = htons(image->hash);
|
||||||
|
memcpy(ptr, &hash, 2);
|
||||||
|
ptr += 2;
|
||||||
|
|
||||||
|
/* Type */
|
||||||
|
type = image_type_to_string(image->type);
|
||||||
|
if ( ! type )
|
||||||
|
ERROR_RETURN("Unknown image type", -1);
|
||||||
|
memset(ptr, 0, 12);
|
||||||
|
strncpy(ptr, type, 12);
|
||||||
|
ptr += 12;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
size = htonl(image->size);
|
||||||
|
memcpy(ptr, &size, 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Space */
|
||||||
|
memcpy(ptr, "\x00\x00\x00\x00", 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Device & hwrev */
|
||||||
|
if ( image->devices ) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
uint8_t len;
|
||||||
|
char buf[9];
|
||||||
|
char ** bufs = NULL;
|
||||||
|
struct device_list * device = image->devices;
|
||||||
|
|
||||||
|
while ( device ) {
|
||||||
|
if ( device->device == dev->device && hwrev_is_valid(device->hwrevs, dev->hwrev) )
|
||||||
|
break;
|
||||||
|
device = device->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( device )
|
||||||
|
bufs = device_list_alloc_to_bufs(device);
|
||||||
|
|
||||||
|
if ( bufs ) {
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
snprintf(buf, 8+1, "%d", dev->hwrev);
|
||||||
|
|
||||||
|
for ( i = 0; bufs[i]; ++i ) {
|
||||||
|
len = ((uint8_t*)bufs[i])[0];
|
||||||
|
if ( memmem(bufs[i]+1, len, buf, strlen(buf)) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( bufs[i] ) {
|
||||||
|
/* Device & hwrev string header */
|
||||||
|
memcpy(ptr, "\x32", 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Device & hwrev string size */
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Device & hwrev string */
|
||||||
|
memcpy(ptr, bufs[i]+1, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(bufs);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
if ( image->version ) {
|
||||||
|
len = strnlen(image->version, 255) + 1;
|
||||||
|
/* Version string header */
|
||||||
|
memcpy(ptr, "\x31", 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Version string size */
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Version string */
|
||||||
|
memcpy(ptr, image->version, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* append layout subsection */
|
||||||
|
if ( image->layout ) {
|
||||||
|
len = strlen(image->layout);
|
||||||
|
/* Layout header */
|
||||||
|
memcpy(ptr, "\x33", 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Layout size */
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Layout string */
|
||||||
|
memcpy(ptr, image->layout, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end */
|
||||||
|
memcpy(ptr, "\x00", 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
ret = mkii_send_receive(dev->udev, MKII_INIT_SEND, msg1, 0, msg1, sizeof(buf1));
|
||||||
|
if ( ret != 1 || msg1->data[0] != 0 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ret = mkii_send_receive(dev->udev, MKII_SEND_IMAGE, msg, ptr - msg->data, msg, sizeof(buf));
|
||||||
|
if ( ret != 9 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* TODO: send image itself */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkii_reboot_device(struct usb_device_info * dev) {
|
int mkii_reboot_device(struct usb_device_info * dev) {
|
||||||
|
|||||||
Reference in new issue
Block a user