Integrated SPICO/SerDes firmware image into its own class
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2020-12-19 18:05:08 +01:00
parent 8083bfc80b
commit abbb20ce3b
5 changed files with 102 additions and 29 deletions

View file

@ -3,4 +3,4 @@ project(rrcSmall)
set(CMAKE_CXX_STANDARD 14)
add_executable(rrcSmall src/main.cpp src/ImageFormat.cpp src/ImageFormat.h)
add_executable(rrcSmall src/main.cpp src/ImageFormat.cpp src/ImageFormat.h src/SmallFirmwareFormat.cpp src/SmallFirmwareFormat.h)

View file

@ -652,19 +652,9 @@ std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> ImageFo
uint8_t increment = ((command >> 2) & 0b1);
if((command & 0b11) == 0 && increment == 0 && parameters[0] == (uint32_t)KnownRegisters::PCIE_MASTER_SPICO_FIRMWARE_SPECIAL_REGISTER){
state.pciSPICOFirmware.clear();
for (auto it = parameters.begin() + 2; it != parameters.end(); ++it) {
state.pciSPICOFirmware.push_back(((*it >> 20) & 0x3FF));
state.pciSPICOFirmware.push_back(((*it >> 10) & 0x3FF));
state.pciSPICOFirmware.push_back(((*it) & 0x3FF));
}
state.pciSPICOFirmware = SmallFirmwareFormat::fromBSMLoad(parameters, 2);
}else if((command & 0b11) == 0 && increment == 0 && parameters[0] == (uint32_t)KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER){
state.pciSerDesFirmware.clear();
for (auto it = parameters.begin() + 2; it != parameters.end(); ++it) {
state.pciSerDesFirmware.push_back(((*it >> 20) & 0x3FF));
state.pciSerDesFirmware.push_back(((*it >> 10) & 0x3FF));
state.pciSerDesFirmware.push_back(((*it) & 0x3FF));
}
state.pciSerDesFirmware = SmallFirmwareFormat::fromBSMLoad(parameters, 2);
}else{
uint32_t index = 0;
for (auto it = parameters.begin() + 2; it != parameters.end(); ++it) {
@ -967,15 +957,12 @@ std::string ImageFormat::Instruction::toString() const{
op << std::hex << std::setw(8) << std::setfill('0') << *it;
}
op << "\n";
auto fw = SmallFirmwareFormat::fromBSMLoad(parameters, 2);
uint32_t off = 0;
for (auto it = parameters.begin() + 2; it != parameters.end(); ++it) {
for (auto it = fw.firmware.begin(); it != fw.firmware.end(); ++it) {
op << " - SPICO_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << ((*it >> 20) & 0x3FF) << "\n";
op << " - SPICO_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << ((*it >> 10) & 0x3FF) << "\n";
op << " - SPICO_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << (*it & 0x3FF) << "\n";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << *it << "\n";
}
}else if(offset == 0 && increment == 0 && parameters[0] == (uint32_t)KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER){
op << "LOAD PCIE_BROADCAST_SERDES_FIRMWARE DATA 0x";
@ -983,15 +970,12 @@ std::string ImageFormat::Instruction::toString() const{
op << std::hex << std::setw(8) << std::setfill('0') << *it;
}
op << "\n";
auto fw = SmallFirmwareFormat::fromBSMLoad(parameters, 2);
uint32_t off = 0;
for (auto it = parameters.begin() + 2; it != parameters.end(); ++it) {
for (auto it = fw.firmware.begin(); it != fw.firmware.end(); ++it) {
op << " - SERDES_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << ((*it >> 20) & 0x3FF) << "\n";
op << " - SERDES_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << ((*it >> 10) & 0x3FF) << "\n";
op << " - SERDES_FW[" << std::hex << std::setw(4) << std::setfill('0') << off++ << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << (*it & 0x3FF) << "\n";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << *it << "\n";
}
}else{

View file

@ -32,6 +32,8 @@
#include <cstdint>
#include <unordered_map>
#include "SmallFirmwareFormat.h"
class ImageFormat{
public:
@ -42,10 +44,8 @@ public:
uint32_t previous;
uint32_t current;
//Each entry is 10-bit only
std::vector<uint16_t> pciSPICOFirmware;
//Each entry is 10-bit only
std::vector<uint16_t> pciSerDesFirmware;
SmallFirmwareFormat pciSPICOFirmware;
SmallFirmwareFormat pciSerDesFirmware;
AnalysisState(uint32_t initial) : current(initial), previous(0){

View file

@ -0,0 +1,40 @@
/*****************************************************************************
* Copyright (c) 2020, rrcSmall FM10K-Documentation Contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "SmallFirmwareFormat.h"
SmallFirmwareFormat SmallFirmwareFormat::fromBSMLoad(const std::vector<uint32_t>& parameters, uint32_t parameterOffset) {
SmallFirmwareFormat fw;
for (auto it = parameters.begin() + parameterOffset; it != parameters.end(); ++it) {
fw.firmware.push_back(((*it >> 20) & 0x3FF));
fw.firmware.push_back(((*it >> 10) & 0x3FF));
fw.firmware.push_back(((*it) & 0x3FF));
}
return fw;
}

49
src/SmallFirmwareFormat.h Normal file
View file

@ -0,0 +1,49 @@
/*****************************************************************************
* Copyright (c) 2020, rrcSmall FM10K-Documentation Contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#pragma once
#include <cstdint>
#include <vector>
class SmallFirmwareFormat {
public:
static SmallFirmwareFormat fromBSMLoad(const std::vector<uint32_t>& parameters, uint32_t parameterOffset);
SmallFirmwareFormat(){
}
SmallFirmwareFormat(const SmallFirmwareFormat& other) : firmware(other.firmware){
}
//Each entry is 10-bit only
std::vector<uint16_t> firmware;
};