[英]How to show current time in u-boot
I'm trying to display current time in the bootloader to calculate how much a function takes to be executed.我试图在引导加载程序中显示当前时间,以计算执行 function 需要多少时间。 I used the time.h library but it doesn't work perfectly.
我使用了 time.h 库,但它不能完美运行。 any idea?
任何想法? used code:
使用的代码:
#include<stdio.h>
#include<time.h>
time_t t;
time(&t);
printf("\before watchdog init: %s", ctime(&t));
error: implicit declaration of function 'time' [-Werror=implicit-function-declaration]错误:隐式声明 function 'time' [-Werror=implicit-function-declaration]
error: implicit declaration of function 'ctime' [-Werror=implicit-function-declaration]错误:隐式声明 function 'ctime' [-Werror=implicit-function-declaration]
There is no need for any C code to display the current time.无需任何 C 代码即可显示当前时间。 Just execute the shell command
date
.只需执行 shell 命令
date
。
To update the RTC time via the network use the sntp
command.要通过网络更新 RTC 时间,请使用
sntp
命令。 If your board does not have a real time clock, you can emulate it with configuration setting CONFIG_RTC_EMULATION=y.如果您的开发板没有实时时钟,您可以使用配置设置 CONFIG_RTC_EMULATION=y 来模拟它。
If you still need a solution in C, look at the code in cmd/date.c:如果你还需要C中的解决方案,查看cmd/date.c中的代码:
struct rtc_time tm;
int rcode = 0;
rcode = dm_rtc_get(dev, &tm);
if (rcode) {
puts("## Get date failed\n");
break;
}
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.