From mboxrd@z Thu Jan 1 00:00:00 1970 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 ABAEDC48BE0 for ; Fri, 11 Jun 2021 16:17:25 +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 09ED261285 for ; Fri, 11 Jun 2021 16:17:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09ED261285 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=in.bosch.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F21418294B; Fri, 11 Jun 2021 18:15:22 +0200 (CEST) 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=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=in.bosch.com header.i=@in.bosch.com header.b="PoI1Y7Xx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E0A0828FB; Fri, 11 Jun 2021 18:15:01 +0200 (CEST) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02on0620.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe07::620]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6E5B282900 for ; Fri, 11 Jun 2021 18:14:56 +0200 (CEST) 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E9ANJ+DvD5o+kTfGdbFFpN1rD1MZNXgGoQ0teYuas2dW8NocmG3F/kVKvwu++7ah+ECp/gaG2s96IzY1Q6HfBSRKvwln0eqQnYtqA7X/XnWKnE6s3TdM8nurXPZXv5g82sIfVG9tMh6OXV1xVWKYxHfXMsZwDirSDD34C2T8RYk2eQJzyKehgShzrWCME35i/F+eXJIm+DzuGPmHCLpHa4ejdh7+/RQ+QyyMWYsMYqcDvvY2iclp61kylHiPppxhzT0xLbWH9w54PyOGq4wtWUxoYHCHlzzQmUnZsfSutosXA6qGFPg5ylAyNth7X3s/aaqgW5qOvEXugXN1NO7pFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mKj8qbeel88dsqltGo5V+kzA3UptS9MBNKw5QGwWP18=; b=kxElkLLWMfE54uIAOjTgil8AQYuBb7VIyPq11XDr0jDfioXfYbbIBpjA68n2vp6znstkk86Q6xyJL6w2m4sbjs8RQH0LMr07gkhGa8o2StUNRtsinKvcXdXOjGaPyanVKfPDJ3qs4zKDeng9ZnVkcZAyXhCD2gNJU1DPrzCL6GGf7QZydZA+r19VAKvTp+oHSI/MdYSe+YopgbRfpF9sdZJ2kK4K9f3viBPRSa9GUosOZV7cSvNPx2NYERU2Fh3IcF5zPBX9/uSF97pvHAvxdrasqk4Jpv4Z5Y+RIkX/H6u2/vGsw/13cOk/MObpjpiNc7TprowdpMGgZ13ZBspTeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 139.15.153.201) smtp.rcpttodomain=lists.denx.de smtp.mailfrom=in.bosch.com; dmarc=pass (p=reject sp=none pct=100) action=none header.from=in.bosch.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.bosch.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mKj8qbeel88dsqltGo5V+kzA3UptS9MBNKw5QGwWP18=; b=PoI1Y7XxDK6ehFzWTIg5QYXM0LwRhxvH3i+liqYjw0uTHWKZg2/k6+ADnqtvFXP+tlZX+y69wgVkhC760BeXA8Ca+4RvdUto+N0GhWbITW5YQIe5tydPriog5Dn+nodhKkSMJnISUqCVde3/vo/7lRIzsRIbOkCmCv3Egj/YV/c= Received: from PR2P264CA0008.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101::20) by AS8PR10MB4833.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:344::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.23; Fri, 11 Jun 2021 16:14:55 +0000 Received: from VE1EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:101:0:cafe::30) by PR2P264CA0008.outlook.office365.com (2603:10a6:101::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Fri, 11 Jun 2021 16:14:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 139.15.153.201) smtp.mailfrom=in.bosch.com; lists.denx.de; dkim=none (message not signed) header.d=none; lists.denx.de; dmarc=pass action=none header.from=in.bosch.com; Received-SPF: Pass (protection.outlook.com: domain of in.bosch.com designates 139.15.153.201 as permitted sender) receiver=protection.outlook.com; client-ip=139.15.153.201; helo=eop.bosch-org.com; Received: from eop.bosch-org.com (139.15.153.201) by VE1EUR03FT038.mail.protection.outlook.com (10.152.19.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Fri, 11 Jun 2021 16:14:55 +0000 Received: from FE-EXCAS2000.de.bosch.com (10.139.217.199) by eop.bosch-org.com (139.15.153.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2176.14; Fri, 11 Jun 2021 18:14:47 +0200 Received: from SI-HUB2000.de.bosch.com (10.4.103.108) by FE-EXCAS2000.de.bosch.com (10.139.217.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2176.14; Fri, 11 Jun 2021 18:14:47 +0200 Received: from localhost.localdomain (10.141.230.85) by SI-HUB2000.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 15.1.2176.14; Fri, 11 Jun 2021 18:14:44 +0200 From: To: , , CC: , , Subject: [PATCH v4 16/18] am335x, guardian: software update available status is stored in AM3352 RTC scracth register Date: Fri, 11 Jun 2021 16:13:48 +0000 Message-ID: <20210611161350.2141-17-Gireesh.Hiremath@in.bosch.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210611161350.2141-1-Gireesh.Hiremath@in.bosch.com> References: <20210611161350.2141-1-Gireesh.Hiremath@in.bosch.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.141.230.85] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ecadbde-44fa-40b0-8480-08d92cf40d38 X-MS-TrafficTypeDiagnostic: AS8PR10MB4833: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iU+PZqVOCb/XLR5rfivelhTQT67kdrHg4tgRa3zx4H3YsWK85KBW2mWl1kaQQUSpwuJsguqfpdak1NFisIaSifeyDtTZlS8wA2fHaux5E84d+mPNe7rpVJdiudhkToEipJ7GTQuMM5X+yHw+xGd5ONTJkchP7mG5BM8TOtNqkphhDiQm40U9RTBBT434ly0wMpuaGu4hHYvHXV2nRIzY2lK0VIYaMqaZiGGKA5SlwLh4r4VuOeAKZF5+s3alxnvPW0LFmV53cPwm4gQKh2BbFZdUH/Do71YLYSH5fpY9IIwARiHbUKBg17BCiPxVIGYkV0YJALcsu70xw2AU/rz/eZUtvVLfxYqIYr7XeAtutjq8JkyfnT4hYWcj9O6a+ec4IRzpgXwEDbSJISuSbz16cVoP4hzZG2o7uaYZq8p5ryVCGhGaXCskrgmUIVepLmp6kon4WqL6kipKrqg/pEkA5paqHzdnzA2rBURLQgl8bwMW1amLBdp1YFD4quTwKzhGj/zBNlS9OybwG33CgDgEX2gNGcxqvMUVhIb3zPjV1M/yhOI4uG/NgkQ8A/MzICSrbKparKOyRwqKgdwjHUqr2lES3dBzDbTvxT9sfQCiA6eq8fTnAzd2Kf0ujoqN3Y1+tIBenRznFe2ef16uGd2KvQMH2arVlNPvcP0tmXvNyjSNpH326N13i0DWji2M1iH8 X-Forefront-Antispam-Report: CIP:139.15.153.201; CTRY:DE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:eop.bosch-org.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(1076003)(2906002)(186003)(16526019)(4326008)(336012)(26005)(110136005)(86362001)(15650500001)(356005)(70206006)(81166007)(5660300002)(70586007)(498600001)(83380400001)(82310400003)(2616005)(2876002)(47076005)(8936002)(54906003)(8676002)(36860700001)(107886003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: in.bosch.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2021 16:14:55.4086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ecadbde-44fa-40b0-8480-08d92cf40d38 X-MS-Exchange-CrossTenant-Id: 0ae51e19-07c8-4e4b-bb6d-648ee58410f4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0ae51e19-07c8-4e4b-bb6d-648ee58410f4; Ip=[139.15.153.201]; Helo=[eop.bosch-org.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR10MB4833 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 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 --- drivers/bootcount/Kconfig | 34 +++++++++++++++-- drivers/bootcount/Makefile | 1 + drivers/bootcount/bootcount_nvmem.c | 57 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 drivers/bootcount/bootcount_nvmem.c diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig index b5ccea0d9c..0de2b7bd78 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,25 @@ 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_GENERIC || BOOTCOUNT_EXT || \ + BOOTCOUNT_AM33XX || BOOTCOUNT_ENV || \ + BOOTCOUNT_RAM || BOOTCOUNT_I2C || \ + BOOTCOUNT_AT91 || DM_BOOTCOUNT + default 0xB0 if BOOTCOUNT_AM33XX_NVMEM + depends on BOOTCOUNT_GENERIC || BOOTCOUNT_EXT || \ + BOOTCOUNT_AM33XX || BOOTCOUNT_ENV || \ + BOOTCOUNT_RAM || BOOTCOUNT_I2C || \ + BOOTCOUNT_AT91 || DM_BOOTCOUNT || \ + 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; +} -- 2.20.1