From patchwork Fri Jun 6 06:41:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 894443 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp348687wrb; Thu, 5 Jun 2025 23:43:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUrTo0GgMZHTVeQ/5RsWVdEiOpCswzeaqTn0rJ6hfw1x3PEwNU8Hd9XkQdpzqIEYDA5IterNg==@linaro.org X-Google-Smtp-Source: AGHT+IFbiPyU82X7/SBW0ysGvcNSXvtqXuNjwlsqIZP5lG4dShYauPPE0jtwxu4w+0LGOdnM8Rvz X-Received: by 2002:a17:907:94cc:b0:ad8:9f50:d8c1 with SMTP id a640c23a62f3a-ade1aab97cemr184835466b.31.1749192239339; Thu, 05 Jun 2025 23:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749192239; cv=none; d=google.com; s=arc-20240605; b=Ny9J1rRvnTVNQcSmnm/QveD9c2b71JrMGZa8EbbXsV5fsOJV/19BQKKI/HNBk2W+jd L47rq7Y+qB713jBnqp0tA4aJ2Tay4ckKOfyl07r8WObN8Kc7qbDr60r2NyM1Qt/wFsKo coAcFHxUXgCFj18QaG7vAbXqVvrVyf5yF5tTxbB9cRwkM9FayrJlNf4qv/mfxEgSjlKg Ahn8qanqptbkEJ9RQ+sH4Uoe8kklRqWz1z2n5/MBo3sOA4aMCFoO+MQzbdXqhl0BxKVr q5R32+ZVnJxrT9K4uFh89sGQPGi7KqvfWzq4E2SCqmq7maEvyN0Q8ppMywrzMr2B2mgn A/XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zBZUy6K3G7k4deHs+hVT5rp+Foz7LScGwYynlpvntA4=; fh=+TzJuMMnKDMsbGyXcXAynrdn4hYe+uVLmq5NLJkVciY=; b=PSPzQ4/wQCTVu3SWO51XT3k3BA+/zzQyU7TWItaLLaon4AbdPk/39ztA9O9cpPLNFP fHMbsoKn4hN5LubE8Y0+5Okmi0BrqeCx02BFXxGOTcAD0wxl31VZgF8/eaRSEmq4vljM Nh35vCwmIeuMHz+qT2d+kKXwi2Ume/bcoCgFTYWMe3wMq7Jl4Aof3/rYGW6yK1au8fM7 EXVHIK3qskx5MRHQgm/w+8EooUnUajG7kMp3mhgNFPRcXzI5lT45jxb0PRReqwY87pJ/ ImtQzeoez7HPgGUgIgyw3pVbTnkp5j4AS6zZUNnp+esEuug7jFNhUye6PDC6DnFGMWTK DIJA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gx/6Q78v"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-ade1d75523asi79989466b.4.2025.06.05.23.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 23:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gx/6Q78v"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41ECF82AF6; Fri, 6 Jun 2025 08:42:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="gx/6Q78v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BBB182BB5; Fri, 6 Jun 2025 08:42:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 C092B82B19 for ; Fri, 6 Jun 2025 08:42:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3a36748920cso1694700f8f.2 for ; Thu, 05 Jun 2025 23:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749192152; x=1749796952; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zBZUy6K3G7k4deHs+hVT5rp+Foz7LScGwYynlpvntA4=; b=gx/6Q78varOvFn9eO/ecHmt1nZ6Ihh8TD3eglChb56FKS7zZkceqEA3rnVGxSYRTQg mClCevD0D7cL5Qe8WtUxosqC+gnAPLa9Mhxtn4uVH0PpG3qXYvupX9oJ6qyUmvNWg37H fQHpdlnl5B5KEBkrywT+YPDyc/MfkgKVhZTywwFrep0wWpdGARba5KH5etXqMe5cuZRA zJ+zVJIN2/zD4Ccs6xE4SQTgOx3VZRMiHT6/NxtdsWr8Xx7rS4fPeJ3qFBjPkzaIwdAM RQP3fUL4+IEmSPVFcd6bqvc3SFjDWUt5WKcuyny2yuV5/5Av0P55RxDXdRCGYF3U8u/p MkpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749192152; x=1749796952; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zBZUy6K3G7k4deHs+hVT5rp+Foz7LScGwYynlpvntA4=; b=nNLnNpoQfzHuS3eL1xXTV9OeeF755CjEPq6ZKbAYyg6NGyqXgU2RVGKJhe0rMFO0QG bs/8ihNQpYN783kk3sBvOM/wmeCR4C68X2fsySs2Z9hmF1TPlQnOzW0DksDA1O+tnLnm qifvpJi59+YM30VG7UPdb037itN63BEEbVliuTBKtJVAsHGLc9kmJz9Ob79IuTIyOMgr 6xXc7wTXse8x9xwdVTLizryrNC2zXchAqTpdinrbMv8odwmrwlMyBkuavWF8KJxca36y pG4s7nauNYemqVSb0Nd5dlb57qkkRxFaMJQFWzUXIycN5Gola/mU6dpHtpz5pUNtqmgD xTkQ== X-Gm-Message-State: AOJu0Yz05rbSSBrCqjeoWhIMVTQrhkhr6cvdM9uGzxW2Ba/3dPLtONVu +E1ppI0iDPvfwQcx+AcmVhWlhoU1+WPF5wqiyHYudW2tEHad9oBCOvPnlPJeQAUs2josoNGJawB oKjfY X-Gm-Gg: ASbGnctINgNFmzykwaf4Rj7bcNEpzbPxX1UKKJa5zS2EDPrjvpid674nrdjBn+Ydngp d1nFHhf2W92Tq00AGx5FyOYIMSnTL1wC9eW91Iccl1VTVlrQjfGFJ7zDLl7IkBHevUkxpIhgOI2 eU2juja5snj10UMtNdy6atV62LEJiAFL6/PFdsLQkFKapiXKUOyQBxupqAfvb0TAMKY7rmzRysh /C9qo/nFpCy0oryTAnDyLfoCMLyiJe/8DdGK0ZxmylOKgS0PO2U02NV/oKxKIcjT21M/R6W7JWA zljxkBcPlLQx7wybnGBpvcIFciIs2FZ/QqLuwxXynHzkbQRoekUX98qEH2DCId1lJDSoVIaNn5b QQ4E+bA== X-Received: by 2002:a05:6000:2485:b0:3a5:2ec5:35a3 with SMTP id ffacd0b85a97d-3a531ab6deamr1802562f8f.45.1749192151969; Thu, 05 Jun 2025 23:42:31 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244d10asm994627f8f.67.2025.06.05.23.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 23:42:31 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Simon Glass , Tom Rini Subject: [PATCH v2 10/13] net: extract function net_sntp_set_rtc() from sntp_handler() Date: Fri, 6 Jun 2025 08:41:46 +0200 Message-ID: <20250606064211.3091237-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250606064211.3091237-1-jerome.forissier@linaro.org> References: <20250606064211.3091237-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean Extract the code that sets the RTC clock from sntp_handler() in net/sntp.c and make it a new function net_sntp_set_rtc() in net/net-common.c. This will allow re-use with NET_LWIP. According to [1] it is safe to assume that all devices have been converted to DM_RTC so drop the useless code. [1] https://lists.denx.de/pipermail/u-boot/2025-June/591376.html Signed-off-by: Jerome Forissier --- Changes in v2: - Drop the non-RTC case include/net-common.h | 2 ++ net/net-common.c | 23 +++++++++++++++++++++++ net/sntp.c | 23 +++-------------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/include/net-common.h b/include/net-common.h index 7853612b237..c212d2f9b3b 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -588,4 +588,6 @@ extern struct wget_http_info default_wget_info; extern struct wget_http_info *wget_info; int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info); +void net_sntp_set_rtc(u32 seconds); + #endif /* __NET_COMMON_H__ */ diff --git a/net/net-common.c b/net/net-common.c index e01b0da7d7b..b064557d524 100644 --- a/net/net-common.c +++ b/net/net-common.c @@ -1,5 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 + +#include #include +#include +#include void copy_filename(char *dst, const char *src, int size) { @@ -25,3 +29,22 @@ int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info) wget_info = info ? info : &default_wget_info; return wget_do_request(dst_addr, uri); } + +void net_sntp_set_rtc(u32 seconds) +{ + struct rtc_time tm; + struct udevice *dev; + int ret; + + rtc_to_tm(seconds, &tm); + + ret = uclass_get_device(UCLASS_RTC, 0, &dev); + if (ret) + printf("SNTP: cannot find RTC: err=%d\n", ret); + else + dm_rtc_set(dev, &tm); + + printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); +} diff --git a/net/sntp.c b/net/sntp.c index 73d1d87d38b..77cee0046bd 100644 --- a/net/sntp.c +++ b/net/sntp.c @@ -57,8 +57,7 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip, unsigned src, unsigned len) { struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt; - struct rtc_time tm; - ulong seconds; + u32 seconds; debug("%s\n", __func__); @@ -69,24 +68,8 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip, * As the RTC's used in U-Boot support second resolution only * we simply ignore the sub-second field. */ - memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong)); - - rtc_to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm); -#ifdef CONFIG_DM_RTC - struct udevice *dev; - int ret; - - ret = uclass_get_device(UCLASS_RTC, 0, &dev); - if (ret) - printf("SNTP: cannot find RTC: err=%d\n", ret); - else - dm_rtc_set(dev, &tm); -#elif defined(CONFIG_CMD_DATE) - rtc_set(&tm); -#endif - printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n", - tm.tm_year, tm.tm_mon, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(seconds)); + net_sntp_set_rtc(ntohl(seconds) - 2208988800UL + net_ntp_time_offset); net_set_state(NETLOOP_SUCCESS); }