diff options
| author | Evan Lojewski <github@meklort.com> | 2020-09-22 22:32:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-22 22:32:54 -0600 |
| commit | f233b78cd99077646845b92b5193869044581d5c (patch) | |
| tree | cc720d7902dcce8d74e7d58616aaa1bfc2fb94c0 /utils/bcmflash | |
| parent | 3f6982672d2cf188c460ebd0d72638e7d47b1cfd (diff) | |
| download | bcm5719-ortega-f233b78cd99077646845b92b5193869044581d5c.tar.gz bcm5719-ortega-f233b78cd99077646845b92b5193869044581d5c.zip | |
bcmflash: Fix APE endianness when writing to a file. (#110)
Ensure that a newly-updated APE image is swapped as
required when writing to a file in addition to NVM.
This has been tested as working by
(1) extracting the firmware.fw file from nvm
(2) editing the firmware.fw file and adding in ape-port0.bin
(3) Writing firmware.fw back to hardware.
Diffstat (limited to 'utils/bcmflash')
| -rw-r--r-- | utils/bcmflash/main.cpp | 85 |
1 files changed, 35 insertions, 50 deletions
diff --git a/utils/bcmflash/main.cpp b/utils/bcmflash/main.cpp index 580bb9e..67bd16a 100644 --- a/utils/bcmflash/main.cpp +++ b/utils/bcmflash/main.cpp @@ -92,6 +92,8 @@ bool save_to_file(const char *filename, void *buffer, size_t size) int main(int argc, char const *argv[]) { bool extract = false; + bool should_write = false; + union { uint8_t bytes[NVRAM_SIZE]; @@ -366,35 +368,13 @@ int main(int argc, char const *argv[]) // TODO: update length (if changed); - if ("file" == options["target"]) - { - // write update file. - if (!save_to_file(options["filename"].c_str(), (char *)nvram.bytes, NVRAM_SIZE)) - { - exit(-1); - } - } - - if ("hardware" == options["target"]) - { - NVRam_acquireLock(); - - NVRam_enable(); - NVRam_enableWrites(); - - NVRam_write(0, nvram.words, NVRAM_SIZE / 4); - - NVRam_disableWrites(); - - NVRam_releaseLock(); - } + should_write = true; } else { cerr << " Unable to open file '" << options["stage1"] << "'" << endl; exit(-1); } - exit(0); } uint32_t *stage2_wd = &stage1_wd[(crc_word + 1)]; // immediately after stage1 crc @@ -517,6 +497,12 @@ int main(int argc, char const *argv[]) #endif } + // Ensure everything is in the correct endianness. + for (int i = 0; i < (new_ape_length - 4) / 4; i++) + { + ape_wd[i] = be32toh(ape_wd[i]); + } + uint32_t new_ape_crc = be32toh(~NVRam_crc(ape, ape_length - sizeof(uint32_t), 0xffffffff)); printf("New Length (bytes): 0x%08X\n", new_ape_length); @@ -526,40 +512,39 @@ int main(int argc, char const *argv[]) // TODO: update length (if changed); - if ("file" == options["target"]) - { - // write update file. - if (!save_to_file(options["filename"].c_str(), (char *)nvram.bytes, NVRAM_SIZE)) - { - exit(-1); - } - } + should_write = true; + } + else + { + cerr << " Unable to open file '" << options["ape"] << "'" << endl; + exit(-1); + } + } - if ("hardware" == options["target"]) + if (should_write) + { + if ("file" == options["target"]) + { + // write update file. + if (!save_to_file(options["filename"].c_str(), (char *)nvram.bytes, NVRAM_SIZE)) { - // Ensure everything is in the correct endianness. - for (int i = 0; i < new_ape_length / 4; i++) - { - ape_wd[i] = be32toh(ape_wd[i]); - } - - NVRam_acquireLock(); + exit(-1); + } + } + else if ("hardware" == options["target"]) + { + NVRam_acquireLock(); - NVRam_enable(); - NVRam_enableWrites(); + NVRam_enable(); + NVRam_enableWrites(); - NVRam_write(0, nvram.words, NVRAM_SIZE / 4); + NVRam_write(0, nvram.words, NVRAM_SIZE / 4); - NVRam_disableWrites(); + NVRam_disableWrites(); - NVRam_releaseLock(); - } - } - else - { - cerr << " Unable to open file '" << options["ape"] << "'" << endl; - exit(-1); + NVRam_releaseLock(); } + exit(0); } |

