(
device: &HidDevice,
fw_binary: &[u8],
start_row: usize,
metadata_row: usize,
rows: usize,
no: u8,
)
| 384 | } |
| 385 | |
| 386 | fn flash_firmware_image( |
| 387 | device: &HidDevice, |
| 388 | fw_binary: &[u8], |
| 389 | start_row: usize, |
| 390 | metadata_row: usize, |
| 391 | rows: usize, |
| 392 | no: u8, |
| 393 | ) { |
| 394 | let fw_slice = &fw_binary[start_row * ROW_SIZE..(start_row + rows) * ROW_SIZE]; |
| 395 | let metadata_slice = &fw_binary[metadata_row * ROW_SIZE..(metadata_row + 1) * ROW_SIZE]; |
| 396 | // Should be roughly 460 plus/minus 2 |
| 397 | debug!("Chunks: {:?}", (fw_slice.len() / ROW_SIZE) + 1); |
| 398 | |
| 399 | let _info = get_fw_info(device); |
| 400 | |
| 401 | let rows = fw_slice.chunks(ROW_SIZE); |
| 402 | for (row_no, row) in rows.enumerate() { |
| 403 | assert_eq!(row.len(), ROW_SIZE); |
| 404 | if row_no == 0 { |
| 405 | info!( |
| 406 | "Writing first firmware row@{:X?}: {:X?}", |
| 407 | start_row + row_no, |
| 408 | row |
| 409 | ); |
| 410 | } |
| 411 | write_row(device, (start_row + row_no) as u16, row).unwrap_or_else(|err| { |
| 412 | panic!( |
| 413 | "Failed to write firmware row #{} (@{:X}): {:?}", |
| 414 | row_no, |
| 415 | start_row + row_no, |
| 416 | err |
| 417 | ) |
| 418 | }); |
| 419 | } |
| 420 | info!( |
| 421 | "Writing metadata row@{:X?}: {:X?}", |
| 422 | metadata_row, metadata_slice |
| 423 | ); |
| 424 | write_row(device, metadata_row as u16, metadata_slice) |
| 425 | .expect("Failed to write firmware metadata"); |
| 426 | |
| 427 | // Not quite sure what this is. But on the first update it has |
| 428 | // 0x01 and on the second it has 0x02. So I think this switches the boot order? |
| 429 | info!("Bootswitch"); |
| 430 | let _ = send_command(device, CmdId::Cmd0x04, no).unwrap(); |
| 431 | |
| 432 | // Seems to reset the device, since the USB device number changes |
| 433 | info!("Reset"); |
| 434 | let _ = send_command(device, CmdId::CmdJump, CmdParam::Reset as u8).unwrap(); |
| 435 | } |
| 436 | |
| 437 | fn send_command(device: &HidDevice, cmd_id: CmdId, cmd_param: u8) -> Result<usize, HidError> { |
| 438 | device.write(&[ |
no test coverage detected