From patchwork Fri Jul 19 09:45:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13737099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 806E5C3DA59 for ; Fri, 19 Jul 2024 09:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=G+46O4rQZG+afw+seJ1aSaqWCwYwoT6C2GKWC2dXu30=; b=XAaU3IjLrpEUZT7MoI8NILr/v2 Wl5jwNzTUl/6om0sjLDacVMDBaw3id8eYrAQaj89mVQj/ZpGvKfwGu6xyK36i5BnfJSCJWR0R7tUN nQpRosIkvQ1SSr+XLJmXM3DpBtTMsJfbh0w7XMbVxzo2NvpG/1QWiB/AMmxvlCM2++t20BFdkpJSx Un0qmA2UGiA4/c1r9b4RB5GNwHmiNAjhjpHEeBHmYJ7WMMih2WMkc00Y/8yKmJ91UZm/doXe1Ae6t rgrCbABULgHv6n1Dm5jf6jzd95iJXYedeUCfT2EhJXaLEs16tgkoWz1wvNkeRlihhqYvB22CsMmoO DZF+VUyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkBt-00000002I6l-0aEQ; Fri, 19 Jul 2024 09:46:17 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkBJ-00000002Hvf-3O7J for linux-arm-kernel@lists.infradead.org; Fri, 19 Jul 2024 09:45:43 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1fc5a93ce94so1841935ad.1 for ; Fri, 19 Jul 2024 02:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20230601.gappssmtp.com; s=20230601; t=1721382338; x=1721987138; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=G+46O4rQZG+afw+seJ1aSaqWCwYwoT6C2GKWC2dXu30=; b=0gx8L73mprAUH/u8XJpaR7ah0VONjnOTCD2Jyslfo026U3W0xad3wDMBdJZhf53kae XRfsKqV/1Lr8bKUXtxFg81+ohtl0Y8S2DYMvYfj4VMBnY3lDaNYjVbMpDRoI5liKCkyi 96jViEtEs2YnHxmHnXYlMC7SQSoCTRFBrEdjLF0ph3bfe5qYyT/2h37uVB3OaEAFSM+8 df6v/xwACM9El5dcrpkLSZMHjleJSBlUPn8uSu4TxbQqZF2r+QZlX8LtqNzn/iaERv/5 yKZKXlW2ZLBVF9ozCv8J8tE+aBimX1jccfQYRdn2oj3H4Z2VcmUyJBtY2pV1k31WKDdr tqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721382338; x=1721987138; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G+46O4rQZG+afw+seJ1aSaqWCwYwoT6C2GKWC2dXu30=; b=V3UyYD0dp/MDsK+7Jtp32+DmBC6eHdrhhGtbc8JbEh1h8HAn982y+n+2Pve8834sl9 EZ1XnF53UnXi1y5e90CDIUnWlgSzr5gOPZnxxvFAPa47X3hbLt/+B2M/JxYzp9WM645/ Lsazn0WPXYm96YB/2ZBFwk5dOdm+z1tJpnoOF5frzXMhsQlmDVz9kNKfObClAF6J4oE2 1hA/JTjFwPap1P5c5MNa5lYNJHYRtDF0txyu4d6jX4lKzXuoywPOTRW6ToI8giB4atsD jH+a8reHQ2F2ExTQez2e1jCK2YlklOp6ntgBsIWthEHRvGtiQox2t10mTWyJMjVxjPka XzDA== X-Forwarded-Encrypted: i=1; AJvYcCUilPWzi/+6BUJ+vTbJTHahnUzFWoHP1O7gcLrKcYej4i0HMwnjJy2ay72Snb8Bil9dYoJIbVuOpYsNgZSVX/9g@lists.infradead.org X-Gm-Message-State: AOJu0YxZkhT9w67qEJJBc92DnW1a7K6VCj9y5IF20uVfGhZ28+HHW2b2 SA7Avth2cfiLyTUga15RRQXVY/fqyVOQTEX5UKvCo1Inx9Gv2gqi48uvSg0eWg== X-Google-Smtp-Source: AGHT+IGTvpfyGkQSzcGiWO9xJsSuPVeVkrZ5bQM0dG5A4we5XMAn0a2gFht26kLa5ZsN/Jp0o9awzQ== X-Received: by 2002:a17:902:b195:b0:1fc:5b41:bb1b with SMTP id d9443c01a7336-1fd5ec8ab33mr13929205ad.4.1721382338043; Fri, 19 Jul 2024 02:45:38 -0700 (PDT) Received: from [127.0.0.1] ([2401:4900:8899:6437:d031:b9ec:7ff1:6aa1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f28f67esm819025ad.96.2024.07.19.02.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 02:45:37 -0700 (PDT) From: Ayush Singh Date: Fri, 19 Jul 2024 15:15:10 +0530 Subject: [PATCH 1/3] dt-bindings: net: ti,cc1352p7: Add boot-gpio MIME-Version: 1.0 Message-Id: <20240719-beagleplay_fw_upgrade-v1-1-8664d4513252@beagleboard.org> References: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> In-Reply-To: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> To: jkridner@beagleboard.org, robertcnelson@beagleboard.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ayush Singh X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1167; i=ayush@beagleboard.org; h=from:subject:message-id; bh=ShGVMtgc0hDJDLEQjlIXd5oij4dB7J9Ckvvpo/zXXW0=; b=owEBbQKS/ZANAwAIAQXO9ceJ5Vp0AcsmYgBmmjW1FCj3t80L4AIBRXHK9xB7rRLJ+43vNde2f nHTW8A6u9uJAjMEAAEIAB0WIQTfzBMe8k8tZW+lBNYFzvXHieVadAUCZpo1tQAKCRAFzvXHieVa dOQKD/97OqRvHiNgAtedUcGy81V44GNPmt+MwamaNqBs/ESpSxZaZCBUmXU4Ikq6jWKM50k3gPs noxPI8ZwpgwqTW7CHvQu+FwuugPwOVub4cAskF4MXDPP76puggUF0gL9/aXCPvEK+sXyuNbeLJL 6hmdiavzI1oqVENYVkxIBsbLxA96T9Dtsj39CMz8spOurWjl0IGziLRfXd8k1Dj9JfqCTwJHiNM x0FPeS+QYjzsoTVgrdowKLtqqevOvpCrMF3Shj1OvmMcC3qtA1/2UgIC1LZ+SDqh5JtkWZfvAE+ 0IeEPi+N4r5fIzon+OKlQOiHBrzTMp42V0T0+5IkV1DSPOL0oNS6tTqdWFsDs+iJYvi2y9wHidT W1jl8/kw9OkiiGlZBlUgCXw23HfXhaNzkzozWAAFEvJagEQbeYSSxyoKNnJfmGLIV3MKcMXnaRd RJAfOS3aJ1liKybxkDjWyGIQWXxpfDTxwgOLWS6rCzmJmY+5FHyGeRaM5wHlaeNSeDisOjD9Vyj Z+jwPRSmqHGM165PaH8qRilV0E1hv+fqYbIw+82m/ETIwS4kovzktB6Sr/6r46tj9WmNwSSqZP3 DGuLmkFSVdV26vPHrjce3pwcXqWtayCdAT4pbydSURatbZzt84eX6Fr5koTF0g8ZNLqGBH4RES9 Ot0J23ppRG8qbcw== X-Developer-Key: i=ayush@beagleboard.org; a=openpgp; fpr=DFCC131EF24F2D656FA504D605CEF5C789E55A74 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240719_024541_884099_86C50BAB X-CRM114-Status: GOOD ( 11.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org boot-gpio (along with reset-gpio) is used to enable bootloader backdoor for flashing new firmware. The pin and pin level to enabel bootloader backdoor is configed using the following CCFG variables in cc1352p7: - SET_CCFG_BL_CONFIG_BL_PIN_NO - SET_CCFG_BL_CONFIG_BL_LEVEL Signed-off-by: Ayush Singh --- Documentation/devicetree/bindings/net/ti,cc1352p7.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ti,cc1352p7.yaml b/Documentation/devicetree/bindings/net/ti,cc1352p7.yaml index 3dde10de4630..a3511bb59b05 100644 --- a/Documentation/devicetree/bindings/net/ti,cc1352p7.yaml +++ b/Documentation/devicetree/bindings/net/ti,cc1352p7.yaml @@ -29,6 +29,9 @@ properties: reset-gpios: maxItems: 1 + boot-gpios: + maxItems: 1 + vdds-supply: true required: @@ -46,6 +49,7 @@ examples: clocks = <&sclk_hf 0>, <&sclk_lf 25>; clock-names = "sclk_hf", "sclk_lf"; reset-gpios = <&pio 35 GPIO_ACTIVE_LOW>; + boot-gpios = <&pio 36 GPIO_ACTIVE_LOW>; vdds-supply = <&vdds>; }; }; From patchwork Fri Jul 19 09:45:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13737100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D901CC3DA59 for ; Fri, 19 Jul 2024 09:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jz9ch4dVrBxP6urYri9BwgC1U24Q+OuXsXlD8NvO7qw=; b=aLFL5jWSblqzUew/hLBBkucsnk WMiCv3DtaIKkrWGwpX9r3BuaBJZrrxk5Y1gxxALpWA9zuf/mFbH44pheNiiTUuRkTM4HjW1/g/1hc FmgGA+EUO56b3V9t58n7sEQ8b2/+hUZsJQ/6OGxlFUJW5lEMxH5d1YlC8DmgX9nOczzLiWDBbonix PtxzQ0J7KfqLLGW+tsVRKLoyZOGtqt4jy8pVIgXxZBQDXvXi6OpPuBjidise5452wavhSc5idj4U6 uEgr0O7GW2Uxtrahpc0ptCo2Y5fpsIWMljMe76fcLMS9jQL+LJyZZaoMtLHa/gvhJSAdaQ3pQXFPb TaKWJt8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkCC-00000002IE0-3P8b; Fri, 19 Jul 2024 09:46:36 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkBN-00000002Hwc-16PC for linux-arm-kernel@lists.infradead.org; Fri, 19 Jul 2024 09:45:46 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1fc5a93ce94so1842165ad.1 for ; Fri, 19 Jul 2024 02:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20230601.gappssmtp.com; s=20230601; t=1721382344; x=1721987144; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jz9ch4dVrBxP6urYri9BwgC1U24Q+OuXsXlD8NvO7qw=; b=GWKQgMoyYnNcLd6f7xMavXZY5ak/gX+VaIWd5h1ksZR2epqt8DgePPQkcXipRsIt63 dkOsmGZerzYl63SIt3nfsKaafdrTdpsDgigY9+ejFqNSJunndxnnbHaMvtKonHlQIpqB +vaKyqnSrqBqZQepIGKWCuZwy4fJvT5ka3uQeyXsDlppaSAm2T14zoY1eMhBl4xFoOyk TEYElv8MlKK5yfVdewHO2K2nIcONlZnFDmzuiDaIYk0osmWhaxaBCOqWVzgd1ZookORT p/b4H82vUqtTmuHnJf5LN2Hmwai/kMH7V2g2e7lxab9BCm3fJ4/50RS20ehSRHnESnSC aJhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721382344; x=1721987144; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jz9ch4dVrBxP6urYri9BwgC1U24Q+OuXsXlD8NvO7qw=; b=NB2busoNZBwokYsr5xI3X1h8zDN3L65ExN8MXOegr+Fo6H0ErrACi7G3rcE+puODwJ Mo6bmKl7XZ/aMkv43LNKV4omuMPaKOYNzZj0jGLF6uUlj/wOHxVJmPS7t66IibjIESKO M73cTnOYmxafiU5wHxRKirypKgUipGwnAwH6TrkVTSPri8T6DT9gQTOfN3oDd3V+xPQ4 CWKM2dnncnrHVeXw3hQ/h8pr3dCeb4QbVCdNNe5B7wuN1/1EyteypaHbjZwmx/WPsnBj SfEr6hwDvvDX7Pf65f/u1RzOjIKdl3SzEOHCgbDuk412X2JAgWsXoaeOs1FTM1/C+eFt GaUQ== X-Forwarded-Encrypted: i=1; AJvYcCWCdkVU4fCj254FbeKdCVERGv9Bex98Du6ZaJ2Zuqc7HhbN8C0Uw8wb9HbzuxBYmCEo29Fd7zrCWd2j96GeCxcNacn6VahRZgVmvG25NdbP8ranjMg= X-Gm-Message-State: AOJu0Yw8I6uB2y5uDgiAke6dhJcRokfPaR4nJtrs9QdiNT3awoWvsEIS raaY+ow2Zq5wapcRXfEdLZOd62+hTBIohnyjqDPrHMWBsEuDsxUfVaRS1jQ1aA== X-Google-Smtp-Source: AGHT+IG0Dk0pyXiY9meaZxdcfjUrxlBVZ658N6RulLlCRYXcYG3KDTx6qBif55oSv0WqFWNFaxs8wg== X-Received: by 2002:a17:902:b195:b0:1fc:5b41:bb1b with SMTP id d9443c01a7336-1fd5ec8ab33mr13930375ad.4.1721382344055; Fri, 19 Jul 2024 02:45:44 -0700 (PDT) Received: from [127.0.0.1] ([2401:4900:8899:6437:d031:b9ec:7ff1:6aa1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f28f67esm819025ad.96.2024.07.19.02.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 02:45:43 -0700 (PDT) From: Ayush Singh Date: Fri, 19 Jul 2024 15:15:11 +0530 Subject: [PATCH 2/3] arm64: dts: ti: k3-am625-beagleplay: Add boot-gpios to cc1352p7 MIME-Version: 1.0 Message-Id: <20240719-beagleplay_fw_upgrade-v1-2-8664d4513252@beagleboard.org> References: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> In-Reply-To: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> To: jkridner@beagleboard.org, robertcnelson@beagleboard.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ayush Singh X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=859; i=ayush@beagleboard.org; h=from:subject:message-id; bh=ktL075+vgq6cWYqcECtw9d1aoTJoi7kLRDiZQD8+fpM=; b=owEBbQKS/ZANAwAIAQXO9ceJ5Vp0AcsmYgBmmjW1ukKzxE3mHOQzG3KoTViMg43jWSqDVpuRC H3CShKNvxqJAjMEAAEIAB0WIQTfzBMe8k8tZW+lBNYFzvXHieVadAUCZpo1tQAKCRAFzvXHieVa dNvOD/4zxih/AxWFlgeOf8/JryAOSm7ENtd7lwPSWatsBhNCh8aGUlUXec9zUg0uiHPK4krGM8T oepqoAJuui8ay+aQw6MrhEDV01Yg0hIDh8iQLJiKnHUAXpLbTgjhhc3qFeQ7Mt1/MkHVD6Ga1yF k0d2dK0/ZpmaG5GNk2qc1iGnAPC68lfkmc2dDWiRTzCJDFoR7Hw1twsdC8yQ2Sx4qyfTcak21Nj uI/hFtwdfS66OqU8wOpTSiMGKgEtt8dsKlKkmNEkKPoAjxTuO1/AzbOhE2XNxk03ZPq3cCXyaJa zjsA65hVmS1OEFd8oiPQUJVwOp7yuyBelJWWw6nSoSbZAuGPPNQknjSg+J8dnrdP508nFlonKjv MIQh2p+Joh3hPnkEUZrC4u+6LsAvk9MsWCVHmgFmif7guLXCQghuEADsq3nMoBwyXsM4vdEVjYu 5MTSzqvORZG86x4p4xFlaGoWDAnhEa4aiB5CL/nuvmNg9WyX0S+4zbUM4h+WNYrOhKU5AVlynpG ETumL9S6LuuZHR8wzMyD9wFwEB0Uue8YRlNDmEwrRYY++aBD2mIHgqCoOu9zeb+YOXWwBpJkxJr TQoTwYMyuwOOxaIzNBBIlK/T4vJyz8QYvS7Sqaq/DVbHaJoK5SvYaLYCzHAHc4VH7E4ZLePim33 VBXzufQnYREtRHA== X-Developer-Key: i=ayush@beagleboard.org; a=openpgp; fpr=DFCC131EF24F2D656FA504D605CEF5C789E55A74 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240719_024545_339153_B0A37148 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add boot-gpios which is required for enabling bootloader backdoor for flashing firmware to cc1352p7. Also fix the incorrect reset-gpio. Signed-off-by: Ayush Singh --- arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts b/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts index 70de288d728e..6c9d1dc26379 100644 --- a/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts +++ b/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts @@ -888,7 +888,8 @@ &main_uart6 { mcu { compatible = "ti,cc1352p7"; - reset-gpios = <&main_gpio0 72 GPIO_ACTIVE_LOW>; + boot-gpios = <&main_gpio0 13 GPIO_ACTIVE_HIGH>; + reset-gpios = <&main_gpio0 14 GPIO_ACTIVE_HIGH>; vdds-supply = <&vdd_3v3>; }; }; From patchwork Fri Jul 19 09:45:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13737101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A9C3C3DA5D for ; Fri, 19 Jul 2024 09:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jyc63DhAsds9my1u5jTRhwrkGNr3acmqIU9G65AUunw=; b=LUMwEoTV5ROX4vyHX/NtYG7bP7 DwnQC6kwfNfbv1sfei3ZEKB8OIrIsB7eyoZpvKcnmgtjga7iFMNBwdKLgxHcS3SwBPYY6agLUA07a adTrp+vO6BKc21tnGMvwYdC8huJe/saJeGNOafxVRlB1I91dA4XvJfNinEZJ4C9iSrmFtE2Af5T+J Zx1rYyFvKkP9k+PJ871TF1c/e73t2mNrttwccN5xZr8+klJX5OcfA6MF//d1FtYq8Qhj3VX20SJQW 4dcOWOAtrmF/uwgdYPAlP0ZTgjN5sGth87T1JbwGaDUgVA1OTkXvflPeOkXqIjxy7MnAdXDHiw8Ma YSOqqmbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkCW-00000002ILW-1M52; Fri, 19 Jul 2024 09:46:56 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUkBT-00000002HyI-0taJ for linux-arm-kernel@lists.infradead.org; Fri, 19 Jul 2024 09:45:53 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1fc5a6147f3so1199985ad.2 for ; Fri, 19 Jul 2024 02:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20230601.gappssmtp.com; s=20230601; t=1721382350; x=1721987150; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jyc63DhAsds9my1u5jTRhwrkGNr3acmqIU9G65AUunw=; b=ZAsR5VTpqq1fKrUaNbjzmCSSj0zZ12PFbvF57KKBtJst8iLdXqtmV/UCP1jD049AMF vN9QRjxlqfEzOTtQizL7Au7iFE/NtHkKqGpKyTMy8jC6qpoeBa1A84LzaGpFqtqqjrfn v77F2+eeWAuf4efbiWi9WMOSahTM85gDM4XAXGwb7N6OmrXyz9Rr48qN1824LHYfZIqs G6VKCmkL87OzCYEJITBN7RVK9qimYRlnFogNz9uEGKRGGZI7FZI6LaJaRgvlaS8dNzPO cgoMwZD0qBddhW7o4t9a4IupY0K/QzCjWAhY3zsKJxb0GJojs8HAQqfWfR8WCLr/vuk+ H7MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721382350; x=1721987150; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jyc63DhAsds9my1u5jTRhwrkGNr3acmqIU9G65AUunw=; b=M9jkaWbJSliR87+KlQoD0xC/8Mf5LEmYkXIsaw1E/hA7BWR/OLF9Wwxoi6OXiOKHCr yNGrfRzmbgbp4g5abC6m9MHKLW7WO8XtEjNRTgOYc7p1SR7ld+XhzRYv0USwmDKZg+e4 F4juIhuj1sO8s6OWAdVkfZUBc9MrQQNCIy0DZnqFHDUKfuoYHNYqjY5X3wIrQrPjsy5L cwbYtGXotTiTdi8vLd+YFGEgqRFIPApHArPSEUXrzZ8ocT31PlX2zLvjBtiToAulqN0O TOtvaDWvAWPrXcqgHo+Fm6WW4QCtuja7I25FJRkF5yvkkP8lYrLLw/t9fOEPt7q80GqV N12w== X-Forwarded-Encrypted: i=1; AJvYcCXQTrGvaQv0yEbkJw3mHtLw+V31eokXYWdm1hGFDD0rrQMDsBIhDkXI3kZup5E2MzuHAYEKInz4GvCuLABBx8bYrWTOJQvv7QGCx/1bLeslvHJj+sk= X-Gm-Message-State: AOJu0YzXxzS32vM7vnLBzU1yxzAVPhbKa/gd3wDeR0u41m4Bd2MU9BaG 3VqO2kGMJh2WDrw9VjiagvauE+ak2zub3ISJWRHPX4ebWc5PDg+pcbvshcH+mg== X-Google-Smtp-Source: AGHT+IFD+1RXHKvtuvKKKF/QwlGwVg9eb2+NGk8HQJO77F0F9d1lDyN6BKrBBr9122fyEql2L5Y+xA== X-Received: by 2002:a17:902:d50a:b0:1fc:5b41:bac9 with SMTP id d9443c01a7336-1fd5ecadd1cmr14605685ad.7.1721382350211; Fri, 19 Jul 2024 02:45:50 -0700 (PDT) Received: from [127.0.0.1] ([2401:4900:8899:6437:d031:b9ec:7ff1:6aa1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f28f67esm819025ad.96.2024.07.19.02.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 02:45:49 -0700 (PDT) From: Ayush Singh Date: Fri, 19 Jul 2024 15:15:12 +0530 Subject: [PATCH 3/3] greybus: gb-beagleplay: Add firmware upload API MIME-Version: 1.0 Message-Id: <20240719-beagleplay_fw_upgrade-v1-3-8664d4513252@beagleboard.org> References: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> In-Reply-To: <20240719-beagleplay_fw_upgrade-v1-0-8664d4513252@beagleboard.org> To: jkridner@beagleboard.org, robertcnelson@beagleboard.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ayush Singh X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=21532; i=ayush@beagleboard.org; h=from:subject:message-id; bh=eOUi0IeBTEWZ4LJ6rjK5a0xfGZiaGzvCtL140SVme1k=; b=owEBbQKS/ZANAwAIAQXO9ceJ5Vp0AcsmYgBmmjW2RHOknJtQK3mgmQZ3YNy8KKpPiv5QLGsA8 p+Vi1E3ciGJAjMEAAEIAB0WIQTfzBMe8k8tZW+lBNYFzvXHieVadAUCZpo1tgAKCRAFzvXHieVa dAK2D/9ao/TkUA+2zVFxh+ewWL10zeq7rbjISlUTfhfbXWnhT39PXHgVuM2RvgGOmNsGF34jJF1 K6QRZ8UrrJW3eXxnyG//I5zw+Vr3utk7767IYwrsLErVAlrh4VTSZNWWjlTAtO8wBJuUPSIB2Ij IXvvOwKt2yuiYUXjqb/h8R202gdIYmZiJIqCDjKtDMBproWkXZ9Mh4vKRog1HKRsazPNLJCVm9D 0UnEr/Y9DlXP+jSYtKz4Ibz3bW1yDyEja30ggtHvZtNFgxHx+XWciozfXQCBXtJ8meTAc5QVYny VQYAwacLoMC1+FbIwYg44qeJV1HuQRYqHMytH+5OMbK8blgqR1UoNiXR7j8PMXzeiAK4TbET+Q0 nFFTHXmn4jPEgBhBx1jdoSjohPAb1NAfF3b/rpLXk4Gx3wjKW3ep6e7IkwU3ttV88A/h7MleVU1 Nm2juXftukQnGm4emuQPc1V86bpbm1v8L0dbCtJos8Z5UmZWurQnDeRW1cstVbJyX0b0CSD2n/f xj1c4+AovaqerOXD2U8hQHyzptFR9uhPTgBZ4bUOIN4Un5TsWLUUZDJOePGsO7exA5nHhA/ZGcc X59QFtKvg0oxDB1/PR44xz1+UG+nDZ/bOTkS4IdiJIkhimQb/pQ8JjFw9HfCVZ2EpQoXYDyWMdU IKkzyEOEseguBYw== X-Developer-Key: i=ayush@beagleboard.org; a=openpgp; fpr=DFCC131EF24F2D656FA504D605CEF5C789E55A74 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240719_024551_345270_37118165 X-CRM114-Status: GOOD ( 31.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Register with firmware upload API to allow updating firmware on cc1352p7 without resorting to overlay for using the userspace flasher. Communication with the bootloader can be moved out of gb-beagleplay driver if required, but I am keeping it here since there are no immediate plans to use the on-board cc1352p7 for anything other than greybus (BeagleConnect Technology). Additionally, there do not seem to any other devices using cc1352p7 or it's cousins as a co-processor. Boot and Reset GPIOs are used to enable cc1352p7 bootloader backdoor for flashing. The delays while starting bootloader are taken from the userspace flasher since the technical specification does not provide sufficient information regarding it. Flashing is skipped in case we are trying to flash the same image as the one that is currently present. This is determined by CRC32 calculation of the supplied firmware and Flash data. We also do a CRC32 check after flashing to ensure that the firmware was flashed properly. Link: https://www.ti.com/lit/ug/swcu192/swcu192.pdf Ti CC1352p7 Tecnical Specification Link: https://openbeagle.org/beagleconnect/cc1352-flasher Userspace Flasher Signed-off-by: Ayush Singh --- drivers/greybus/Kconfig | 1 + drivers/greybus/gb-beagleplay.c | 625 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 614 insertions(+), 12 deletions(-) diff --git a/drivers/greybus/Kconfig b/drivers/greybus/Kconfig index ab81ceceb337..d485a99959cb 100644 --- a/drivers/greybus/Kconfig +++ b/drivers/greybus/Kconfig @@ -21,6 +21,7 @@ config GREYBUS_BEAGLEPLAY tristate "Greybus BeaglePlay driver" depends on SERIAL_DEV_BUS select CRC_CCITT + select FW_UPLOAD help Select this option if you have a BeaglePlay where CC1352 co-processor acts as Greybus SVC. diff --git a/drivers/greybus/gb-beagleplay.c b/drivers/greybus/gb-beagleplay.c index 33f8fad70260..aecbfb5b5eaf 100644 --- a/drivers/greybus/gb-beagleplay.c +++ b/drivers/greybus/gb-beagleplay.c @@ -6,21 +6,18 @@ * Copyright (c) 2023 BeagleBoard.org Foundation */ -#include +#include +#include +#include +#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include #include #include -#include -#include + +#define CC1352_BOOTLOADER_TIMEOUT 2000 +#define CC1352_BOOTLOADER_ACK 0xcc +#define CC1352_BOOTLOADER_NACK 0x33 #define RX_HDLC_PAYLOAD 256 #define CRC_LEN 2 @@ -57,6 +54,17 @@ * @rx_buffer_len: length of receive buffer filled. * @rx_buffer: hdlc frame receive buffer * @rx_in_esc: hdlc rx flag to indicate ESC frame + * + * @fwl: underlying firmware upload device + * @boot_gpio: cc1352p7 boot gpio + * @rst_gpio: cc1352p7 reset gpio + * @flashing_mode: flag to indicate that flashing is currently in progress + * @fwl_ack_com: completion to signal an Ack/Nack + * @fwl_ack: Ack/Nack byte received + * @fwl_cmd_response_com: completion to signal a bootloader command response + * @fwl_cmd_response: bootloader command response data + * @fwl_crc32: crc32 of firmware to flash + * @fwl_reset_addr: flag to indicate if we need to send COMMAND_DOWNLOAD again */ struct gb_beagleplay { struct serdev_device *sd; @@ -72,6 +80,17 @@ struct gb_beagleplay { u16 rx_buffer_len; bool rx_in_esc; u8 rx_buffer[MAX_RX_HDLC]; + + struct fw_upload *fwl; + struct gpio_desc *boot_gpio; + struct gpio_desc *rst_gpio; + bool flashing_mode; + struct completion fwl_ack_com; + u8 fwl_ack; + struct completion fwl_cmd_response_com; + u32 fwl_cmd_response; + u32 fwl_crc32; + bool fwl_reset_addr; }; /** @@ -100,6 +119,69 @@ struct hdlc_greybus_frame { u8 payload[]; } __packed; +/** + * enum cc1352_bootloader_cmd: CC1352 Bootloader Commands + */ +enum cc1352_bootloader_cmd { + COMMAND_DOWNLOAD = 0x21, + COMMAND_GET_STATUS = 0x23, + COMMAND_SEND_DATA = 0x24, + COMMAND_RESET = 0x25, + COMMAND_CRC32 = 0x27, + COMMAND_BANK_ERASE = 0x2c, +}; + +/** + * enum cc1352_bootloader_status: CC1352 Bootloader COMMAND_GET_STATUS response + */ +enum cc1352_bootloader_status { + COMMAND_RET_SUCCESS = 0x40, + COMMAND_RET_UNKNOWN_CMD = 0x41, + COMMAND_RET_INVALID_CMD = 0x42, + COMMAND_RET_INVALID_ADR = 0x43, + COMMAND_RET_FLASH_FAIL = 0x44, +}; + +/** + * struct cc1352_bootloader_packet: CC1352 Bootloader Request Packet + * + * @len: length of packet + optional request data + * @checksum: 8-bit checksum excluding len + * @cmd: bootloader command + */ +struct cc1352_bootloader_packet { + u8 len; + u8 checksum; + u8 cmd; +} __packed; + +#define CC1352_BOOTLOADER_PKT_MAX_SIZE \ + (U8_MAX - sizeof(struct cc1352_bootloader_packet)) + +/** + * struct cc1352_bootloader_download_cmd_data: CC1352 Bootloader COMMAND_DOWNLOAD request data + * + * @addr: address to start programming data into + * @size: size of data that will be sent + */ +struct cc1352_bootloader_download_cmd_data { + __be32 addr; + __be32 size; +} __packed; + +/** + * struct cc1352_bootloader_crc32_cmd_data: CC1352 Bootloader COMMAND_CRC32 request data + * + * @addr: address where crc32 calculation starts + * @size: number of bytes comprised by crc32 calculation + * @read_repeat: number of read repeats for each data location + */ +struct cc1352_bootloader_crc32_cmd_data { + __be32 addr; + __be32 size; + __be32 read_repeat; +} __packed; + static void hdlc_rx_greybus_frame(struct gb_beagleplay *bg, u8 *buf, u16 len) { struct hdlc_greybus_frame *gb_frame = (struct hdlc_greybus_frame *)buf; @@ -331,11 +413,131 @@ static void hdlc_deinit(struct gb_beagleplay *bg) flush_work(&bg->tx_work); } +/** + * csum8: Calculate 8-bit checksum on data + */ +static u8 csum8(const u8 *data, size_t size, u8 base) +{ + size_t i; + u8 sum = base; + + for (i = 0; i < size; ++i) + sum += data[i]; + + return sum; +} + +static void cc1352_bootloader_send_ack(struct gb_beagleplay *bg) +{ + static const u8 ack[] = { 0x00, CC1352_BOOTLOADER_ACK }; + + serdev_device_write_buf(bg->sd, ack, sizeof(ack)); +} + +static void cc1352_bootloader_send_nack(struct gb_beagleplay *bg) +{ + static const u8 nack[] = { 0x00, CC1352_BOOTLOADER_NACK }; + + serdev_device_write_buf(bg->sd, nack, sizeof(nack)); +} + +/** + * cc1352_bootloader_pkt_rx: Process a CC1352 Bootloader Packet + * + * @bg: beagleplay greybus driver + * @data: packet buffer + * @count: packet buffer size + * + * @return: number of bytes processed + * + * Here are the steps to successfully receive a packet from cc1352 bootloader + * according to the docs: + * 1. Wait for nonzero data to be returned from the device. This is important + * as the device may send zero bytes between a sent and a received data + * packet. The first nonzero byte received is the size of the packet that is + * being received. + * 2. Read the next byte, which is the checksum for the packet. + * 3. Read the data bytes from the device. During the data phase, packet size + * minus 2 bytes is sent. + * 4. Calculate the checksum of the data bytes and verify it matches the + * checksum received in the packet. + * 5. Send an acknowledge byte or a not-acknowledge byte to the device to + * indicate the successful or unsuccessful reception of the packet. + */ +static int cc1352_bootloader_pkt_rx(struct gb_beagleplay *bg, const u8 *data, + size_t count) +{ + bool is_valid = false; + + switch (data[0]) { + /* Skip 0x00 bytes. */ + case 0x00: + return 1; + case CC1352_BOOTLOADER_ACK: + case CC1352_BOOTLOADER_NACK: + WRITE_ONCE(bg->fwl_ack, data[0]); + complete(&bg->fwl_ack_com); + return 1; + case 3: + if (count < 3) + return 0; + is_valid = data[1] == data[2]; + WRITE_ONCE(bg->fwl_cmd_response, (u32)data[2]); + break; + case 6: + if (count < 6) + return 0; + is_valid = csum8(&data[2], sizeof(__be32), 0) == data[1]; + WRITE_ONCE(bg->fwl_cmd_response, get_unaligned_be32(&data[2])); + break; + default: + return -EINVAL; + } + + if (is_valid) { + cc1352_bootloader_send_ack(bg); + complete(&bg->fwl_cmd_response_com); + } else { + dev_warn(&bg->sd->dev, + "Dropping bootloader packet with invalid checksum"); + cc1352_bootloader_send_nack(bg); + } + + return data[0]; +} + +static size_t cc1352_bootloader_rx(struct gb_beagleplay *bg, const u8 *data, + size_t count) +{ + int ret; + size_t off = 0; + + memcpy(bg->rx_buffer + bg->rx_buffer_len, data, count); + bg->rx_buffer_len += count; + + do { + ret = cc1352_bootloader_pkt_rx(bg, bg->rx_buffer + off, + bg->rx_buffer_len - off); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, ret, + "Invalid Packet"); + off += ret; + } while (ret > 0 && off < count); + + bg->rx_buffer_len -= off; + memmove(bg->rx_buffer, bg->rx_buffer + off, bg->rx_buffer_len); + + return count; +} + static size_t gb_tty_receive(struct serdev_device *sd, const u8 *data, size_t count) { struct gb_beagleplay *bg = serdev_device_get_drvdata(sd); + if (READ_ONCE(bg->flashing_mode)) + return cc1352_bootloader_rx(bg, data, count); + return hdlc_rx(bg, data, count); } @@ -343,7 +545,8 @@ static void gb_tty_wakeup(struct serdev_device *serdev) { struct gb_beagleplay *bg = serdev_device_get_drvdata(serdev); - schedule_work(&bg->tx_work); + if (!READ_ONCE(bg->flashing_mode)) + schedule_work(&bg->tx_work); } static struct serdev_device_ops gb_beagleplay_ops = { @@ -412,6 +615,192 @@ static void gb_beagleplay_stop_svc(struct gb_beagleplay *bg) hdlc_tx_frames(bg, ADDRESS_CONTROL, 0x03, &payload, 1); } +static int cc1352_bootloader_wait_for_ack(struct gb_beagleplay *bg) +{ + int ret; + + ret = wait_for_completion_timeout( + &bg->fwl_ack_com, msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT)); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, ret, + "Failed to acquire ack semaphore"); + + switch (READ_ONCE(bg->fwl_ack)) { + case CC1352_BOOTLOADER_ACK: + return 0; + case CC1352_BOOTLOADER_NACK: + return -EAGAIN; + default: + return -EINVAL; + } +} + +static int cc1352_bootloader_sync(struct gb_beagleplay *bg) +{ + static const u8 sync_bytes[] = { 0x55, 0x55 }; + + serdev_device_write_buf(bg->sd, sync_bytes, sizeof(sync_bytes)); + return cc1352_bootloader_wait_for_ack(bg); +} + +static int cc1352_bootloader_get_status(struct gb_beagleplay *bg) +{ + int ret; + static const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt), + .checksum = COMMAND_GET_STATUS, + .cmd = COMMAND_GET_STATUS + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + ret = cc1352_bootloader_wait_for_ack(bg); + if (ret < 0) + return ret; + + ret = wait_for_completion_timeout( + &bg->fwl_cmd_response_com, + msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT)); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, ret, + "Failed to acquire last status semaphore"); + + switch (READ_ONCE(bg->fwl_cmd_response)) { + case COMMAND_RET_SUCCESS: + return 0; + default: + return -EINVAL; + } + + return 0; +} + +static int cc1352_bootloader_erase(struct gb_beagleplay *bg) +{ + int ret; + static const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt), + .checksum = COMMAND_BANK_ERASE, + .cmd = COMMAND_BANK_ERASE + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + + ret = cc1352_bootloader_wait_for_ack(bg); + if (ret < 0) + return ret; + + return cc1352_bootloader_get_status(bg); +} + +static int cc1352_bootloader_reset(struct gb_beagleplay *bg) +{ + static const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt), + .checksum = COMMAND_RESET, + .cmd = COMMAND_RESET + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + + return cc1352_bootloader_wait_for_ack(bg); +} + +/** + * cc1352_bootloader_empty_pkt: Calculate the number of empty bytes in the current packet + */ +static size_t cc1352_bootloader_empty_pkt(const u8 *data, size_t size) +{ + size_t i; + + for (i = 0; i < size && data[i] == 0xff; ++i) + continue; + + return i; +} + +static int cc1352_bootloader_crc32(struct gb_beagleplay *bg, u32 *crc32) +{ + int ret; + static const struct cc1352_bootloader_crc32_cmd_data cmd_data = { + .addr = 0, .size = cpu_to_be32(704 * 1024), .read_repeat = 0 + }; + const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt) + sizeof(cmd_data), + .checksum = csum8((const void *)&cmd_data, sizeof(cmd_data), + COMMAND_CRC32), + .cmd = COMMAND_CRC32 + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + serdev_device_write_buf(bg->sd, (const u8 *)&cmd_data, + sizeof(cmd_data)); + + ret = cc1352_bootloader_wait_for_ack(bg); + if (ret < 0) + return ret; + + ret = wait_for_completion_timeout( + &bg->fwl_cmd_response_com, + msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT)); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, ret, + "Failed to acquire last status semaphore"); + + *crc32 = READ_ONCE(bg->fwl_cmd_response); + + return 0; +} + +static int cc1352_bootloader_download(struct gb_beagleplay *bg, u32 size, + u32 addr) +{ + int ret; + const struct cc1352_bootloader_download_cmd_data cmd_data = { + .addr = cpu_to_be32(addr), + .size = cpu_to_be32(size), + }; + const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt) + sizeof(cmd_data), + .checksum = csum8((const void *)&cmd_data, sizeof(cmd_data), + COMMAND_DOWNLOAD), + .cmd = COMMAND_DOWNLOAD + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + serdev_device_write_buf(bg->sd, (const u8 *)&cmd_data, + sizeof(cmd_data)); + + ret = cc1352_bootloader_wait_for_ack(bg); + if (ret < 0) + return ret; + + return cc1352_bootloader_get_status(bg); +} + +static int cc1352_bootloader_send_data(struct gb_beagleplay *bg, const u8 *data, + size_t size) +{ + int ret, rem = min(size, CC1352_BOOTLOADER_PKT_MAX_SIZE); + const struct cc1352_bootloader_packet pkt = { + .len = sizeof(pkt) + rem, + .checksum = csum8(data, rem, COMMAND_SEND_DATA), + .cmd = COMMAND_SEND_DATA + }; + + serdev_device_write_buf(bg->sd, (const u8 *)&pkt, sizeof(pkt)); + serdev_device_write_buf(bg->sd, data, rem); + + ret = cc1352_bootloader_wait_for_ack(bg); + if (ret < 0) + return ret; + + ret = cc1352_bootloader_get_status(bg); + if (ret < 0) + return ret; + + return rem; +} + static void gb_greybus_deinit(struct gb_beagleplay *bg) { gb_hd_del(bg->gb_hd); @@ -442,6 +831,154 @@ static int gb_greybus_init(struct gb_beagleplay *bg) return ret; } +static enum fw_upload_err cc1352_prepare(struct fw_upload *fw_upload, + const u8 *data, u32 size) +{ + int ret; + u32 curr_crc32; + struct gb_beagleplay *bg = fw_upload->dd_handle; + + dev_info(&bg->sd->dev, "CC1352 Start Flashing..."); + + /* Might involve network calls */ + gb_greybus_deinit(bg); + msleep(5 * MSEC_PER_SEC); + + gb_beagleplay_stop_svc(bg); + msleep(200); + flush_work(&bg->tx_work); + + serdev_device_wait_until_sent(bg->sd, CC1352_BOOTLOADER_TIMEOUT); + + WRITE_ONCE(bg->flashing_mode, true); + + gpiod_direction_output(bg->boot_gpio, 0); + gpiod_direction_output(bg->rst_gpio, 0); + msleep(200); + + gpiod_set_value(bg->rst_gpio, 1); + msleep(200); + + gpiod_set_value(bg->boot_gpio, 1); + msleep(200); + + gpiod_direction_input(bg->boot_gpio); + gpiod_direction_input(bg->rst_gpio); + + ret = cc1352_bootloader_sync(bg); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to sync"); + + ret = cc1352_bootloader_crc32(bg, &curr_crc32); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to fetch crc32"); + + bg->fwl_crc32 = crc32(0xffffffff, data, size) ^ 0xffffffff; + + /* Check if attempting to reflash same firmware */ + if (bg->fwl_crc32 == curr_crc32) { + dev_warn(&bg->sd->dev, "Skipping reflashing same image"); + cc1352_bootloader_reset(bg); + WRITE_ONCE(bg->flashing_mode, false); + msleep(200); + gb_greybus_init(bg); + gb_beagleplay_start_svc(bg); + return FW_UPLOAD_ERR_FW_INVALID; + } + + ret = cc1352_bootloader_erase(bg); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to erase"); + + bg->fwl_reset_addr = true; + + return FW_UPLOAD_ERR_NONE; +} + +static void cc1352_cleanup(struct fw_upload *fw_upload) +{ + struct gb_beagleplay *bg = fw_upload->dd_handle; + + WRITE_ONCE(bg->flashing_mode, false); +} + +static enum fw_upload_err cc1352_write(struct fw_upload *fw_upload, + const u8 *data, u32 offset, u32 size, + u32 *written) +{ + int ret; + size_t empty_bytes; + struct gb_beagleplay *bg = fw_upload->dd_handle; + + /* Skip 0xff packets. Significant performance improvement */ + empty_bytes = cc1352_bootloader_empty_pkt(data + offset, size); + if (empty_bytes >= CC1352_BOOTLOADER_PKT_MAX_SIZE) { + bg->fwl_reset_addr = true; + *written = empty_bytes; + return FW_UPLOAD_ERR_NONE; + } + + if (bg->fwl_reset_addr) { + ret = cc1352_bootloader_download(bg, size, offset); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, + FW_UPLOAD_ERR_HW_ERROR, + "Failed to send download cmd"); + + bg->fwl_reset_addr = false; + } + + ret = cc1352_bootloader_send_data(bg, data + offset, size); + if (ret < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to flash firmware"); + *written = ret; + + return FW_UPLOAD_ERR_NONE; +} + +static enum fw_upload_err cc1352_poll_complete(struct fw_upload *fw_upload) +{ + u32 curr_crc32; + struct gb_beagleplay *bg = fw_upload->dd_handle; + + if (cc1352_bootloader_crc32(bg, &curr_crc32) < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to fetch crc32"); + + if (bg->fwl_crc32 != curr_crc32) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_FW_INVALID, + "Invalid CRC32"); + + if (cc1352_bootloader_reset(bg) < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_HW_ERROR, + "Failed to reset"); + + dev_info(&bg->sd->dev, "CC1352 Flashing Successful"); + WRITE_ONCE(bg->flashing_mode, false); + msleep(200); + + if (gb_greybus_init(bg) < 0) + return dev_err_probe(&bg->sd->dev, FW_UPLOAD_ERR_RW_ERROR, + "Failed to initialize greybus"); + + gb_beagleplay_start_svc(bg); + + return FW_UPLOAD_ERR_NONE; +} + +static void cc1352_cancel(struct fw_upload *fw_upload) +{ + struct gb_beagleplay *bg = fw_upload->dd_handle; + + dev_info(&bg->sd->dev, "CC1352 Bootloader Cancel"); + + cc1352_bootloader_reset(bg); +} + static void gb_serdev_deinit(struct gb_beagleplay *bg) { serdev_device_close(bg->sd); @@ -463,6 +1000,65 @@ static int gb_serdev_init(struct gb_beagleplay *bg) return 0; } +static const struct fw_upload_ops cc1352_bootloader_ops = { + .prepare = cc1352_prepare, + .write = cc1352_write, + .poll_complete = cc1352_poll_complete, + .cancel = cc1352_cancel, + .cleanup = cc1352_cleanup +}; + +static int gb_fw_init(struct gb_beagleplay *bg) +{ + int ret; + struct fw_upload *fwl; + struct gpio_desc *desc; + + bg->fwl = NULL; + bg->boot_gpio = NULL; + bg->rst_gpio = NULL; + bg->flashing_mode = false; + bg->fwl_cmd_response = 0; + bg->fwl_ack = 0; + init_completion(&bg->fwl_ack_com); + init_completion(&bg->fwl_cmd_response_com); + + desc = devm_gpiod_get(&bg->sd->dev, "boot", GPIOD_IN); + if (IS_ERR(desc)) + return PTR_ERR(fwl); + bg->boot_gpio = desc; + + desc = devm_gpiod_get(&bg->sd->dev, "reset", GPIOD_IN); + if (IS_ERR(desc)) { + ret = PTR_ERR(desc); + goto free_boot; + } + bg->rst_gpio = desc; + + fwl = firmware_upload_register(THIS_MODULE, &bg->sd->dev, "cc1352p7", + &cc1352_bootloader_ops, bg); + if (IS_ERR(fwl)) { + ret = PTR_ERR(fwl); + goto free_reset; + } + bg->fwl = fwl; + + return 0; + +free_reset: + devm_gpiod_put(&bg->sd->dev, bg->rst_gpio); + bg->rst_gpio = NULL; +free_boot: + devm_gpiod_put(&bg->sd->dev, bg->boot_gpio); + bg->boot_gpio = NULL; + return ret; +} + +static void gb_fw_deinit(struct gb_beagleplay *bg) +{ + firmware_upload_unregister(bg->fwl); +} + static int gb_beagleplay_probe(struct serdev_device *serdev) { int ret = 0; @@ -481,6 +1077,10 @@ static int gb_beagleplay_probe(struct serdev_device *serdev) if (ret) goto free_serdev; + ret = gb_fw_init(bg); + if (ret) + goto free_hdlc; + ret = gb_greybus_init(bg); if (ret) goto free_hdlc; @@ -500,6 +1100,7 @@ static void gb_beagleplay_remove(struct serdev_device *serdev) { struct gb_beagleplay *bg = serdev_device_get_drvdata(serdev); + gb_fw_deinit(bg); gb_greybus_deinit(bg); gb_beagleplay_stop_svc(bg); hdlc_deinit(bg);