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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 945D0C433F5 for ; Mon, 25 Apr 2022 12:58:06 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 74C1E83A96; Mon, 25 Apr 2022 14:58:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="jwdqYSFN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D1E2833D7; Mon, 25 Apr 2022 14:58:01 +0200 (CEST) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (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 005D783B57 for ; Mon, 25 Apr 2022 14:57:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=oliver.graute@gmail.com Received: by mail-ed1-x535.google.com with SMTP id be20so9940502edb.12 for ; Mon, 25 Apr 2022 05:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=Ny576AaftIURp7SleNwoP0aOsFwwIeVxafkPmrI4Q6Q=; b=jwdqYSFNpwWxR2/2Mcjogsfb3dvyjHIJ8lUoL84+ZVsPKxFvWAe59L5gQU7ulahHT/ PCmxdJi8bDAs+Y66lQRBbZ7UaRI1GkS2slgPCsPOHNiqKQKRRSbqi/AgoQWm4QJx0D0O JOwiR4zx9PHDxsqbGYT0fKRF3XHQG1UGheMufK3zJDqWQugoiiY13JyDqxSXHcQ1UW89 Qd2M6FqO2p+pZVlyKklruhpvUQd84lEA+itpG4pV0cxf/0EgBV275sTO/wWt1o3peawa oLzbiEqg1V3KjcJap2gF4HNEq7Jf2RSdb9hQa3rZThi8c5tkwacRcFtz2PLowN5PAMVC SSfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:mime-version:content-disposition:user-agent; bh=Ny576AaftIURp7SleNwoP0aOsFwwIeVxafkPmrI4Q6Q=; b=XE4Z325YmyJQ9oYsVsEaubzTv2cNKV5VJ7nyMi83QVFQsMo3hPWjUQQcRxVWErHPMX fLbDFzXfzLqG59qU4AMaL1x8tFz3rC1fEnTQIGDhQ43iTlpLwsdU1D9u/eTfseUJhJz6 HU2Xd5CoZEMIOW73CpUgf1N0AG83v2WJGwSw0iQoGUcRwI/LsH8LBEucPRT2mwCnAW9V GCYWl7kXaPuI785BBwrYVKAf4xG4bU3+C/b2idLZTmr65jtCK4drNw3YKMqUmJYOtEP8 VehbK+TmdMaGLhdQQSJty0Cv/S7uha3GBsFZL1ssUpcieJ61UAf12uM+o9/c1FwLEOVz RN6Q== X-Gm-Message-State: AOAM533L2LE3cMidMEII96I43xfWZe4NfBDWRAtAytRSUpSIXtkO/rxy 9t14fIn/GvjnNcMg1QELv89Pg8opcn0= X-Google-Smtp-Source: ABdhPJwFPCnz00099jrQ+8p220F1FRwZnwMVoJxLI+1x+dlE9jm0DtOqqMlzr3iRX8kJsC+0/TwMIg== X-Received: by 2002:a05:6402:350a:b0:423:e41e:75cb with SMTP id b10-20020a056402350a00b00423e41e75cbmr19007575edd.178.1650891477979; Mon, 25 Apr 2022 05:57:57 -0700 (PDT) Received: from localhost (business-90-187-74-145.pool2.vodafone-ip.de. [90.187.74.145]) by smtp.gmail.com with ESMTPSA id x19-20020a05640226d300b004228faf83desm4808682edd.12.2022.04.25.05.57.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Apr 2022 05:57:57 -0700 (PDT) Date: Mon, 25 Apr 2022 14:55:39 +0200 From: Oliver Graute To: u-boot@lists.denx.de, michael@walle.cc Cc: hs@denx.de, philipp.tomsich@theobroma-systems.com, sjg@chromium.org, u-boot@lists.denx.de, oliver.graute@kococonnector.com Subject: possible off-by-one error on month counting in rtc rv8803 driver Message-ID: <20220425125539.GA16510@optiplex> Mail-Followup-To: u-boot@lists.denx.de, michael@walle.cc, hs@denx.de, philipp.tomsich@theobroma-systems.com, sjg@chromium.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Hello, I stumbled across the following possible off-by-one error in counting the month in RTC driver rv8803. I'am using struct rtc_time to define a EOL date for my U-Boots. So after this date U-Boot stops booting by reading the RTC before with rtc_get(). I'am using the same EOL code for two different imx boards with different RTCs and therefore different RTC drivers. On both boards I have set the same EOL date. So the EOL Date is 25.09.2022 23:59:59 The board with rv3029 stopps booting on 26.09.2022 0:00:00 The board with rv8803 stopps booting on 26.08.2022 0:00:00 U-Boot Code: (drivers/rtc/rv3029.c) v3029_rtc_set() ... regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1); ... rv3029_rtc_get() ... tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1; ... (drivers/rtc/rv8803.c) rv8803_rtc_set() ... buf[RTC_MON_REG_ADDR] = bin2bcd(tm->tm_mon) ... rv8803_rtc_get() ... tm->tm_mon = bcd2bin(buf[RTC_MON_REG_ADDR] & 0x1F); ... I assume that the error is here and increase and decrease by one is also required here like in the Linux driver code for RTC 8803. Linux Code: rv3029_set_time() ... regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1); ... rv3029_read_time() ... tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1; ... rv8803_set_time() ... date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1); ... rv8803_get_time() ... tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; ... Can someone verify and comment on this. Then I would prepare a patch later on. Best Regards, Oliver