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 F298FC4708C for ; Fri, 28 May 2021 09:35:05 +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 6EF8A613BA for ; Fri, 28 May 2021 09:35:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EF8A613BA 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 B39F582F4A; Fri, 28 May 2021 11:33:05 +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="gM9HpFsQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7EA1B82F21; Fri, 28 May 2021 11:32:32 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20601.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::601]) (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 E059182F1C for ; Fri, 28 May 2021 11:32:28 +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=SgFKA+VF0Ngr6AitZvftPSR5hP9GELOa9H0FuOMkCdHBvn2gjjD/R8AyLI6TVfiuPBT/hirXjbpXIuzt53yK2pu9KC9UAQsgNAXFvpLX+JFhMXjC1LDT7lbZ9U4UDQ7E2zoa+AfpFijHChk3/6eZLN9wMXLorH4uR28BZ2TLjQn8QYkQUIW6YKhPuAwnao+dyB13ppYiUcVMjLVz8m2hF3nMMUIcmDu5x5WdNZxpEPr1keWITH9tlQMZoI4CyADOmeHrfdlzY9kwJabaDprAQBqMCu+Orta7J7Y5xWA5zYARWYfwE9Bby6v04a28QcEiSxWvgu8L77jJaA+gU4Ip7g== 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=2EHBK8o5VsNiYkLS2rr+pda7Cgyhk7emNgEVGWPYsj4=; b=iQG+Hw/vKDQMUJwRnpnKNAO2oUOTWJBG4iNZinb/ptZO0OFO490f6qWy3k++Iyv2Nk9jOkO86jAYVHnl5eKzzIVxmmvL1VuaOVfo97WIv9m/d8tCqebvDJgWBUx/YLggpfu+rDCtGfHPf9m4Z4jrzaRXVMnMvq2XQ4an7SNH6Y2u5HuvmUS62VkVNB5p4JwrIyTINzemGXSKa5neJ5IvqLSTCOzrsLemxmzia71QTWZbibrgP7YElsY9LBU21NQoUvDuwGEvESMiZ7D1L8HBca6cAea9bwRNOq0cwTXlt1EUAHNyKF8h3Xnkp+dtDR+c1WZfMAn4+E5ZxYG7uIPYPw== 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=2EHBK8o5VsNiYkLS2rr+pda7Cgyhk7emNgEVGWPYsj4=; b=gM9HpFsQkcB4UYbcNpa/eMNQKsof/SnFc4OEMDuntylYgL19xmmeleGLF8UUKS05ln3qP230KNIjwj9Fs3+1Rs1UfeDUjFuXUjBJfsW9vPRCFNOMAkifkm2zoC5ibVvXqkWFPPd+ZIvn4caP5uUSe3SMMY1pkWKOVSsys2cbpFY= Received: from AM7PR02CA0021.eurprd02.prod.outlook.com (2603:10a6:20b:100::31) by VI1PR10MB1645.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:802:31::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Fri, 28 May 2021 09:32:23 +0000 Received: from AM5EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:100:cafe::17) by AM7PR02CA0021.outlook.office365.com (2603:10a6:20b:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Fri, 28 May 2021 09:32:23 +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 AM5EUR03FT058.mail.protection.outlook.com (10.152.17.48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.30 via Frontend Transport; Fri, 28 May 2021 09:32:20 +0000 Received: from SI-EXCAS2001.de.bosch.com (10.139.217.202) 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, 28 May 2021 11:31:47 +0200 Received: from FE-HUB2000.de.bosch.com (10.4.103.109) by SI-EXCAS2001.de.bosch.com (10.139.217.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2176.14; Fri, 28 May 2021 11:31:47 +0200 Received: from localhost.localdomain (10.142.41.29) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.2176.14; Fri, 28 May 2021 11:31:45 +0200 From: To: , , CC: , , Subject: [PATCH v3 17/19] am335x, guardian: software update available status is stored in AM3352 RTC scracth register Date: Fri, 28 May 2021 09:30:28 +0000 Message-ID: <20210528093030.1483-18-Gireesh.Hiremath@in.bosch.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210528093030.1483-1-Gireesh.Hiremath@in.bosch.com> References: <20210528093030.1483-1-Gireesh.Hiremath@in.bosch.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.142.41.29] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c12a4433-3db3-4a44-d8c9-08d921bb7e11 X-MS-TrafficTypeDiagnostic: VI1PR10MB1645: 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: PvCyH1tuBsOk3/A61H9oij5LmMqTU+kVDEw4DTZ03402bPykLS41DWYzSUIj/2zCQ0bw9KpfhZ834P4okMx/0Xi7gFY15onIH2EDOy1A9rTNjDjD89eP9fp+cC09mZz7n1l7Yc28Rp1M22NvBwRG1DgF/vthJvPxc5rasOWDXzSceMOnLSCCwQMs+d2K5Tt5R+WOEmhdyiI4+WQezRagAMtX7IY1ZUEVWB15sz+Dk3VLrnAF0NqG7ZXb+BIRGDIwyksh+PDuC8Jm0x/f/0bjYfIfDAF54o8MDH5gEj2jMIKlwh1M09foG1UvGuWs5/9CvN2SdWxT4d6TJFSlNUZjBTgvn+prfQzhtZbST0WafQ/Wwk9aM+ImgJAXVHDXpVdgP16NzoWSrF0bVO87d15nkc2pLlhiAViHsiQucXBH+kcHD2uV44oBDVRy1EAbLi6HodV7oj0aZmcL3pVRXy1KeogclcR+Q/STEe8RNc8ARwGyesblL5WVmNHPEFm7JPrYvjChRtl317fsg2LC1bU7OzUeBAv58WYNBl2aj3KiDAHToTxsKri5D9eVHIwEhOZughKlkhoQvH0L2bEH9lo9A9fZKFC/OrTpUTcMMaSBqE8gpqd9q87gEbGxcJyHQ6qDqDRYiO3zaSNaM31vUYChmZjtuZVC71RdotlVc7Oje1R1tOhd2Urm7B5KOw2xBmFO 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)(39860400002)(346002)(376002)(396003)(136003)(46966006)(36840700001)(478600001)(5660300002)(54906003)(6666004)(110136005)(4326008)(8676002)(26005)(336012)(2616005)(8936002)(2876002)(82310400003)(16526019)(107886003)(186003)(47076005)(36860700001)(83380400001)(70586007)(356005)(70206006)(316002)(2906002)(15650500001)(81166007)(1076003)(86362001)(82740400003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: in.bosch.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2021 09:32:20.6476 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c12a4433-3db3-4a44-d8c9-08d921bb7e11 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: AM5EUR03FT058.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB1645 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.4 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 | 27 ++++++++++++-- drivers/bootcount/Makefile | 1 + drivers/bootcount/bootcount_nvmem.c | 57 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 drivers/bootcount/bootcount_nvmem.c 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; +} -- 2.20.1