From cbeb5cf1285083b05f43361c510aba69837d1f91 Mon Sep 17 00:00:00 2001 From: IveanEx Date: Fri, 6 Dec 2024 16:22:54 +0100 Subject: [PATCH] Fix MultiChip Bug --- Bender.yml | 4 +-- target/rtl/bootrom/src/bootrom.c | 25 +++++++++----- target/sim/sw/device/apps/common.mk | 1 - .../src/snax-test-integration.c | 22 ++++++------ target/sim/sw/host/apps/offload/src/offload.c | 34 ++++++++++++------- util/occamygen/occamygen.py | 19 +++++------ util/solder/solder.py | 2 +- 7 files changed, 60 insertions(+), 47 deletions(-) diff --git a/Bender.yml b/Bender.yml index 1884e2c44..2f0a885af 100644 --- a/Bender.yml +++ b/Bender.yml @@ -118,8 +118,8 @@ sources: files: - target/rtl/test/uartdpi/uartdpi.sv - target/sim_chip/testharness/testharness.sv - # - target/sim/test/bootrom.sv - - target/rtl/bootrom/bootrom.sv + - target/sim/test/bootrom.sv + # - target/rtl/bootrom/bootrom.sv - target/rtl/src/occamy_chip.sv diff --git a/target/rtl/bootrom/src/bootrom.c b/target/rtl/bootrom/src/bootrom.c index 390c60c5d..1cbe6970b 100644 --- a/target/rtl/bootrom/src/bootrom.c +++ b/target/rtl/bootrom/src/bootrom.c @@ -33,6 +33,7 @@ void delay_cycles(uint64_t cycle) { // Boot modes. enum boot_mode_t { + HALT, TARGET_CHIPID, UART, COPY_TO_REMOTE, @@ -67,16 +68,17 @@ void bootrom() { print_u8(address_prefix, target_chip_id); print_str(address_prefix, "\r\n\t Enter the number to select the mode: "); - print_str(address_prefix, "\r\n\t 1. Change the target remote Chip ID"); - print_str(address_prefix, "\r\n\t 2. Load from UART to 0x"); + print_str(address_prefix, "\r\n\t 1. Halt the CVA6 Core"); + print_str(address_prefix, "\r\n\t 2. Change the target remote Chip ID"); + print_str(address_prefix, "\r\n\t 3. Load from UART to 0x"); print_u48(address_prefix, remote_chip_mem_start_address); print_str(address_prefix, - "\r\n\t 3. Copy memory from local chip to remote chip"); + "\r\n\t 4. Copy memory from local chip to remote chip"); print_str(address_prefix, - "\r\n\t 4. Copy memory from remote chip to local chip"); - print_str(address_prefix, "\r\n\t 5. Print memory from 0x"); + "\r\n\t 5. Copy memory from remote chip to local chip"); + print_str(address_prefix, "\r\n\t 6. Print memory from 0x"); print_u48(address_prefix, remote_chip_mem_start_address); - print_str(address_prefix, "\r\n\t 6. Continue to Boot from 0x"); + print_str(address_prefix, "\r\n\t 7. Continue to Boot from 0x"); print_u48(address_prefix, local_chip_mem_start_address); print_str(address_prefix, "\r\n"); @@ -85,6 +87,11 @@ void bootrom() { char* cur = 0; switch (boot_mode) { + case HALT: + print_str(address_prefix, "\r\n\t CVA6 Core is Halted. "); + getchar(address_prefix); + __asm__ volatile("wfi"); + break; case TARGET_CHIPID: print_str(address_prefix, "\r\n\t Enter the target remote Chip ID: "); @@ -92,12 +99,12 @@ void bootrom() { cur = in_buf; target_chip_id = 0; while (*cur != '\0') { - if (*cur >= '0' || *cur <= '9') { + if (*cur >= '0' && *cur <= '9') { target_chip_id = (target_chip_id << 4) + *cur - '0'; - } else if (*cur >= 'A' || *cur <= 'F') { + } else if (*cur >= 'A' && *cur <= 'F') { target_chip_id = (target_chip_id << 4) + *cur - 'A' + 10; - } else if (*cur >= 'a' || *cur <= 'f') { + } else if (*cur >= 'a' && *cur <= 'f') { target_chip_id = (target_chip_id << 4) + *cur - 'a' + 10; } else { diff --git a/target/sim/sw/device/apps/common.mk b/target/sim/sw/device/apps/common.mk index dd5de1c06..5d94fcf9f 100644 --- a/target/sim/sw/device/apps/common.mk +++ b/target/sim/sw/device/apps/common.mk @@ -47,7 +47,6 @@ INCDIRS += $(SNRT_DIR)/../math/include BASE_LD = $(abspath $(SNRT_DIR)/base.ld) MEMORY_LD = $(abspath $(APPSDIR)/memory.ld) ORIGIN_LD = $(abspath $(BUILDDIR)/origin.ld) -BASE_LD = $(abspath $(SNRT_DIR)/base.ld) SNRT_LIB_DIR = $(abspath $(RUNTIME_DIR)/build/) SNRT_LIB_NAME = snRuntime SNRT_LIB = $(realpath $(SNRT_LIB_DIR)/lib$(SNRT_LIB_NAME).a) diff --git a/target/sim/sw/device/apps/snax/snax-test-integration/src/snax-test-integration.c b/target/sim/sw/device/apps/snax/snax-test-integration/src/snax-test-integration.c index 457f7511e..d50feffab 100644 --- a/target/sim/sw/device/apps/snax/snax-test-integration/src/snax-test-integration.c +++ b/target/sim/sw/device/apps/snax/snax-test-integration/src/snax-test-integration.c @@ -26,7 +26,7 @@ int main() { if (snrt_is_dm_core()) { tcdm0_start_addr = (uint64_t)snrt_cluster_base_addrl(); tcdm0_start_addr += (uint64_t)snrt_cluster_base_addrh() << 32; - printf("The C0 TCDM ADDR is %p%p \n", + printf("The C0 TCDM ADDR is %p%p \r\n", (uint8_t*)(tcdm0_start_addr >> 32), (uint8_t*)tcdm0_start_addr); } @@ -37,7 +37,7 @@ int main() { if (snrt_is_dm_core()) { tcdm1_start_addr = (uint64_t)snrt_cluster_base_addrl(); tcdm1_start_addr += (uint64_t)snrt_cluster_base_addrh() << 32; - printf("The C1 TCDM ADDR is %p%p \n", + printf("The C1 TCDM ADDR is %p%p \r\n", (uint8_t*)(tcdm1_start_addr >> 32), (uint8_t*)tcdm1_start_addr); } @@ -48,7 +48,7 @@ int main() { if (snrt_is_dm_core()) { test_data_start_addr = (uint64_t)test_data; test_data_start_addr += (uint64_t)snrt_cluster_base_addrh() << 32; - printf("[C0] Start to load data from %p%p \n", + printf("[C0] Start to load data from %p%p \r\n", (uint8_t*)(test_data_start_addr >> 32), (uint8_t*)test_data_start_addr); snrt_dma_start_1d_wideptr(tcdm0_start_addr, test_data_start_addr, @@ -62,7 +62,7 @@ int main() { // Thenc C1 fetches data from C0 if (snrt_cluster_idx() == 1) { if (snrt_is_dm_core()) { - printf("[C1] Start to load data from %p%p \n", + printf("[C1] Start to load data from %p%p \r\n", (uint8_t*)(tcdm0_start_addr >> 32), (uint8_t*)tcdm0_start_addr); snrt_dma_start_1d_wideptr(tcdm1_start_addr, tcdm0_start_addr, @@ -76,12 +76,12 @@ int main() { // Start to check if (snrt_cluster_idx() == 0) { if (snrt_cluster_core_idx() == 0) { - printf("C0 Checking the results\n"); + printf("C0 Checking the results\r\n"); for (int i = 0; i < length_data; i++) { if (((int8_t*)tcdm0_start_addr)[i] != test_data[i]) { err++; - printf("C0 data is incorrect!\n"); - printf("tcdm0[%d]=%d, test_data[%d]=%d\n", i, + printf("C0 data is incorrect!\r\n"); + printf("tcdm0[%d]=%d, test_data[%d]=%d\r\n", i, ((int8_t*)tcdm0_start_addr)[i], i, test_data[i]); return -1; } @@ -91,12 +91,12 @@ int main() { snrt_global_barrier(); if (snrt_cluster_idx() == 1) { if (snrt_cluster_core_idx() == 0) { - printf("C1 Checking the results\n"); + printf("C1 Checking the results\r\n"); for (int i = 0; i < length_data; i++) { if (((int8_t*)tcdm1_start_addr)[i] != test_data[i]) { err++; - printf("C1 data is incorrect!\n"); - printf("tcdm0[%d]=%d, test_data[%d]=%d\n", i, + printf("C1 data is incorrect!\r\n"); + printf("tcdm0[%d]=%d, test_data[%d]=%d\r\n", i, ((int8_t*)tcdm1_start_addr)[i], i, test_data[i]); return -1; } @@ -107,7 +107,7 @@ int main() { snrt_global_barrier(); if (snrt_cluster_idx() == 0) { if (snrt_is_dm_core()) { - printf("Checking all done! No error!\n"); + printf("Checking all done! No error!\r\n"); } } diff --git a/target/sim/sw/host/apps/offload/src/offload.c b/target/sim/sw/host/apps/offload/src/offload.c index 67273e5f4..5dd4b24d6 100644 --- a/target/sim/sw/host/apps/offload/src/offload.c +++ b/target/sim/sw/host/apps/offload/src/offload.c @@ -24,38 +24,46 @@ int main() { print_str(current_chip_address_prefix, "[Occamy] Enter target Chip ID: "); scan_str(current_chip_address_prefix, in_buf); print_str(current_chip_address_prefix, "\r\n"); - target_chip_id = 0; - for (char *cur = in_buf, target_chip_id = 0; *cur != '\0'; cur++) { - if (*cur >= '0' || *cur <= '9') { + char* cur = in_buf; + + while (*cur != '\0') { + if (*cur >= '0' && *cur <= '9') { target_chip_id = (target_chip_id << 4) + *cur - '0'; - } else if (*cur >= 'A' || *cur <= 'F') { + } else if (*cur >= 'A' && *cur <= 'F') { target_chip_id = (target_chip_id << 4) + *cur - 'A' + 10; - } else if (*cur >= 'a' || *cur <= 'f') { + } else if (*cur >= 'a' && *cur <= 'f') { target_chip_id = (target_chip_id << 4) + *cur - 'a' + 10; + } else { + print_str(current_chip_address_prefix, + "[Occamy] Invalid target chip ID. \r\n"); + scan_char(current_chip_address_prefix); + break; } + cur++; } + uintptr_t target_chip_address_prefix = (uintptr_t)get_chip_baseaddress(target_chip_id); comm_buffer_ptr = (comm_buffer_t*)(((uint64_t)&__narrow_spm_start) | target_chip_address_prefix); - print_str(current_chip_address_prefix, - "[Occamy] Snitch Communication Buffer is: "); - print_u48(current_chip_address_prefix, (uint64_t)comm_buffer_ptr); - print_str(current_chip_address_prefix, "\r\n"); + // print_str(current_chip_address_prefix, + // "[Occamy] Snitch Communication Buffer is: "); + // print_u48(current_chip_address_prefix, (uint64_t)comm_buffer_ptr); + // print_str(current_chip_address_prefix, "\r\n"); reset_and_ungate_quadrants_all(target_chip_id); - print_str(current_chip_address_prefix, "[Occamy] Snitch ungated. \r\n"); + // print_str(current_chip_address_prefix, "[Occamy] Snitch ungated. \r\n"); deisolate_all(target_chip_id); - print_str(current_chip_address_prefix, "[Occamy] Snitch deisolated. \r\n"); + // print_str(current_chip_address_prefix, "[Occamy] Snitch deisolated. \r\n"); // Enable interrupts to receive notice of job termination enable_sw_interrupts(); // Program Snitch entry point and communication buffer (*comm_buffer_ptr).lock = 0; (*comm_buffer_ptr).chip_id = current_chip_id; program_snitches(target_chip_id, comm_buffer_ptr); - print_str(current_chip_address_prefix, - "[Occamy] Snitch Jump Address Programmed. \r\n"); + // print_str(current_chip_address_prefix, + // "[Occamy] Snitch Jump Address Programmed. \r\n"); // Compiler fence to ensure Snitch entry point is // programmed before Snitches are woken up diff --git a/util/occamygen/occamygen.py b/util/occamygen/occamygen.py index cb5298760..08a0e9cab 100755 --- a/util/occamygen/occamygen.py +++ b/util/occamygen/occamygen.py @@ -370,23 +370,22 @@ def main(): no_loopback=True, context="soc", node=am_soc_narrow_xbar) + + # Default port: wide xbar (Should stay on the first position) + soc_narrow_xbar.add_output_entry("soc_wide", am_soc_wide_xbar) + soc_narrow_xbar.add_input("soc_wide") for i in range(nr_s1_quadrants): - # soc_narrow_xbar.add_output_symbolic_multi("s1_quadrant_{}".format(i), - # [("s1_quadrant_base_addr", - # "S1QuadrantAddressSpace"), - # ("s1_quadrant_cfg_base_addr", - # "S1QuadrantCfgAddressSpace")]) - soc_narrow_xbar.add_output_entry( - "s1_quadrant_{}".format(i), am_narrow_xbar_quadrant_s1[i]) + soc_narrow_xbar.add_output_symbolic_multi("s1_quadrant_{}".format(i), + [("ClusterBaseOffset", + "S1QuadrantAddressSpace"), + ("S1QuadrantCfgBaseOffset", + "S1QuadrantCfgAddressSpace")]) soc_narrow_xbar.add_input("s1_quadrant_{}".format(i)) soc_narrow_xbar.add_input("cva6") - soc_narrow_xbar.add_input("soc_wide") soc_narrow_xbar.add_input("periph") - # Default port: wide xbar - soc_narrow_xbar.add_output_entry("soc_wide", am_soc_wide_xbar) soc_narrow_xbar.add_output_entry("periph", am_soc_axi_lite_periph_xbar) soc_narrow_xbar.add_output_entry("spm_narrow", am_spm_narrow) soc_narrow_xbar.add_output_entry("sys_idma_cfg", am_sys_idma_cfg) diff --git a/util/solder/solder.py b/util/solder/solder.py index 60746a3ee..f48631031 100644 --- a/util/solder/solder.py +++ b/util/solder/solder.py @@ -1598,7 +1598,7 @@ def emit(self): for i, (idx, entries) in enumerate(self.symbolic_addrmap_multi): for base, length in entries: addrmap_lines.append( - " '{{ idx: {}, start_addr: {}[{i}], end_addr: {}[{i}] + {} }}".format( + " '{{ idx: {}, start_addr: {{chip_id_i, {}[39:0]}}, end_addr: {{chip_id_i, {{{} + {}}}[39:0] }} }}".format( idx, base, base, length, i=i)) addrmap += "{}\n}};\n".format(',\n'.join(addrmap_lines))