From patchwork Thu Jun 25 06:25:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1316738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sqlW4b5Lz9sSJ for ; Thu, 25 Jun 2020 16:25:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=XhQQXwv2; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49sqlW3tRHzDqhn for ; Thu, 25 Jun 2020 16:25:59 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49sqlL1W7ZzDqgb for ; Thu, 25 Jun 2020 16:25:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=XhQQXwv2; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49sqlK6XJcz9s1x; Thu, 25 Jun 2020 16:25:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1593066350; bh=6D2DuSMTviyAt2id7pC5jtY0U6/JqieqRlq7VQWtwQk=; h=From:To:Cc:Subject:Date:From; b=XhQQXwv2Gv7dn3SHfdNyy0SKpfLGckAcxiD4JNbcoPUnvSsstm/Szo+0mfziCLYqX xFyxtSvsjmHgrLwy+6nQbrhR4xhuaSIkPd5L0b58MeJbET1IC8sAAhkTxCUI8aD+s4 LVMEXhl+n/HjzfoW7bHDc9EyZC+tnXjB2TmwkTA+FZhuxzENseFHoU+/4Yc/1ovDq7 uOmS0OhsM6V9I5Dh06fx4vAF44VHxcbXwwG/nS/37vUnZmaPHYNqAPYwZBWDDbuSeK ACI7Gd9sKyK0Bk9yI3NPB45p1MJjhxftEdQ0SibM+vuUQ4IIdD3BBO4hZ/pxd+G4uh QtTA74zUZipeg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 25 Jun 2020 16:25:43 +1000 Message-Id: <20200625062544.306406-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 1/2] libpdbg: Refactor code to get chip id X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- libpdbg/dtb.c | 58 +++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 6d9b182..3006cda 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -173,55 +173,63 @@ static void ppc_target(struct pdbg_dtb *dtb) } } -static void bmc_target(struct pdbg_dtb *dtb) +static uint32_t get_chipid(void) { FILE *cfam_id_file; char *path; - uint32_t cfam_id = 0; - uint32_t chip_id = 0; + uint32_t cfam_id = 0, chip_id; int rc; - if (pdbg_backend_option) { - if (!strcmp(pdbg_backend_option, "p8")) { - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; - if (!dtb->system.fdt) - dtb->system.fdt = &_binary_p8_dtb_o_start; - } else if (!strcmp(pdbg_backend_option, "p9")) { - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; - if (!dtb->system.fdt) - dtb->system.fdt = &_binary_p9_dtb_o_start; - } else { - pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); - pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9'\n"); - } - - return; - } - /* Try and determine the correct device type */ rc = asprintf(&path, "%s/fsi0/slave@00:00/cfam_id", kernel_get_fsi_path()); if (rc < 0) { pdbg_log(PDBG_ERROR, "Unable create fsi path"); - return; + return 0; } cfam_id_file = fopen(path, "r"); free(path); if (!cfam_id_file) { pdbg_log(PDBG_ERROR, "Unabled to open CFAM ID file\n"); - return; + return 0; } rc = fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id); if (rc != 1) { pdbg_log(PDBG_ERROR, "Unable to read CFAM ID: %s", strerror(errno)); fclose(cfam_id_file); - return; + return 0; } fclose(cfam_id_file); + chip_id = (cfam_id >> 4) & 0xff; + return chip_id; +} + +static void bmc_target(struct pdbg_dtb *dtb) +{ + uint32_t chip_id; + + if (pdbg_backend_option) { + if (!strcmp(pdbg_backend_option, "p8")) { + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; + } else if (!strcmp(pdbg_backend_option, "p9")) { + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; + } else { + pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); + pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9'\n"); + } + + return; + } + + chip_id = get_chipid(); switch(chip_id) { case CHIP_ID_P9: