From patchwork Wed Jan 6 15:32:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gireesh Hiremath X-Patchwork-Id: 1422994 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=in.bosch.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=in.bosch.com header.i=@in.bosch.com header.a=rsa-sha256 header.s=key2-intmail header.b=F8nSTYY8; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4D9vg04Tj0z9sVk for ; Thu, 7 Jan 2021 03:18:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 042E7827A3; Wed, 6 Jan 2021 17:15:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=reject dis=none) header.from=in.bosch.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=in.bosch.com header.i=@in.bosch.com header.b="F8nSTYY8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE513826C2; Wed, 6 Jan 2021 16:32:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 17D74826CA for ; Wed, 6 Jan 2021 16:32:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=in.bosch.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Gireesh.Hiremath@in.bosch.com Received: from si0vm1948.rbesz01.com (lb41g3-ha-dmz-psi-sl1-mailout.fe.ssn.bosch.com [139.15.230.188]) by si0vms0217.rbdmz01.com (Postfix) with ESMTPS id 4D9tfS6BJ9z4f3lwv; Wed, 6 Jan 2021 16:32:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=key2-intmail; t=1609947168; bh=6fpWpkFc7jzpZRNXYDyHBuNEiuJWZJIJiVXj4p17DYI=; l=10; h=From:Subject:From:Reply-To:Sender; b=F8nSTYY8gf4qq9kNyAs2pEOy76dpdNBlW5Ph7kGay646Q4GPVVEdTIfCpNE0sC+us Qvyk0PUEqOig5SQagOy2ps+RFoA62VUlIyXbIVD84EfH1EVsXYaSJmLNLmcIU//jYb UcFa8zzIny8jI0gD3Si+2bvqUc338uObX44mK1gs= Received: from fe0vm02900.rbesz01.com (unknown [10.58.172.176]) by si0vm1948.rbesz01.com (Postfix) with ESMTPS id 4D9tfS5y9gz38s; Wed, 6 Jan 2021 16:32:48 +0100 (CET) X-AuditID: 0a3aad0c-f29ff700000020da-0d-5ff5d820b42e Received: from fe0vm1652.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by fe0vm02900.rbesz01.com (SMG Outbound) with SMTP id B5.1B.08410.028D5FF5; Wed, 6 Jan 2021 16:32:48 +0100 (CET) Received: from SI-HUB2000.de.bosch.com (si-hub2000.de.bosch.com [10.4.103.108]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 4D9tfS4vcjzV14; Wed, 6 Jan 2021 16:32:48 +0100 (CET) Received: from localhost.localdomain (10.142.201.46) by SI-HUB2000.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 15.1.2106.2; Wed, 6 Jan 2021 16:32:46 +0100 From: To: , , CC: , , Subject: [PATCH 1/1] am335x, guardian: software update available status is stored in AM3352 RTC scracth register Date: Wed, 6 Jan 2021 15:32:33 +0000 Message-ID: <20210106153233.2843-2-Gireesh.Hiremath@in.bosch.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210106153233.2843-1-Gireesh.Hiremath@in.bosch.com> References: <20210106153233.2843-1-Gireesh.Hiremath@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.142.201.46] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLLMWRmVeSWpSXmKPExsXCZbVWVlfhxtd4g4lPdS2mH3/LajF10mZ2 i7d7O9kdmD3+Pr/O4vHqwCp2j7N3djAGMEdx2aSk5mSWpRbp2yVwZfQs+8tS0K9TMWebWgPj bJUuRk4OCQETiUsvfjN1MXJxCAnMYJL4/HcxlLObUeLI7YUsEM4aRon2C7sZuxg5ONgEVCVW L6wBMUUEgiVWH1EDGcQsUCCx7+opZhBbGMi+9HoLK4jNIqAiMXHpWnYQm1fAUeLmvyNsEIvl Jc73rgOLcwo4SSz/uAXMFgKq6dozmwmiXlDi5MwnLBDz5SWat85mhrAlJA6+eMEMMUdR4s/x lYwTGAVnIWmZhaRlFpKWBYzMqxjF0lINynINjCwNDPSKklKLqwwM9ZLzczcxQkKYZwfjqZ4P eocYmTgYDzFKcDArifBaHPsSL8SbklhZlVqUH19UmpNafIhRmoNFSZxXhWdjnJBAemJJanZq akFqEUyWiYNTqoFJIN9HNlCA7/BTnvufWsKUL54OXptvtuLNnJjg03tWLTQR8rMoPrSxQbia fXrs0oo14r781t0N/h/eXeiw6D5+T/bknRBdyaipbDdLFc1Cw896Rc5ofloV/I9PcNLrCq4b k9n+Nq0y9/jX1naw7PXctu6tvrE3cpqZD4k98o027VC4nXs4LDP0pmRYFsv1/sYjDeqVMpwX /XkOyt+dYGTHI5C28tvOuOM+qbGa4a//NMYtdkmZ8exM9OkTObvep30vtHr52V5fZ3rBb3Np p5Du1VXTrjC8Xx1R+yPL8ObSLPsfO+5PYk6ad1lKccrsr3qLVq4+v1At+E3Osm3GotyubgZl GlYztEwTF8tZHldiKc5INNRiLipOBADC3Vxu0AIAAA== X-Mailman-Approved-At: Wed, 06 Jan 2021 17:14:49 +0100 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Gireesh Hiremath RTC second scratch register[32-bit]: -zero byte hold boot count value -first byte hold update available state -second byte hold version -third byte hold magic number Signed-off-by: Gireesh Hiremath Gbp-Pq: Topic apertis/guardian Gbp-Pq: Name am335x-guardian-software-update-available-status-is-store.patch --- configs/am335x_guardian_defconfig | 1 + drivers/bootcount/Kconfig | 27 ++++++++++++-- drivers/bootcount/Makefile | 1 + drivers/bootcount/bootcount_nvmem.c | 57 +++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 drivers/bootcount/bootcount_nvmem.c diff --git a/configs/am335x_guardian_defconfig b/configs/am335x_guardian_defconfig index b5d8d80d14..c8336a8256 100644 --- a/configs/am335x_guardian_defconfig +++ b/configs/am335x_guardian_defconfig @@ -71,6 +71,7 @@ CONFIG_VERSION_VARIABLE=y CONFIG_BOOTP_SEND_HOSTNAME=y CONFIG_SPL_DM=y CONFIG_BOOTCOUNT_LIMIT=y +CONFIG_BOOTCOUNT_AM33XX_NVMEM=y CONFIG_LED=y CONFIG_LED_GPIO=y CONFIG_MISC=y diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig index b5ccea0d9c..d543061233 100644 --- a/drivers/bootcount/Kconfig +++ b/drivers/bootcount/Kconfig @@ -42,6 +42,25 @@ config BOOTCOUNT_AM33XX This requires the RTC clocks, etc, to be enabled prior to use and not all boards with this IP block on it will have the RTC in use. +config BOOTCOUNT_AM33XX_NVMEM + bool "Boot counter in AM33XX RTC IP block with upgrade_available flag" + depends on AM33XX + select SPL_AM33XX_ENABLE_RTC32K_OSC if AM33XX + help + Add support for maintaining bootcount,upgrade_available, + version and BOOTMAGIC in a AM33xx RTC IP block + scratch register2. + + A bootcount driver for the RTC IP block found on many TI platforms. + This requires the RTC clocks, etc, to be enabled prior to use and + not all boards with this IP block on it will have the RTC in use. + + If there is upgrade in software then "upgrade_available" is 1, + "bootcount" is incremented otherwise "upgrade_available" and + "bootcount" is always 0. So the Userspace Application must set + the "upgrade_available" and "bootcount" variable to 0, if a boot + was successfully. + config BOOTCOUNT_ENV bool "Boot counter in environment" help @@ -177,16 +196,18 @@ config SYS_BOOTCOUNT_EXT_NAME config SYS_BOOTCOUNT_ADDR hex "RAM address used for reading and writing the boot counter" - default 0x44E3E000 if BOOTCOUNT_AM33XX + default 0x44E3E000 if BOOTCOUNT_AM33XX || BOOTCOUNT_AM33XX_NVMEM default 0xE0115FF8 if ARCH_LS1043A || ARCH_LS1021A depends on BOOTCOUNT_AM33XX || BOOTCOUNT_GENERIC || BOOTCOUNT_EXT || \ - BOOTCOUNT_I2C + BOOTCOUNT_I2C || BOOTCOUNT_AM33XX_NVMEM help Set the address used for reading and writing the boot counter. config SYS_BOOTCOUNT_MAGIC hex "Magic value for the boot counter" - default 0xB001C041 + default 0xB001C041 if BOOTCOUNT_AM33XX + default 0xB0 if BOOTCOUNT_AM33XX_NVMEM + depends on BOOTCOUNT_AM33XX || BOOTCOUNT_AM33XX_NVMEM help Set the magic value used for the boot counter. diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile index 51d860b00e..12658ffdce 100644 --- a/drivers/bootcount/Makefile +++ b/drivers/bootcount/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_BOOTCOUNT_RAM) += bootcount_ram.o obj-$(CONFIG_BOOTCOUNT_ENV) += bootcount_env.o obj-$(CONFIG_BOOTCOUNT_I2C) += bootcount_i2c.o obj-$(CONFIG_BOOTCOUNT_EXT) += bootcount_ext.o +obj-$(CONFIG_BOOTCOUNT_AM33XX_NVMEM) += bootcount_nvmem.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount-uclass.o obj-$(CONFIG_DM_BOOTCOUNT_RTC) += rtc.o diff --git a/drivers/bootcount/bootcount_nvmem.c b/drivers/bootcount/bootcount_nvmem.c new file mode 100644 index 0000000000..5f266d5ec8 --- /dev/null +++ b/drivers/bootcount/bootcount_nvmem.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2011 + * Heiko Schocher, DENX Software Engineering, hs@denx.de. + * (C) Copyright 2018 Robert Bosch Power Tools GmbH. + * + * A bootcount driver for the RTC IP block found on many TI platforms. + * This requires the RTC clocks, etc, to be enabled prior to use and + * not all boards with this IP block on it will have the RTC in use. + */ + +#include +#include + +#define BC_VERSION 2 + +void bootcount_store(ulong bootcount) +{ + u8 upgrade_available = 0; + ulong val = 0; + struct davinci_rtc *reg = + (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; + + val = raw_bootcount_load(®->scratch2); + upgrade_available = (val >> 8) & 0x000000ff; + + /* Only update bootcount during upgrade process */ + if (!upgrade_available) + bootcount = 0; + + val = (bootcount & 0x000000ff) | + (upgrade_available << 8) | + (BC_VERSION << 16) | + (CONFIG_SYS_BOOTCOUNT_MAGIC << 24); + + /* + * write RTC kick registers to enable write + * for RTC Scratch registers. Scratch register 2 is + * used for bootcount value. + */ + writel(RTC_KICK0R_WE, ®->kick0r); + writel(RTC_KICK1R_WE, ®->kick1r); + raw_bootcount_store(®->scratch2, val); +} + +ulong bootcount_load(void) +{ + unsigned long val = 0; + struct davinci_rtc *reg = + (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; + + val = raw_bootcount_load(®->scratch2); + if ((val >> 24) != CONFIG_SYS_BOOTCOUNT_MAGIC) + return 0; + else + return val & 0x000000ff; +}