|
6 | 6 | use std::array::TryFromSliceError; |
7 | 7 | use std::fmt::Display; |
8 | 8 |
|
9 | | -use clap::{ValueEnum, builder::PossibleValue}; |
| 9 | +use clap::ValueEnum; |
| 10 | +use clap::builder::PossibleValue; |
10 | 11 | use color_eyre::eyre::{Context, Result, eyre}; |
11 | 12 | use log::debug; |
12 | 13 |
|
13 | | -use crate::{bmp::BmpPlatform, firmware_file::FirmwareFile}; |
| 14 | +use crate::bmp::BmpPlatform; |
| 15 | +use crate::firmware_file::FirmwareFile; |
14 | 16 |
|
15 | 17 | /// Represents a conceptual Vector Table for Armv7 processors. |
16 | 18 | pub struct Armv7mVectorTable<'b> |
@@ -73,21 +75,19 @@ impl FirmwareType |
73 | 75 | /// This function panics if `firmware.len() < 8`. |
74 | 76 | pub fn detect_from_firmware(platform: BmpPlatform, firmware_file: &FirmwareFile) -> Result<Self> |
75 | 77 | { |
76 | | - // If the firmware image has a load address |
77 | | - if let Some(load_address) = firmware_file.load_address() { |
78 | | - // Check if the address is the bootloader area for the platform |
79 | | - let boot_start = platform.load_address(Self::Bootloader); |
80 | | - return Ok( |
81 | | - if load_address == boot_start { |
82 | | - Self::Bootloader |
83 | | - } else { |
84 | | - Self::Application |
85 | | - } |
86 | | - ); |
87 | | - } |
88 | | - |
89 | | - // If the firmware doesn't have a known load address, fall back to figuring it out |
90 | | - // from the NVIC table at the front of the image |
| 78 | + // If the firmware image has a load address |
| 79 | + if let Some(load_address) = firmware_file.load_address() { |
| 80 | + // Check if the address is the bootloader area for the platform |
| 81 | + let boot_start = platform.load_address(Self::Bootloader); |
| 82 | + return Ok(if load_address == boot_start { |
| 83 | + Self::Bootloader |
| 84 | + } else { |
| 85 | + Self::Application |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + // If the firmware doesn't have a known load address, fall back to figuring it out |
| 90 | + // from the NVIC table at the front of the image |
91 | 91 | let buffer = &firmware_file.data()[0..(4 * 2)]; |
92 | 92 |
|
93 | 93 | let vector_table = Armv7mVectorTable::from_bytes(buffer); |
|
0 commit comments