Added new patching entries for known key -> value mappings
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-25 23:04:47 +01:00
parent 9f71deeaf9
commit 3d44e39c32

View file

@ -120,6 +120,8 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
PCIE_CFG_SPD_NUMBER_L = 0xFF234567 PCIE_CFG_SPD_NUMBER_H = 0x00A0C9FF
http://standards.ieee.org/regauth/oui/tutorials/EUI64.html
*/
// == 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
//
// @0x1054 LOAD 8 entries api.platform.config.switch.0.bootCfg.customMac.0-4
@ -136,31 +138,31 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
// 0x8c71 LOAD PEP7 device config Vital Product Data BSM_SCRATCH[0x352]
// 0x8e38 LOAD PEP8 device config Vital Product Data BSM_SCRATCH[0x384]
//
// 0x9000 LOAD 1 api.platform.config.switch.0.bootCfg.systimeClockSource
// 0x9010 LOAD 1 api.platform.config.switch.0.bootCfg.pep.0.mode
// 0x9020 LOAD 1 api.platform.config.switch.0.bootCfg.pep.2.mode
// 0x9030 LOAD 1 api.platform.config.switch.0.bootCfg.pep.4.mode
// 0x9040 LOAD 1 api.platform.config.switch.0.bootCfg.pep.6.mode
// 0x9050 LOAD 1 api.platform.config.switch.0.bootCfg.pep.0.enable
// 0x9060 LOAD 1 api.platform.config.switch.0.bootCfg.pep.1.enable
// 0x9070 LOAD 1 api.platform.config.switch.0.bootCfg.pep.2.enable
// 0x9080 LOAD 1 api.platform.config.switch.0.bootCfg.pep.3.enable
// 0x9090 LOAD 1 api.platform.config.switch.0.bootCfg.pep.4.enable
// 0x90a0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.5.enable
// 0x90b0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.6.enable
// 0x90c0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.7.enable
// 0x90d0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.8.enable
// ==0x9000 LOAD 1 api.platform.config.switch.0.bootCfg.systimeClockSource
// ==0x9010 LOAD 1 api.platform.config.switch.0.bootCfg.pep.0.mode
// ==0x9020 LOAD 1 api.platform.config.switch.0.bootCfg.pep.2.mode
// ==0x9030 LOAD 1 api.platform.config.switch.0.bootCfg.pep.4.mode
// ==0x9040 LOAD 1 api.platform.config.switch.0.bootCfg.pep.6.mode
// ==0x9050 LOAD 1 api.platform.config.switch.0.bootCfg.pep.0.enable
// ==0x9060 LOAD 1 api.platform.config.switch.0.bootCfg.pep.1.enable
// ==0x9070 LOAD 1 api.platform.config.switch.0.bootCfg.pep.2.enable
// ==0x9080 LOAD 1 api.platform.config.switch.0.bootCfg.pep.3.enable
// ==0x9090 LOAD 1 api.platform.config.switch.0.bootCfg.pep.4.enable
// ==0x90a0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.5.enable
// ==0x90b0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.6.enable
// ==0x90c0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.7.enable
// ==0x90d0 LOAD 1 api.platform.config.switch.0.bootCfg.pep.8.enable
// 0x90e0 LOAD 1 = 0x0 ???? (0-index) IF 1: GPIO_DATA.data[14] = 0 (drive to gnd), GPIO_CFG.Dir[14] = 1 (output), GPIO_CFG.OpenDrain[14] = 1 (open drain)
// (BSM_SCRATCH[0x149] = 0x00084000)
// 0x90f0 LOAD 1 = 0x0 api.platform.config.switch.0.bootCfg.spiTransferMode BSM_SCRATCH[0x149] |= value << 30
// 0x9100 LOAD 1 = 0x7 api.platform.config.switch.0.bootCfg.spiTransferSpeed BSM_SCRATCH[0x149] |= value << 27
// ==0x90f0 LOAD 1 = 0x0 api.platform.config.switch.0.bootCfg.spiTransferMode BSM_SCRATCH[0x149] |= value << 30
// ==0x9100 LOAD 1 = 0x7 api.platform.config.switch.0.bootCfg.spiTransferSpeed BSM_SCRATCH[0x149] |= value << 27
// (BSM_ARGS = BSM_SCRATCH[0x149])
// 0x9110 LOAD 1 = 0x1 ???? do pcie init? IF 0: JUMP 0x081b78: OTHERWISE BIG BLOCK INIT?
// 0x9120 LOAD 1 = 0x0 ???? IF 0: SOFT_RESET.EPLReset = 0, SOFT_RESET.SwitchReset = 0 (RESET) ELSE: JUMP 0x080464
//
// 0x9130 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.numberOfLanes
// ==0x9130 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.numberOfLanes
// 0x9160 LOAD 9 0, 4, 0, 4 ... ???? BSM_SCRATCH[0x13d]
// 0x9190 LOAD 9 = 0x0 ???? BSM_SCRATCH[0x13e] IF NOT 0: BAR4allowed = 0 ELSE (OPTION 0x92c0)
// 0x91c0 LOAD 9 ???? BSM_SCRATCH[0x13f] IF 0: JUMP 0x084da0 ELSE: PCIE_CTRL.RxLaneflipEn = 1
@ -171,10 +173,10 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
// 0x9290 LOAD 9 = 0x0 ???? Set TEST settings? PCIE_PORTLOGIC BSM_SCRATCH[0x146] IF 1: JUMP 0x084d94, else (OPTION 0x9190)
// 0x92c0 LOAD 9 = 0x0 ???? BSM_SCRATCH[0x15a] IF 0: init SR_IOV something?
// 0x92f0 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.gen
// ==0x92f0 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.gen
// 0x9320 LOAD 9 = 9x 0x000000FF ???? BSM_SCRATCH[0x155], (val & 0x000000ff) << 0x10 something PCIe value?
// 0x9350 LOAD 9 ???? BSM_SCRATCH[0x17e], (val & 0x000000ff) something PCIe value?
// 0x9380 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.ASPMEnable BSM_SCRATCH[0x17f] IF NOT 0: JUMP ELSE SET PCIE_CFG_PCIE_LINK_CAP.ActiveStateLinkPMSupport = 0
// ==0x9380 LOAD 9 api.platform.config.switch.0.bootCfg.pep.0.ASPMEnable BSM_SCRATCH[0x17f] IF NOT 0: JUMP ELSE SET PCIE_CFG_PCIE_LINK_CAP.ActiveStateLinkPMSupport = 0
//
// 0x93b0 LOAD 1 = 0x00 ???? IF 0: JUMP 0x080d38 ELSE WRITE BSM_SCRATCH[0x1b0] = 0x41000c ???? DEAD code?
// 0x93c0 LOAD 1 = 0x492550f0 PCIE_CLK_CTRL |= (value & 0xfffff0f0)
@ -189,6 +191,7 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
auto entry = config.getEntry("api.platform.config.switch.0.bootCfg.mgmtPep");
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()){
std::cout << "Patching bootCfg.mgmtPep and bootCfg.pep.bar4Allowed\n";
auto value = entry.getInteger();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x91f0);
@ -204,7 +207,10 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
bar4allowed = testEntry.getBool();
}
load->data[pepOffset] = bar4allowed && (pepOffset == value || value == -1);
//std::cout << " Patched PEP " << std::dec << pepOffset << " = 0x" << std::hex << std::setw(8) << std::setfill('0') << load->data[pepOffset] << " @ " << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << " Patched PEP " << std::dec << pepOffset << " = " << (load->data[pepOffset] ? "true" : "false") << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
}
}
@ -266,6 +272,191 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
}
}
{
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9130);
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(0x01c) && load->data.size() == 9) {
for(uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset){
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".numberOfLanes";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
uint32_t value = entry.getInteger();
if(load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[pepOffset] = value;
}
}
}
}
}
}
{
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x92f0);
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(0x075) && load->data.size() == 9) {
for(uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset){
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".gen";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
uint32_t value = entry.getInteger();
if(load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[pepOffset] = value;
}
}
}
}
}
}
{
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9380);
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(0x096) && load->data.size() == 9) {
for(uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset){
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".ASPMEnable";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueBool && !entry.value.empty()) {
bool value = entry.getBool();
if(load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[pepOffset] = value;
}
}
}
}
}
}
{
for(uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset){
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".enable";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueBool && !entry.value.empty()) {
bool value = entry.getBool();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9050 + pepOffset * 0x10);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if(load->data[0] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0] << " -> "
<< std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
}
}
}
}
}
{
for(auto pepOffset : std::vector<uint32_t>{0, 2, 4, 6}){
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".mode";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueBool && !entry.value.empty()) {
bool value = entry.getBool();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9010 + (pepOffset/2) * 0x10);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if(load->data[0] != value){
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
}
}
}
}
}
{
auto entry = config.getEntry("api.platform.config.switch.0.bootCfg.systimeClockSource");
if(entry.type == Configuration::ConfigurationNode::Type::ValueBool && !entry.value.empty()) {
bool value = entry.getBool();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9000);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if(load->data[0] != value){
std::cout << "Patching bootCfg.systimeClockSource" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
}
}
}
}
{
auto entry = config.getEntry("api.platform.config.switch.0.bootCfg.spiTransferMode");
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
uint32_t value = entry.getInteger();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x90f0);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if(load->data[0] != value){
std::cout << "Patching bootCfg.spiTransferMode" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
}
}
}
}
{
auto entry = config.getEntry("api.platform.config.switch.0.bootCfg.spiTransferSpeed");
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
uint32_t value = entry.getInteger();
for(auto baseOffset : baseOffsets){
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9100);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if(load->data[0] != value){
std::cout << "Patching bootCfg.spiTransferSpeed" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
}
}
}
}
// =========== Patching Ends ===========
std::ofstream patchedImage(patchedImageFile);