mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-06 15:26:58 +02:00
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 <jerome.forissier@linaro.org>
51 lines
1.0 KiB
C
51 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <dm/uclass.h>
|
|
#include <net-common.h>
|
|
#include <linux/time.h>
|
|
#include <rtc.h>
|
|
|
|
void copy_filename(char *dst, const char *src, int size)
|
|
{
|
|
if (src && *src && (*src == '"')) {
|
|
++src;
|
|
--size;
|
|
}
|
|
|
|
while ((--size > 0) && src && *src && (*src != '"'))
|
|
*dst++ = *src++;
|
|
*dst = '\0';
|
|
}
|
|
|
|
struct wget_http_info default_wget_info = {
|
|
.method = WGET_HTTP_METHOD_GET,
|
|
.set_bootdev = true,
|
|
};
|
|
|
|
struct wget_http_info *wget_info;
|
|
|
|
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);
|
|
}
|