dfu: Fix writing to the GD32VF103 bootloader

Just set the alt_name rather than creating one giant sector and use the GD32
serial number for the sector map fixup.

See c2c8215061
This commit is contained in:
Richard Hughes 2021-02-27 11:31:09 +00:00
parent b3f9841924
commit aeba5f7f53
2 changed files with 25 additions and 28 deletions

View File

@ -4,7 +4,7 @@ Plugin = dfu
# GD32VF103 Rev1 # GD32VF103 Rev1
[DeviceInstanceId=USB\VID_28E9&PID_0189] [DeviceInstanceId=USB\VID_28E9&PID_0189]
Flags = gd32 Flags = gd32,force-dfu-mode
Vendor = GDMicroelectronics Vendor = GDMicroelectronics
# Realtek USB camera # Realtek USB camera

View File

@ -674,45 +674,42 @@ fu_dfu_target_setup (FuDfuTarget *self, GError **error)
} }
/* GD32VF103 devices features and peripheral list */ /* GD32VF103 devices features and peripheral list */
if (fu_device_has_custom_flag (device, "gd32")) { if (priv->alt_setting == 0x0 &&
fu_device_has_custom_flag (device, "gd32")) {
/* RB R8 R6 R4 VB V8 /* RB R8 R6 R4 VB V8
* Flash (KB) 128 64 32 16 128 64 * Flash (KB) 128 64 32 16 128 64
* TB T8 T6 T4 CB C8 C6 C4 * TB T8 T6 T4 CB C8 C6 C4
* Flash (KB) 128 64 32 16 128 64 32 16 * Flash (KB) 128 64 32 16 128 64 32 16
*/ */
guint flashsz = 0; const gchar *serial = fu_device_get_serial (device);
const gchar *chip_id = fu_dfu_device_get_chip_id (fu_dfu_target_get_device (self)); if (serial == NULL || strlen (serial) < 4 || serial[3] != 'J') {
FuDfuSector *sector; g_set_error (error,
if (chip_id[1] == '2') { FWUPD_ERROR,
flashsz = 8; FWUPD_ERROR_NOT_SUPPORTED,
} else if (chip_id[1] == '4') { "GD32 serial number %s invalid",
flashsz = 16; serial);
} else if (chip_id[1] == '6') { return FALSE;
flashsz = 32; }
} else if (chip_id[1] == '8') { if (serial[2] == '2') {
flashsz = 64; fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/8*1Kg");
} else if (chip_id[1] == 'B') { } else if (serial[2] == '4') {
flashsz = 128; fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/16*1Kg");
} else if (chip_id[1] == 'D') { } else if (serial[2] == '6') {
flashsz = 256; fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/32*1Kg");
} else if (serial[2] == '8') {
fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/64*1Kg");
} else if (serial[2] == 'B') {
fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/128*1Kg");
} else if (serial[2] == 'D') {
fu_dfu_target_set_alt_name (self, "@Internal Flash /0x8000000/256*1Kg");
} else { } else {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"Unknown GD32 sector size: %c", "Unknown GD32 sector size: %c",
chip_id[1]); serial[2]);
return FALSE; return FALSE;
} }
g_debug ("using GD32 sector size of 0x%x", flashsz * 0x400);
sector = fu_dfu_sector_new (0x08000000, /* addr */
flashsz * 0x400, /* size */
flashsz * 0x400, /* size_left */
0x0, /* zone */
0x0, /* number */
DFU_SECTOR_CAP_ERASEABLE |
DFU_SECTOR_CAP_READABLE |
DFU_SECTOR_CAP_WRITEABLE);
g_ptr_array_add (priv->sectors, sector);
} }
/* get string */ /* get string */