From patchwork Wed May 21 15:14:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 891525 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2177586wrm; Wed, 21 May 2025 08:16:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWk/KZhD6H79ReVjCqX4wh6tRL2/8GL2WndXl/SEddiwPBDkPnJpt9bga+nQS9gFh9lv0EfrA==@linaro.org X-Google-Smtp-Source: AGHT+IGgzP1I7KL9aYzU/8X8h1wwUWhw5+eB1qCmm/lj77zm7iGFC6UDb/sNH+q0Zt9wIK/eXTlc X-Received: by 2002:a05:6000:1889:b0:3a3:7e01:d2fa with SMTP id ffacd0b85a97d-3a37e01d307mr4470454f8f.28.1747840563374; Wed, 21 May 2025 08:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747840563; cv=none; d=google.com; s=arc-20240605; b=AgdmdFetyIVc1U8//IwFDid6ul0jiO28vC/PsRrV3cA6SJXcklzLdpLXdyFmc86Q6F z9C81l4oDqpyzJ9gFvecfZq31NgVz6ftTvfwkTn9858Qda343i8+GYNHqDr8ilEnnE7b bJ1fiS/RGMEG7kdH0hty7VwcyOw/LcCjDBY8vCA3zURx0lRsMptX2ObgIZ2tPi4A9pES GB0NqrZNHl0VQCa1gRzCV/RDPkePtfJ0wTit58XuOcACtVf8GXeoAhVdAK71fMKSjkQx 4h+nHBt7a8atT9bCjSBUbm3IwTBA1MlR2p8f091gfCOLxwtxra1fCo4m/h/wTim92S8B mjng== 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=Hk2c9/tSgoicmyHI7pE/MgajoOLTC2DBKjzOxz2/U5s=; fh=+TzJuMMnKDMsbGyXcXAynrdn4hYe+uVLmq5NLJkVciY=; b=BOUAvSfQBcrtCSXWKNULuHnewNYrxo9rJjVG1IjcGw289i9goRu16LWqkxYAf+fYP1 l841nX1zdEXZCYRUi4j1EhThR3GIhnGyxHAVrDYIGDpuGhdHBcDwL6W4Q8yQVCPkvdUV nfdaKMdjdUKFrJIHw1kq14JFK3/Tnr/6h3fE+bOFJIHwoYidzAcSbxrfc9Zywdt85JbF XPZAkWXJqHk0ogEzkQll3Wc81TuVQXdznqmh1hFb4oEHda2bRUE9hbZREbjaBwcPAQIj sEktHrXo2uDxeSfq+syZ1Ztc/hC6+/Taf95UqUjqg7R6mZ6eZjF0ukw478k+aZBU6kht ELfA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MG8gBWkI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-3a35ca8bab1si9776607f8f.693.2025.05.21.08.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 08:16:03 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MG8gBWkI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 168C882F70; Wed, 21 May 2025 17:15:55 +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="MG8gBWkI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D383B82E0A; Wed, 21 May 2025 17:15:53 +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-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 D6C1E82E9A for ; Wed, 21 May 2025 17:15:51 +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-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43d0618746bso56435665e9.2 for ; Wed, 21 May 2025 08:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1747840551; x=1748445351; 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=Hk2c9/tSgoicmyHI7pE/MgajoOLTC2DBKjzOxz2/U5s=; b=MG8gBWkIUQYQvQpprOftEkXyo7hvzkG2d69eaDnzhPgIa3sVepuN58TGvPGihDKW+9 78iPZcdZVB+00wuL2ZVcMCOQAFduZ39u7HdqsahMGzNI9qTOT9fUyTMrm4ki6ncaVGfk JTYhvfMW8N1WYOrI9ATo54vte8IJ1NOJAOzuQ+EsvOzNkAPeuDQdXl+Jyn3PcsuC9M/a sySEMR49am8J3JX7eouvR+0g9bk8T7R4rW3RgX5NgYvdNUV3SF5ylFQcYGnOL6fHEexz OBD4FVBgAGH6emAIYNPMTdqxK05/IzL5KbXtpEHtOJDaag8/VGowOdBvoGnGxOKusssL 9cyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747840551; x=1748445351; 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=Hk2c9/tSgoicmyHI7pE/MgajoOLTC2DBKjzOxz2/U5s=; b=vOAvTTfpWjXCpuvvWwonNpnaCSD64EIpKwvDaaN3OInTRGVbi783pvOxjuy+HEocXi ycuhXfhkDyzp2pIB1XNmd6ScfwSXh4s2q50OAflMehG7ePk5um5FsyQcDuNaVY4ixogf qQ+m56+9oEFgqYHE4vQwOxP+3fT/R2b/IWbaGeR6rCH04Rc68ScQs4ce/egk4tgVwjq5 Pg5YwD4XE8cpbv3oZUkfr5mb+and8utUkEfW01TLlVcYfwHusP+/kFcpSnwNduyWZ2Pf PItdyGoH1cSOdpMTi3ZOW00Q39Ul2/4R35TCKIyVrehaBpxm4IP5wp8hcIGZ+K2XAP+g YAVw== X-Gm-Message-State: AOJu0Yz2WgYJsfbDhx3kFDhyJf6RSxpurRlBPWrOWUE8B1r+K/cHaMQL 4rNgDjkCd/rFTcnH4SUDtxAKCHFcQP2je1EmfEA6jFc4lafLm1ltXfLX0wOi8+6xqCM8tORADpB AitxtiWo= X-Gm-Gg: ASbGncuAK4qAbU+WaLE81ZtDqOAr9/8oOkkydXZA9ozVXsMZPgwF/So7GBbB9BbhXtZ J2EKAWove2ATPFFef3KrbZlYWGlUrNG7ZqsIDC6DXAenI4CGSgFu6q0W/lnNXDMki/WWEI5VoAU 7ZZZeA7ZHNuPN8wNMCTnu3D9y0tgxso+FW0A1xGIhDiEkUnxdsvHCPiCgzpXhRA5qZBVn3z+b7T GD0Bfnpj3TFaIp0Ya+Yk0DykiRiDmDYOuWE/jjmyKv8vZMPftscXJC/g3I1uqHCnT0UmjshSf/w GdantPa30pmE0U75xbQXcuK1sB76JfYkcHO9kM3CLSS/PoC7HilPDIpq4H4S X-Received: by 2002:a05:600c:1992:b0:43d:45a:8fca with SMTP id 5b1f17b1804b1-442ff039684mr195582365e9.30.1747840551026; Wed, 21 May 2025 08:15:51 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:f65b:56f4:360e:9fce]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a3632a2bffsm18505226f8f.32.2025.05.21.08.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 08:15:50 -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 1/3] net: extract function net_sntp_set_rtc() from sntp_handler() Date: Wed, 21 May 2025 17:14:41 +0200 Message-ID: <20250521151516.16729-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250521151516.16729-1-jerome.forissier@linaro.org> References: <20250521151516.16729-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. Signed-off-by: Jerome Forissier --- include/net-common.h | 2 ++ net/net-common.c | 28 ++++++++++++++++++++++++++++ net/sntp.c | 23 +++-------------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/include/net-common.h b/include/net-common.h index e536968a92b..a021bf503ff 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -586,4 +586,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..30d04323d4a 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,27 @@ 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; +#ifdef CONFIG_DM_RTC + struct udevice *dev; + int ret; +#endif + + rtc_to_tm(seconds, &tm); + +#ifdef CONFIG_DM_RTC + 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); +} 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); }