Changes

Jump to: navigation, search

Deploying Embedded Linux Systems

1,834 bytes added, 11:20, 18 December 2012
m
Watchdog
= Watchdog =
 
Typically, during application development the watchdog device included in the embedded system is turned off. Before moving to the field, enabling the watchdog is a mandatory choice. The use of this peripheral is a little bit tricky because it involves both U-Boot and Linux. The following sequence shows the typical scenario when the system is working on the field:
 
# Processor comes out of reset; internal watchdog is disabled
# U-Boot enables watchdog (timeout = 5 s); U-Boot main loop will take care of refreshing it
# Before giving control to Linux kernel, U-Boot will set up a 180 seconds timeout. This is required in order to allow the kernel to complete the boot stage and to run the application that will handle the watchdog refresh
# Once the kernel boot process has completed, watchdog application will open the watchdog device file and will take care about its refresh (timeout = 10 s)
 
To enable watchdog support in U-Boot, source code must be modified and the bootloadr must be recompiled. Usually this means enabling CONFIG_WATCHDOG and CONFIG_xxx (where xxx is the name of the watchdog device).
 
Once Linux is started (and if the kernel is compiled with watchdog support), watchdog is refreshed by a simple application like the one shown below:
 
<pre>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
int main(int argc, const char *argv[]){
int fd=open("/dev/watchdog",O_WRONLY);
if(fd==-1){
perror("watchdog");
exit(1);
}
while(1){
write(fd,"\0",1);
fsync(fd);
sleep(5);
}
}
</pre>
 
This requires the character device file:
<pre>
crw-r--r-- 1 root root 10, 130 Oct 3 2006 /dev/watchdog
</pre>
 
which can be created using the following command:
<pre>
mknod /dev/watchdog c 10 130
</pre>
= Startup sequence =

Navigation menu