How to use the startup script in VxWorks is something everyone should know. Here’s an example:
Need to define the following two macros:
#define INCLUDE_SHELL
#define INCLUDE_STARTUP_SCRIPT
Called in usrConfig.c:
#ifdef INCLUDE_STARTUP_SCRIPT
usrStartupScript (startupScriptFieldSplit (sysBootParams.startupScript));
#endif
There might be an issue with devices like sata/sd/usb not working. The reason is that this function is executed under the usrRoot task with a priority of 0, while sata/sd/usb create their own tasks to manage these devices. Clearly, these tasks will only start executing after the root task is finished, so when calling usrStartupScript, sata/sd/usb are not ready yet and cannot work properly.There are many solutions, for example, adding taskDelay() before usrStartupScript to allow sata/sd/usb tasks to run first. One method I recommend is to open the device multiple times in this function; the first attempt will certainly fail, but the second should succeed:
Implementation code is as follows:
int times= 0;
fd = ERROR;
while ((++times <= 10) && (fd == ERROR))
{
fd = open (fileName, O_RDONLY, 0);
if (fd == ERROR)
{
if (times== 1)
{
printf ("Waiting for driver to mount\n");
}
else if (times== 10)
{
printf("\n");
}
else
{
printf(".");
taskDelay(sysClkRateGet());
}
}
}
Place the file in the BSP directory, then modify the startup parameters in bootrom accordingly.
boot device : fs
processor number : 0
host name : host
file name : /sd0:0/vxWorks.st
user (u) : target
ftp password (pw) (blank = use rsh): vxTarget
flags (f) : 0x0
target name (tn) : hjj
startup script (s) : start.txt
other (o) : qefcc