summaryrefslogtreecommitdiffstats
path: root/utils/bcmregtool
diff options
context:
space:
mode:
Diffstat (limited to 'utils/bcmregtool')
-rw-r--r--utils/bcmregtool/CMakeLists.txt5
-rw-r--r--utils/bcmregtool/apeloader/CMakeLists.txt66
-rw-r--r--utils/bcmregtool/apeloader/ape.h66
-rw-r--r--utils/bcmregtool/apeloader/ape.ld46
-rw-r--r--utils/bcmregtool/apeloader/main.c95
-rw-r--r--utils/bcmregtool/main.cpp152
6 files changed, 418 insertions, 12 deletions
diff --git a/utils/bcmregtool/CMakeLists.txt b/utils/bcmregtool/CMakeLists.txt
index e8d3f33..9a2200b 100644
--- a/utils/bcmregtool/CMakeLists.txt
+++ b/utils/bcmregtool/CMakeLists.txt
@@ -1,12 +1,15 @@
project(bcmregtool)
+
+add_subdirectory(apeloader)
+
add_definitions(-Wall -Werror)
set(SOURCES
main.cpp
)
simulator_add_executable(${PROJECT_NAME} ${SOURCES})
-target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD MII APE)
+target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD MII APE apeloader-binary)
target_link_libraries(${PROJECT_NAME} PRIVATE simulator OptParse elfio)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION .)
diff --git a/utils/bcmregtool/apeloader/CMakeLists.txt b/utils/bcmregtool/apeloader/CMakeLists.txt
new file mode 100644
index 0000000..80c8df8
--- /dev/null
+++ b/utils/bcmregtool/apeloader/CMakeLists.txt
@@ -0,0 +1,66 @@
+################################################################################
+###
+### @file CMakeLists.txt
+###
+### @project bcm5719
+###
+### @brief First binary stage for the bcm5719
+###
+################################################################################
+###
+################################################################################
+###
+### @copyright Copyright (c) 2018, Evan Lojewski
+### @cond
+###
+### All rights reserved.
+###
+### Redistribution and use in source and binary forms, with or without
+### modification, are permitted provided that the following conditions are met:
+### 1. Redistributions of source code must retain the above copyright notice,
+### this list of conditions and the following disclaimer.
+### 2. 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.
+### 3. 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 HOLDER 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.
+### @endcond
+################################################################################
+
+
+project(apeloader)
+
+# Firmware
+set(LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/ape.ld")
+arm_add_executable(${PROJECT_NAME}
+ main.c
+ )
+arm_linker_script(${PROJECT_NAME} ${LINKER_SCRIPT})
+
+target_link_libraries(${PROJECT_NAME} APE-arm)
+target_link_libraries(${PROJECT_NAME} bcm5719-arm)
+target_compile_options(${PROJECT_NAME} PRIVATE -nodefaultlibs)
+
+
+# Simulator add_executable
+# simulator_add_executable(sim-${PROJECT_NAME}
+ # init_hw.c
+ # main.c)
+
+# target_link_libraries(sim-${PROJECT_NAME} simulator)
+# target_link_libraries(sim-${PROJECT_NAME} NVRam MII VPD APE)
diff --git a/utils/bcmregtool/apeloader/ape.h b/utils/bcmregtool/apeloader/ape.h
new file mode 100644
index 0000000..d4c9ae6
--- /dev/null
+++ b/utils/bcmregtool/apeloader/ape.h
@@ -0,0 +1,66 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @file stage1.h
+///
+/// @project
+///
+/// @brief Functions provided by stage1.
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @copyright Copyright (c) 2018, Evan Lojewski
+/// @cond
+///
+/// All rights reserved.
+///
+/// Redistribution and use in source and binary forms, with or without
+/// modification, are permitted provided that the following conditions are met:
+/// 1. Redistributions of source code must retain the above copyright notice,
+/// this list of conditions and the following disclaimer.
+/// 2. 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.
+/// 3. 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 HOLDER 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.
+/// @endcond
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef APE_H
+#define APE_H
+
+// #include <bcm5719_eeprom.h>
+// #include <bcm5719_GEN.h>
+
+// void early_init_hw(void);
+// void load_nvm_config(NVRAMContents_t *nvram);
+// void init_hw(NVRAMContents_t *nvram);
+
+#define STATUS_MAIN (0x8234700u)
+#define STATUS_EARLY_INIT (0x8234800u)
+#define STATUS_NVM_CONFIG (0x8234900u)
+#define STATUS_INIT_HW (0x8234A00u)
+
+// static inline void reportStatus(uint32_t code, uint8_t step)
+// {
+// GEN.GenDataSig.r32 = (code | step);
+// }
+
+
+#endif /* APE_H */
diff --git a/utils/bcmregtool/apeloader/ape.ld b/utils/bcmregtool/apeloader/ape.ld
new file mode 100644
index 0000000..3b26fae
--- /dev/null
+++ b/utils/bcmregtool/apeloader/ape.ld
@@ -0,0 +1,46 @@
+OUTPUT_FORMAT(binary)
+ENTRY(__start)
+
+SECTIONS
+{
+ .text 0x00100000 : ALIGN(4) SUBALIGN(4)
+ {
+ KEEP(*(.init))
+ *(.text)
+ }
+
+
+ .data . : ALIGN(4) SUBALIGN(4)
+ {
+ *(.data*)
+ *(.rodata*)
+ }
+
+ _fbss = .;
+ .bss . : ALIGN(4) SUBALIGN(4)
+ {
+ *(.bss*)
+ }
+ _ebss = .;
+
+
+ .stack . (NOLOAD) : ALIGN(4) SUBALIGN(4)
+ {
+ _fstack = .;
+ _estack = 00118000;
+ }
+
+
+ /DISCARD/ :
+ {
+ *(.comment)
+ *(.note.GNU-stack)
+ *(.eh_frame)
+ *(.got)
+ *(.ARM.exidx*)
+ *(.reginfo)
+ *(.mdebug.abi32)
+ *(.pdr)
+ }
+}
+
diff --git a/utils/bcmregtool/apeloader/main.c b/utils/bcmregtool/apeloader/main.c
new file mode 100644
index 0000000..71e25c5
--- /dev/null
+++ b/utils/bcmregtool/apeloader/main.c
@@ -0,0 +1,95 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @file main.c
+///
+/// @project
+///
+/// @brief Main stage1 code
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @copyright Copyright (c) 2018, Evan Lojewski
+/// @cond
+///
+/// All rights reserved.
+///
+/// Redistribution and use in source and binary forms, with or without
+/// modification, are permitted provided that the following conditions are met:
+/// 1. Redistributions of source code must retain the above copyright notice,
+/// this list of conditions and the following disclaimer.
+/// 2. 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.
+/// 3. 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 HOLDER 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.
+/// @endcond
+////////////////////////////////////////////////////////////////////////////////
+
+#include "ape.h"
+
+#include <APE_SHM.h>
+
+int __start()
+{
+ // Update SHM.Sig to signal ready.
+ SHM.SegSig.bits.Sig = SHM_SEG_SIG_SIG_LOADER;
+ SHM.FwStatus.bits.Ready = 1;
+
+ for(;;)
+ {
+ uint32_t command = SHM.LoaderCommand.bits.Command;
+ if(!command) continue;
+
+ uint32_t arg0 = SHM.LoaderArg0.r32;
+ uint32_t arg1 = SHM.LoaderArg1.r32;
+
+ switch(command)
+ {
+ default:
+ break;
+
+ case SHM_LOADER_COMMAND_COMMAND_READ_MEM:
+ {
+ // Read word address specified in arg0
+ uint32_t* addr = ((void*)arg0);
+ SHM.LoaderArg0.r32 = *addr;
+ break;
+ }
+ case SHM_LOADER_COMMAND_COMMAND_WRITE_MEM:
+ {
+ // Write word address specified in arg0 with arg1
+ uint32_t* addr = ((void*)arg0);
+ *addr = arg1;
+ break;
+ }
+ case SHM_LOADER_COMMAND_COMMAND_CALL:
+ {
+ // call address specified in arg0.
+ void (*function)(uint32_t) = ((void*)arg0);
+ function(arg1);
+ break;
+ }
+ }
+
+ // Mark command as handled.
+ SHM.LoaderCommand.bits.Command = 0;
+ }
+
+} \ No newline at end of file
diff --git a/utils/bcmregtool/main.cpp b/utils/bcmregtool/main.cpp
index 24fff7f..5f326e0 100644
--- a/utils/bcmregtool/main.cpp
+++ b/utils/bcmregtool/main.cpp
@@ -90,6 +90,45 @@ const char* regnames[32] = {
"$ra", /* return address */
};
+
+void boot_ape_loader()
+{
+ extern unsigned char apeloader_bin[];
+ extern unsigned int apeloader_bin_len;
+
+ int numWords = apeloader_bin_len/4;
+
+ RegAPEMode_t mode = APE.Mode;
+ mode.bits.Halt = 1;
+ mode.bits.FastBoot = 1;
+ APE.Mode = mode;
+
+ // We hijack the complete SHM here.
+
+
+ // load file.
+ for(int i = 0; i < numWords; i++)
+ {
+ SHM.write(0x0B00 + i*4, ((uint32_t*)apeloader_bin)[i]);
+
+ printf("SHM[%d]: 0x%08X ?= 0x%08X\n", i, SHM.read(0x0B00 + i*4), ((uint32_t*)apeloader_bin)[i]);
+ }
+
+
+ // Mark fw as not read.
+ SHM.FwStatus.bits.Ready = 0;
+ // Start the file
+ APE.GpioMessage.r32 = 0x60220B00|2;
+
+ mode.bits.Halt = 0;
+ mode.bits.FastBoot = 1;
+ mode.bits.Reset = 1;
+ APE.Mode = mode;
+
+ // Wait for ready.
+ while(0 == SHM.FwStatus.bits.Ready);
+}
+
const string symbol_for_address(uint32_t address, uint32_t &offset)
{
Elf_Half sec_num = gELFIOReader.sections.size();
@@ -317,6 +356,11 @@ int main(int argc, char const *argv[])
.action("store_true")
.help("Print ape information registers.");
+ parser.add_option("-p", "--apeboot")
+ .dest("apeboot")
+ .metavar("APE_FILE")
+ .help("File to boot on the APE.");
+
parser.add_option("-m", "--mii")
.dest("mii")
.set_default("0")
@@ -439,6 +483,91 @@ int main(int argc, char const *argv[])
exit(0);
}
+ if(options.is_set("apeboot"))
+ {
+ boot_ape_loader();
+
+ int fileLength = 0;
+ int fileWords = 0;
+ #define NVRAM_SIZE (1024u * 256u) /* 256KB */
+
+ union {
+ uint8_t bytes[NVRAM_SIZE];
+ uint32_t words[NVRAM_SIZE/4];
+ } ape;
+
+ string &file = options["apeboot"];
+
+ fstream infile;
+ infile.open(file, fstream::in | fstream::binary);
+ if(infile.is_open())
+ {
+ // get length of file:
+ infile.seekg(0, infile.end);
+ fileLength = infile.tellg();
+ fileWords = fileLength / 4;
+ infile.seekg(0, infile.beg);
+
+ // Read in file
+ infile.read((char*)ape.bytes, fileLength);
+
+ infile.close();
+ }
+ else
+ {
+ cerr << " Unable to open file '" << file << "'" << endl;
+ exit(-1);
+ }
+
+ if(ape.words[0] == be32toh(APE_HEADER_MAGIC))
+ {
+ // The file is swapped... fix it.
+ for(int i = 0; i < sizeof(ape)/sizeof(ape.words[0]); i++)
+ {
+ ape.words[i] = be32toh(ape.words[i]);
+ }
+ }
+
+ RegAPEMode_t mode = APE.Mode;
+ mode.bits.Halt = 1;
+ mode.bits.FastBoot = 1;
+ APE.Mode = mode;
+
+ // We hijack the complete SHM here.
+
+
+ // load file.
+ for(int i = 0; i < fileWords; i++)
+ {
+ SHM.write(0x0B00 + i*4, ape.words[i]);
+
+ printf("SHM[%d]: 0x%08X ?= 0x%08X\n", i, SHM.read(0x0B00 + i*4), ape.words[i]);
+
+ // DEVICE.ApeMemoryBase.r32 = 0xD800 + (i * 4);
+ // DEVICE.ApeMemoryData.r32 = ape.words[i];
+ }
+
+
+
+ // Start the file
+ APE.GpioMessage.r32 = 0x60220B00|2;
+
+ // DEVICE.ApeMemoryBase.r32 = 0xD800;
+ // printf("APE Memory Base: 0x%08X\n", (uint32_t)DEVICE.ApeMemoryBase.r32);
+ // printf("APE Memory Data: 0x%08X\n", (uint32_t)DEVICE.ApeMemoryData.r32);
+ // DEVICE.ApeMemoryData.r32 = ape.words[0];
+ // printf("APE Memory Base: 0x%08X\n", (uint32_t)DEVICE.ApeMemoryBase.r32);
+ // printf("APE Memory Data: 0x%08X\n", (uint32_t)DEVICE.ApeMemoryData.r32);
+ // printf("ape.words[0]: 0x%08X\n", (uint32_t)ape.words[0]);
+
+ mode.bits.Halt = 0;
+ mode.bits.FastBoot = 1;
+ mode.bits.Reset = 1;
+ APE.Mode = mode;
+
+ exit(0);
+ }
+
if(options.get("ape"))
{
APE.Mode.print();
@@ -449,6 +578,7 @@ int main(int argc, char const *argv[])
SHM.FwVersion.print();
printf("APE SegSig: 0x%08X\n", (uint32_t)SHM.SegSig.r32);
+ printf("APE SegLen: 0x%08X\n", (uint32_t)SHM.ApeSegLength.r32);
printf("APE RcpuApeResetCount: 0x%08X\n", (uint32_t)SHM.RcpuApeResetCount.r32);
printf("APE RCPU SegSig: 0x%08X\n", (uint32_t)SHM.RcpuSegSig.r32);
@@ -462,19 +592,19 @@ int main(int argc, char const *argv[])
printf("RegAPENcsiChannel0CtrlstatRx: 0x%08X\n", (uint32_t)SHM.NcsiChannel0CtrlstatRx.r32);
+ // boot_ape_loader();
+ // printf("Loader Command: 0x%08X\n", (uint32_t)SHM.LoaderCommand.r32);
+ // printf("Loader Arg0: 0x%08X\n", (uint32_t)SHM.LoaderArg0.r32);
+ // printf("Loader Arg1: 0x%08X\n", (uint32_t)SHM.LoaderArg1.r32);
- // Ensure all APE locks are released.
- // APE_releaseAllLocks();
-
+ // SHM.LoaderArg0.r32 = 0x00100040;
+ // SHM.LoaderCommand.bits.Command = SHM_LOADER_COMMAND_COMMAND_READ_MEM;
- APE.PerLockGrantPhy0.print();
- APE.PerLockGrantGrc.print();
- APE.PerLockGrantPhy1.print();
- APE.PerLockGrantPhy2.print();
- APE.PerLockGrantMem.print();
- APE.PerLockGrantPhy3.print();
- APE.PerLockGrantPort6.print();
- APE.PerLockGrantGpio.print();
+ // // Wait for command to be handled.
+ // while(0 != SHM.LoaderCommand.bits.Command);
+ // printf("Loader Command: 0x%08X\n", (uint32_t)SHM.LoaderCommand.r32);
+ // printf("Loader Arg0: 0x%08X\n", (uint32_t)SHM.LoaderArg0.r32);
+ // printf("Loader Arg1: 0x%08X\n", (uint32_t)SHM.LoaderArg1.r32);
exit(0);
}
OpenPOWER on IntegriCloud