Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2228CC4338F for ; Thu, 12 Aug 2021 05:19:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E795060E9B for ; Thu, 12 Aug 2021 05:19:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E795060E9B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C108D80EEA; Thu, 12 Aug 2021 07:19:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="O/+i1Vup"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E089182D73; Thu, 12 Aug 2021 07:19:44 +0200 (CEST) Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 44CDA82C30 for ; Thu, 12 Aug 2021 07:19:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x529.google.com with SMTP id z11so7605510edb.11 for ; Wed, 11 Aug 2021 22:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=y01a0ivhUmnxTkwhTJah2LIyKJk0ntGE9pYWmTphm90=; b=O/+i1VupjCLgiZkE+1++xDeBoRQyrwLlSOndPHBf8nEWijgI0V89bcmAnO/vuitsrF eonEqKE8ng4itnqSaTKZ81J1JTPhvFKkBMAHBIBE5AX66EkAngBYMmy3ReswxTaE5evO IlCXsqf4YSo5FAHW3FI071GFpU2iDDD0mDK01RBpctxYPPYmcAuwDFBL4NBIFJ55Lijf NYOLQuspvmfLPhyGMYuHSwni/MVQnT98htwi41f+wBDOaQ6zqOCDNL/VWrqqMJMR74f4 vBtAVBwsUwZM2gZu1TKoROOF53CxEpdRUOw6Hp9UxzgnHskbPqgzGlcjapJE/jfIx5bq iJew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=y01a0ivhUmnxTkwhTJah2LIyKJk0ntGE9pYWmTphm90=; b=aF9S4wy3pz/XZt7WFvp1ZrRxs3O8vQPapr1Qa7TS8bgslK5Gqd4paZAImuS1o2TcQQ 0IWT/Aw6o0yHxuzMcLpuQoz8WxOb+xP/LVORgSBdvXTUiaeHmMR8/tcqTJw/mE1tCIIr oKihPlRnVQ4zMAl+yFY1HxGoFbBOEt3doXb0XyZ7okicO0WkCtBn7MmraZYdk7SiQ3XD pDyYBrjKHnw03AhHcHoMe59wW+FUB4lL04w//bVi5vX3ruZlxrsYxDJEwYF2SPM2DvnR TiNB5KKGjx3hEwejLTlE/mM0KEWxMnc/3jvKmuq8OVZDh9i7YfTktAp1ZdM1wHdRjQJp nUiQ== X-Gm-Message-State: AOAM532GC1npQRAomMKA6bu4geyGr/BtxMGp8c1k2eptxvRlNM95KFgn iXeUP0de4sZPq4NFtAB1xczyy/Dmsll4P9qj X-Google-Smtp-Source: ABdhPJxmkfYoDvc5n1zHWpdS+5QNoSaZO0wXVRCcZBap6MW7UU142rhNr/4TNhGmG1qfgerKT8BgVA== X-Received: by 2002:aa7:c585:: with SMTP id g5mr3284429edq.340.1628745573661; Wed, 11 Aug 2021 22:19:33 -0700 (PDT) Received: from ?IPv6:2a02:768:2307:40d6:f666:9af6:3fed:e53b? ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id ju5sm393390ejc.8.2021.08.11.22.19.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Aug 2021 22:19:33 -0700 (PDT) Subject: Re: [PATCH] zynqmp: restore the jtag interface To: Jorge Ramirez-Ortiz Cc: adrian.fiergolski@fastree3d.com, ibai.erkiaga-elorza@xilinx.com, sjg@chromium.org, t.karthik.reddy@xilinx.com, ricardo@foundries.io, u-boot@lists.denx.de References: <20210716171640.18879-1-jorge@foundries.io> From: Michal Simek Message-ID: Date: Thu, 12 Aug 2021 07:19:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210716171640.18879-1-jorge@foundries.io> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 7/16/21 7:16 PM, Jorge Ramirez-Ortiz wrote: > As a security feature, if boot.bin was configured for secure boot the > CSU will disable the JTAG interface on all cases. > > Some boards might rely on this interface for flashing to QSPI in which > case those systems might end up bricked during development. > > This commit attempts to restore the interface - if the CSU allows for it. sorry I missed this. > > Signed-off-by: Jorge Ramirez-Ortiz > --- > arch/arm/mach-zynqmp/Kconfig | 9 ++++++++ > arch/arm/mach-zynqmp/include/mach/hardware.h | 23 +++++++++++++------ > board/xilinx/zynqmp/zynqmp.c | 24 ++++++++++++++++++++ > 3 files changed, 49 insertions(+), 7 deletions(-) > > diff --git a/arch/arm/mach-zynqmp/Kconfig b/arch/arm/mach-zynqmp/Kconfig > index 39144d654e..1e551c0020 100644 > --- a/arch/arm/mach-zynqmp/Kconfig > +++ b/arch/arm/mach-zynqmp/Kconfig > @@ -149,6 +149,15 @@ config SPL_ZYNQMP_ALT_BOOTMODE_ENABLED > Overwrite bootmode selected via boot mode pins to tell SPL what should > be the next boot device. > > +config SPL_ZYNQMP_RESTORE_JTAG > + bool "Restore JTAG" > + depends on SPL > + default n no need for default n - that's default option anyway. > + help > + Booting SPL in secure mode causes the CSU to disable the JTAG interface > + even if no eFuses were burnt. This option restores the interface if > + possible. Indentation is weird. Please look at tabs/spaces. > + > config ZYNQ_SDHCI_MAX_FREQ > default 200000000 > > diff --git a/arch/arm/mach-zynqmp/include/mach/hardware.h b/arch/arm/mach-zynqmp/include/mach/hardware.h > index 3776499070..58822e3f25 100644 > --- a/arch/arm/mach-zynqmp/include/mach/hardware.h > +++ b/arch/arm/mach-zynqmp/include/mach/hardware.h > @@ -42,17 +42,20 @@ > struct crlapb_regs { > u32 reserved0[36]; > u32 cpu_r5_ctrl; /* 0x90 */ > - u32 reserved1[37]; > + u32 reserved1[7]; > + u32 dbg_lpd_ctrl; /* 0xB0 */ > + u32 reserved2[29]; > u32 timestamp_ref_ctrl; /* 0x128 */ > - u32 reserved2[53]; > + u32 reserved3[53]; > u32 boot_mode; /* 0x200 */ > - u32 reserved3_0[7]; > + u32 reserved4_0[7]; > u32 reset_reason; /* 0x220 */ > - u32 reserved3_1[6]; > + u32 reserved4_1[6]; > u32 rst_lpd_top; /* 0x23C */ > - u32 reserved4[4]; > + u32 rst_lpd_dbg; /* 0x240 */ > + u32 reserved5[3]; > u32 boot_pin_ctrl; /* 0x250 */ > - u32 reserved5[21]; > + u32 reserved6[21]; > }; > > #define crlapb_base ((struct crlapb_regs *)ZYNQMP_CRL_APB_BASEADDR) > @@ -141,9 +144,15 @@ struct apu_regs { > struct csu_regs { > u32 reserved0[4]; > u32 multi_boot; > - u32 reserved1[11]; > + u32 reserved1[7]; > + u32 jtag_chain_status_wr; > + u32 jtag_chain_status; > + u32 jtag_sec; > + u32 jtag_dap_cfg; > u32 idcode; > u32 version; > + u32 reserved2[3055]; > + u32 pcap_prog; > }; > > #define csu_base ((struct csu_regs *)ZYNQMP_CSU_BASEADDR) > diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c > index 1748fec2e4..feffda54e7 100644 > --- a/board/xilinx/zynqmp/zynqmp.c > +++ b/board/xilinx/zynqmp/zynqmp.c > @@ -355,6 +355,25 @@ static int multi_boot(void) > return 0; > } > > +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ZYNQMP_RESTORE_JTAG) > +static void restore_jtag(void) > +{ > + const u32 disable_security_gate = 0xff; > + const u32 setup_clock = 0x01002002; > + const u32 setup_jtag = 0x3; > + const u32 release_pl = 0x1; > + const u32 enable_debug = 0xff; > + const u32 do_reset = 0x0; All above should be just macros. Please put them to hardware.h > + > + writel(disable_security_gate, &csu_base->jtag_sec); > + writel(enable_debug, &csu_base->jtag_dap_cfg); > + writel(setup_jtag, &csu_base->jtag_chain_status_wr); > + writel(setup_clock, &crlapb_base->dbg_lpd_ctrl); > + writel(do_reset, &crlapb_base->rst_lpd_dbg); > + writel(release_pl, &csu_base->pcap_prog); > +} > +#endif > + > #define PS_SYSMON_ANALOG_BUS_VAL 0x3210 > #define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914 > > @@ -374,6 +393,11 @@ int board_init(void) > zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj, > zynqmp_pm_cfg_obj_size); > printf("Silicon version:\t%d\n", zynqmp_get_silicon_version()); > + > +#if defined(CONFIG_SPL_ZYNQMP_RESTORE_JTAG) > + /* the CSU disables the JTAG interface when secure boot is enabled */ > + restore_jtag(); > +#endif As checkpatch suggests WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible > #else > if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) > xilinx_read_eeprom(); > Thanks, Michal -- Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs