Implemented api.platform.config.switch.0.bootCfg.pep.%.serialNumber MAC address
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
DataHoarder 2020-12-27 01:30:17 +01:00
parent 2f81fe9539
commit 082ef5bdf3
5 changed files with 84 additions and 11 deletions

View file

@ -180,3 +180,49 @@ const Configuration::ConfigurationNode *Configuration::ConfigurationNode::getSub
return nullptr;
}
std::pair<uint32_t, uint32_t> Configuration::ConfigurationNode::getEUI64ToInteger() const {
std::pair<uint32_t, uint32_t> pair{0xFFFFFFFF, 0xFFFFFFFF};
uint32_t b[8];
int scanCount;
/* Try with the ':' delimiter */
scanCount = sscanf(getText().c_str(),
"%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x",
&b[0],
&b[1],
&b[2],
&b[3],
&b[4],
&b[5],
&b[6],
&b[7]);
/* Try with the '-' delimiter */
if (scanCount == 0) {
scanCount = sscanf(getText().c_str(),
"%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x",
&b[0],
&b[1],
&b[2],
&b[3],
&b[4],
&b[5],
&b[6],
&b[7]);
}
if (scanCount == 8) {
pair.second = (b[0] & 0xFF) << 24;
pair.second |= (b[1] & 0xFF) << 16;
pair.second |= (b[2] & 0xFF) << 8;
pair.second |= (b[3] & 0xFF);
pair.first = (b[4] & 0xFF) << 24;
pair.first |= (b[5] & 0xFF) << 16;
pair.first |= (b[6] & 0xFF) << 8;
pair.first |= (b[7] & 0xFF);
}
return pair;
}

View file

@ -83,6 +83,8 @@ public:
return std::stoi(value, nullptr, 0);
}
std::pair<uint32_t, uint32_t> getEUI64ToInteger() const;
const std::string &getText() const {
return value;
}

View file

@ -26,11 +26,8 @@
*****************************************************************************/
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <fstream>
#include "ImageFormat.h"
#include "Registers.h"
#include "instructions/Write.h"
@ -53,17 +50,12 @@ ImageFormat ImageFormat::fromBytes(const std::vector<uint8_t> &imageBytes) {
image.header.baseAddress |= imageBytes[offset++] << 8;
image.header.baseAddress |= imageBytes[offset++];
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", image.header.speed, image.header.mode,
image.header.baseAddress);
offset = CFG_SIGNATURE;
uint8_t currentCharacter;
while ((currentCharacter = imageBytes[offset++]) != 0xFF) {
image.imageSignature += currentCharacter;
}
std::cout << "SIGNATURE: " << image.imageSignature << "\n";
offset = CFG_HEADER;
image.cfgHeader.length = imageBytes[offset++];

View file

@ -38,8 +38,8 @@ namespace Instruction {
class Instruction {
protected:
uint32_t _address;
uint32_t _endAddress;
uint32_t _address{};
uint32_t _endAddress{};
public:
/*Instruction(){

View file

@ -44,6 +44,12 @@ void decodeImage(const std::string &fileName) {
}
auto imageObject = ImageFormat::fromBytes(bytes);
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", imageObject.getHeader().speed, imageObject.getHeader().mode,
imageObject.getHeader().baseAddress);
std::cout << "SIGNATURE: " << imageObject.imageSignature << "\n";
for (auto &k : imageObject.getBootConfig().getAllEntries()) {
std::cout << k << "\n";
}
@ -130,7 +136,7 @@ patchImage(const std::string &originalImage, const std::string &settingsFile, co
*/
// == is patching implemented. @ is absolute addressing, nothing relative to bank offsets
// @0x1000 LOAD 9x2 entries @ 0x120053/0x120054 + 0x100028/0x100029 BSM_SCRATCH[0x141]-BSM_SCRATCH[0x142] PCIE_CFG_SPD_NUMBER_L SerialNumber and PCIE_SM_AREA.SerialNumber
// ==@0x1000 LOAD 9x2 api.platform.config.switch.0.bootCfg.pep.%.serialNumber @ 0x120053/0x120054 + 0x100028/0x100029 BSM_SCRATCH[0x141]-BSM_SCRATCH[0x142] PCIE_CFG_SPD_NUMBER_L SerialNumber and PCIE_SM_AREA.SerialNumber
//
// @0x1054 LOAD 8 entries api.platform.config.switch.0.bootCfg.customMac.0-4
//
@ -233,6 +239,33 @@ patchImage(const std::string &originalImage, const std::string &settingsFile, co
}
}
{
auto &instruction = imageObject.findInstructionByAddress(0x1000);
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x00a) && load->data.size() == 9 * 2) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".serialNumber";
auto entry = config.getEntry(key.str());
if (entry.type == Configuration::ConfigurationNode::Type::ValueText &&
!entry.value.empty()) {
auto value = entry.getEUI64ToInteger();
if(value.first == 0xFFFFFFFF && value.second == 0xFFFFFFFF){
value.first &= 0xFF000100 | pepOffset;
value.second &= 0x000000FF;
}
load->data[pepOffset * 2] = value.first;
load->data[pepOffset * 2 + 1] = value.second;
}
}
}
}
}
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9230);