网站seo内部优化,做的比较好的教育网站,短视频营销成功的案例,雅安网站制作说明
公司SOC使用的watchdog模块是新思#xff08;Synopsys#xff09;的IP。
需求
用户有时会在uboot/kernel中做些开发#xff0c;新增一些功能#xff08;OTA升级等#xff09;#xff0c;可能会出现uboot/kernel启动崩溃甚至设备死机等问题#xff0c;需要在uboo…说明
公司SOC使用的watchdog模块是新思Synopsys的IP。
需求
用户有时会在uboot/kernel中做些开发新增一些功能OTA升级等可能会出现uboot/kernel启动崩溃甚至设备死机等问题需要在uboot启动阶段开启watchdog监控设备运行实现异常后复位。
实现
前提dts watchdog节点配置ok。由于历史原因根据是否支持DMDriver modeluboot原生支持两种wdt驱动和使用的配置/实现方式。
不支持DM常见于较早版本ubootwdt驱动实现
核心配置项CONFIG_HW_WATCHDOG支持DM
核心配置项CONFIG_WDT// file: drivers/watchdog/Kconfig
config WDTbool Enable driver model for watchdog timer driversdepends on DM.... 不支持DM
配置项
核心配置
CONFIG_HW_WATCHDOG wdt timeout时间
CONFIG_WATCHDOG_TIMEOUT_MSECS具体型号的wdt例如dw wdt。
CONFIG_DESIGNWARE_WATCHDOG如果未配置支持DMCONFIG_WDT但是配置了硬件wdtCONFIG_HW_WATCHDOG会自动选上例如
config DESIGNWARE_WATCHDOGbool Designware watchdog timer supportselect HW_WATCHDOG if !WDT...驱动代码
定义并实现驱动相关功能接口
//file: drivers/watchdog/designware_wdt.c
static int designware_wdt_settimeout(unsigned int timeout)
{....
}static void designware_wdt_enable(void)
{....
}static void designware_wdt_disable(void)
{....
}static unsigned int designware_wdt_is_enabled(void)
{....
}定义实现对外接口
//file: drivers/watchdog/designware_wdt.c
#if defined(CONFIG_HW_WATCHDOG)
void hw_watchdog_reset(void)
{...
}void hw_watchdog_init(void)
{// 初始化wdt并enable...
}void hw_watchdog_disable(void)
{...
}
#endifuboot中使用
头文件watchdog.h中会定义统一的宏WATCHDOG_RESET、WATCHDOG_DISABLE指向驱动文件中实现的hw对外接口具体使用后面统一说明。
// file: include/watchdog.h
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
#define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
#define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
#else
#define INIT_FUNC_WATCHDOG_INIT
#define INIT_FUNC_WATCHDOG_RESET
#endif#ifdef CONFIG_HW_WATCHDOG#if defined(__ASSEMBLY__)#define WATCHDOG_RESET bl hw_watchdog_reset#elseextern void hw_watchdog_reset(void);extern void hw_watchdog_disable(void);#define WATCHDOG_RESET hw_watchdog_reset#define WATCHDOG_DISABLE hw_watchdog_disable#endif /* __ASSEMBLY__ */
#else....
#endif由于不支持DMwdt-uclass.cDM接口未使用。
验证
这种方式整体上执行流程比较固定uboot启动wdt就会自动运行,支持配置项较少验证方法只能代码调试。由于不支持DM这种模式不支持wdt cmd。
支持DM
配置项
核心配置
CONFIG_WDT
CONFIG_WATCHDOG // enable uboot内部使用的喂狗接口该方式下必需enable配置CONFIG_WDT后会自动开启CONFIG_WATCHDOG, 如下
// file: drivers/watchdog/Kconfig
config WDTbool Enable driver model for watchdog timer driversdepends on DMimply WATCHDOG...自动启动配置可选配置
CONFIG_WATCHDOG_AUTOSTARTy // 自动启动
CONFIG_WATCHDOG_TIMEOUT_MSECS //wdt timeout时间, 默认60s具体型号的wdt例如dw wdt。
CONFIG_DESIGNWARE_WATCHDOG驱动代码
按照DM模型实现probe等相关接口实现DM定义的 wdt 操作接口
//file: include/wdt.h
struct wdt_ops {int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);int (*stop)(struct udevice *dev);int (*reset)(struct udevice *dev);int (*expire_now)(struct udevice *dev, ulong flags);
}uboot中使用
wdt cmd使用的是wdt-uclass.c中的统一接口wdt-uclass.c中的函数再调用具体驱动的接口。头文件watchdog.h中会定义统一的宏WATCHDOG_RESET指向wdt-uclass.c中实现的对外喂狗接口具体使用后面统一说明。
// file: include/watchdog.h
#ifdef CONFIG_HW_WATCHDOG...
#else/** Maybe a software watchdog?*/#if defined(CONFIG_WATCHDOG)#if defined(__ASSEMBLY__)#define WATCHDOG_RESET bl watchdog_reset#else/* Dont require the watchdog to be enabled in SPL */#if defined(CONFIG_SPL_BUILD) \!defined(CONFIG_SPL_WATCHDOG)#define WATCHDOG_RESET() {}#elseextern void watchdog_reset(void);#define WATCHDOG_RESET watchdog_reset#endif#endif#else/** No hardware or software watchdog.*/#if defined(__ASSEMBLY__)#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/#else#define WATCHDOG_RESET() {}#endif /* __ASSEMBLY__ */#endif /* CONFIG_WATCHDOG !__ASSEMBLY__ */
#endif /* CONFIG_HW_WATCHDOG */验证
使用cli命令验证
enable wdt命令cmdline
CONFIG_CMD_WDTy // wdt cmd运行效果
uboot# wdt
wdt - Watchdog sub-systemUsage:
wdt list - list watchdog devices
wdt dev [name] - get/set current watchdog device
wdt start timeout ms [flags] - start watchdog timer
wdt stop - stop watchdog timer
wdt reset - reset watchdog timer
wdt expire [flags] - expire watchdog timer immediatelyuboot# wdt list
dw-wd0x27000000 (designware_wdt) // dts配置
uboot# wdt dev dw-wd0x27000000
uboot# wdt start 30000uboot中使用
两种配置是否支持DM方式uboot中都是使用统一的宏WATCHDOG_RESET等去操作wdt不同的是宏指向的函数。
不支持DMWATCHDOG_RESET指向的是wdt驱动中hw_watchdog_reset函数。支持DMWATCHDOG_RESET指向的是wdt-uclass.c中watchdog_reset函数。
uboot初始化时会主动调用INIT_FUNC_WATCHDOG_INIT初始化wdt不支持DM配置CONFIG_HW_WATCHDOGwdt初始化时会直接enable wdt。
//file: common/board_f.c
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
static int init_func_watchdog_init(void)
{
# if defined(CONFIG_HW_WATCHDOG) \(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \defined(CONFIG_SH) || \defined(CONFIG_DESIGNWARE_WATCHDOG) || \defined(CONFIG_IMX_WATCHDOG))hw_watchdog_init(); //该函数默认实现会配置好wdt并enableputs( Watchdog enabled\n);
# endifWATCHDOG_RESET();return 0;
}int init_func_watchdog_reset(void)
{WATCHDOG_RESET();return 0;
}
#endif /* CONFIG_WATCHDOG */uboot是裸机程序所有操作都是顺序执行开启wdt后如有耗时操作需要自己调用WATCHDOG_RESET进行喂狗进到cli时uboot cli会间隔调用WATCHDOG_RESET喂狗。