From ad3b17431101d40817adf11c4be9f677514b7ecd Mon Sep 17 00:00:00 2001 From: devenrao Date: Sun, 4 Feb 2024 19:23:33 +0530 Subject: [PATCH] modify to use different device tree for rainier and everest 1) Rainier and everest uses different port mapping so modified to use different device trees for everest and rainier 2) Modified to use fapi_pos over ocmb index for determining the backend sbefifo target Tested: ----rainxx test result--- odyssey p[3] mp[0] perv[8] p[26] mp[0] perv[8] p[27] mp[0] perv[8] root@xxxx:/tmp# getscom odyssey 08012400 -all pdbg_default_dtb PDBG_BACKEND_SBEFIFO ***sbefifo_target system type returned is Rainier 4U ****sbefifo_target - loading bmc sbefifo rainier target sbefifo_ocmb_getscom odyssey k0:n0:s0:p03 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p26 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p27 0x0008000000000000 /usr/bin/edbg getscom odyssey 08012400 -all ---rainxx test result----- ecmdquery chips -dc odyssey p[4] mp[0,1] perv[8] p[5] mp[0,1] perv[8] root@xxx:/tmp# getscom odyssey 08012400 -all system type returned is Rainier 2U loading bmc sbefifo rainier target sbefifo_ocmb_getscom odyssey k0:n0:s0:p04 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p05 0x0008000000000000 /usr/bin/edbg getscom odyssey 08012400 -all ------everest---------------- odyssey p[2] mp[0,1] perv[8] p[3] mp[0,1] perv[8] p[34] mp[0,1] perv[8] p[35] mp[0,1] perv[8] root@xxxx:~# getscom odyssey 08012400 -all pdbg_default_dtb PDBG_BACKEND_SBEFIFO ***sbefifo_target system type returned is Everest **** sbefifo_target - loading bmc sbefifo everest target sbefifo_ocmb_getscom odyssey k0:n0:s0:p02 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p03 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p34 0x0008000000000000 sbefifo_ocmb_getscom odyssey k0:n0:s0:p35 0x0008000000000000 /usr/bin/edbg getscom odyssey 08012400 -all Signed-off-by: Marri Devender Rao Change-Id: I832b5b71351a5d34a9c9223753ef211caf51731c --- libpdbg/dtb.c | 118 +++++++++++++++++++++++++++++++++++++++++++---- libpdbg/target.c | 6 ++- 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 2ca99f3df..953ea3f1e 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -40,13 +40,16 @@ #include "p9r-fsi.dt.h" #include "p9z-fsi.dt.h" #include "bmc-kernel.dt.h" +#include "bmc-kernel-rainier.dt.h" +#include "bmc-kernel-everest.dt.h" #include "p8-host.dt.h" #include "p9-host.dt.h" #include "p10-host.dt.h" #include "p8-cronus.dt.h" #include "cronus.dt.h" #include "bmc-sbefifo.dt.h" - +#include "bmc-sbefifo-rainier.dt.h" +#include "bmc-sbefifo-everest.dt.h" #include "p8.dt.h" #include "p9.dt.h" #include "p10.dt.h" @@ -60,6 +63,9 @@ static const char *pdbg_backend_option; static const uint16_t ODYSSEY_CHIP_ID = 0x60C0; static const uint8_t ATTR_TYPE_OCMB_CHIP = 75; +static const char* RAINIER_2U = "Rainier 2U"; +static const char* RAINIER_4U = "Rainier 4U"; +static const char* EVEREST = "Everest"; static struct pdbg_dtb pdbg_dtb = { .backend = { @@ -107,6 +113,44 @@ static bool get_chipid(uint32_t *chip_id) return true; } +static char* get_p10_system_type() +{ + FILE* file = fopen("/proc/device-tree/model", "r"); + if (file == NULL) { + pdbg_log(PDBG_ERROR, "Unable to read device-tree model file: %s", strerror(errno)); + return ""; + } + + // Determine the size of the file + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Allocate memory for the file content + char* buffer = (char*)malloc(file_size + 1); + + if (buffer == NULL) { + pdbg_log(PDBG_ERROR, "Memory allocation failed"); + return ""; + } + + // Read the file content into the buffer + size_t bytes_read = fread(buffer, 1, file_size, file); + + if (bytes_read != file_size) { + pdbg_log(PDBG_ERROR, "Error reading file"); + return ""; + } + + // Null-terminate the buffer to create a valid C-string + buffer[bytes_read] = '\0'; + + // Close the file + fclose(file); + + return buffer; +} + /* Determines the most appropriate backend for the host system we are * running on. */ static enum pdbg_backend default_backend(void) @@ -258,8 +302,21 @@ static void bmc_target(struct pdbg_dtb *dtb) dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p10")) { pdbg_proc = PDBG_PROC_P10; - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; + if (!dtb->backend.fdt) { + char *system_type = get_p10_system_type(); + if (strcmp(system_type, EVEREST) == 0) { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel everest target"); + dtb->backend.fdt = &_binary_bmc_kernel_everest_dtb_o_start; + } else if (strcmp(system_type, RAINIER_2U) == 0 || + strcmp(system_type, RAINIER_4U) == 0) { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel rainier target"); + dtb->backend.fdt = &_binary_bmc_kernel_rainier_dtb_o_start; + } else { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel target"); + dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; + } + free(system_type); + } if (!dtb->system.fdt) dtb->system.fdt = &_binary_p10_dtb_o_start; } else { @@ -277,8 +334,21 @@ static void bmc_target(struct pdbg_dtb *dtb) case CHIP_ID_P10: pdbg_log(PDBG_INFO, "Found a POWER10 OpenBMC based system\n"); pdbg_proc = PDBG_PROC_P10; - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; + if (!dtb->backend.fdt) { + char *system_type = get_p10_system_type(); + if (strcmp(system_type, EVEREST) == 0) { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel everest target"); + dtb->backend.fdt = &_binary_bmc_kernel_everest_dtb_o_start; + } else if (strcmp(system_type, RAINIER_2U) == 0 || + strcmp(system_type, RAINIER_4U) == 0) { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel rainier target"); + dtb->backend.fdt = &_binary_bmc_kernel_rainier_dtb_o_start; + } else { + pdbg_log(PDBG_INFO, "bmc_target - loading bmc kernel target"); + dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; + } + free(system_type); + } if (!dtb->system.fdt) dtb->system.fdt = &_binary_p10_dtb_o_start; break; @@ -321,8 +391,23 @@ static void sbefifo_target(struct pdbg_dtb *dtb) dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p10")) { pdbg_proc = PDBG_PROC_P10; - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + if (!dtb->backend.fdt) { + char *system_type = get_p10_system_type(); + if (strcmp(system_type, EVEREST) == 0) { + pdbg_log(PDBG_INFO, + "sbefifo_target - loading bmc sbefifo everest target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_everest_dtb_o_start; + } else if (strcmp(system_type, RAINIER_2U) == 0 || + strcmp(system_type, RAINIER_4U) == 0) { + pdbg_log(PDBG_INFO, + "sbefifo_target - loading bmc sbefifo rainier target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_rainier_dtb_o_start; + } else { + pdbg_log(PDBG_INFO, "sbefifo_target - loading bmc sbefifo target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + } + free(system_type); + } if (!dtb->system.fdt) dtb->system.fdt = &_binary_p10_dtb_o_start; } else { @@ -340,8 +425,23 @@ static void sbefifo_target(struct pdbg_dtb *dtb) case CHIP_ID_P10: pdbg_log(PDBG_INFO, "Found a POWER10 OpenBMC based system\n"); pdbg_proc = PDBG_PROC_P10; - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + if (!dtb->backend.fdt) { + char *system_type = get_p10_system_type(); + if (strcmp(system_type, EVEREST) == 0) { + pdbg_log(PDBG_INFO, + "sbefifo_target - loading bmc sbefifo everest target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_everest_dtb_o_start; + } else if (strcmp(system_type, RAINIER_2U) == 0 || + strcmp(system_type, RAINIER_4U) == 0) { + pdbg_log(PDBG_INFO, + "sbefifo_target - loading bmc sbefifo rainier target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_rainier_dtb_o_start; + } else { + pdbg_log(PDBG_INFO, "sbefifo_target - loading bmc sbefifo target"); + dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + } + free(system_type); + } if (!dtb->system.fdt) dtb->system.fdt = &_binary_p10_dtb_o_start; break; diff --git a/libpdbg/target.c b/libpdbg/target.c index 6961f8649..b96321462 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -869,13 +869,15 @@ struct pdbg_target *get_backend_target(const char* class, uint32_t ocmb_proc = pdbg_target_index(pdbg_target_parent("proc", ocmb)); - uint32_t ocmb_index = pdbg_target_index(ocmb) % 0x8; + uint32_t fapi_pos = 0; + pdbg_target_get_attribute(ocmb, "ATTR_FAPI_POS", 4, 1, &fapi_pos); + fapi_pos = fapi_pos % 0x8; struct pdbg_target *target; pdbg_for_each_class_target(class, target) { uint32_t index = pdbg_target_index(target); uint32_t proc = 0; if(!pdbg_target_u32_property(target, "proc", &proc)) { - if(index == ocmb_index && proc == ocmb_proc) { + if(index == fapi_pos && proc == ocmb_proc) { return target; } }