📄 bootlib.c
字号:
/* bootLib.c - boot ROM subroutine library *//* Copyright 1995-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02v,13mar02,jkf Fixing SPR#74251, using bootLib.h macros for array sizes instead of numeric constants. Changed copyright to 2002.02u,30mar99,jdi doc: corrected misspelling of NOMANUAL which caused bootScanNum() to publish.02t,28mar99,jdi doc: fixed tiny formatting errors in .iP section.02s,14mar99,jdi doc: removed refs to config.h and/or configAll.h (SPR 25663).02r,04feb99,dbt when bootParamsShow() routine is called without any parameter, print an error message (Fixed SPR #24885).02q,26aug97,spm modified bootLeaseExtract to allow improved treatment of DHCP address information by startup routines02p,27nov96,spm added DHCP client and support for network device unit numbers.02p,12sep97,dgp doc: fix SPR 5330 boot line has required parameters02o,19jun96,dbt fixed spr 6691. Modified function promptParamString in order to take into account the size of the field to read Modified promptRead to read the entire string even if it is too long. This is to empty the reception buffer of the standard input. Update copyright.02n,14oct95,jdi doc: revised pathnames for Tornado.02m,16feb95,jdi doc format corrections.02l,12jan93,jdi fixed poor style in bootParamsPrompt().02k,20jan93,jdi documentation cleanup for 5.1.02j,28jul92,rdc made bootStructToString write enable memory before writing.02i,26may92,rrr the tree shuffle02h,01mar92,elh changed printParamNum to take an int param (instead of char).02g,05dec91,rrr shut up some ansi warnings.02f,19nov91,rrr shut up some ansi warnings.02e,04oct91,rrr passed through the ansification filter -changed functions to ansi style -changed includes to have absolute path from h/ -changed VOID to void -changed copyright notice02d,30apr91,jdi documentation tweak.02c,05apr91,jdi documentation -- removed header parens and x-ref numbers; doc review by dnw.02b,24mar91,jaa documentation.02a,15jul90,dnw added "targetName", "startupScript", and "other" fields replaced bootParamsToString() with bootStructToString() replaced bootStringToParams() with bootStringToStruct() changed to initialize procNum to 0 instead of NONE routines accept and generate boot strings w/o host & filename (required for bootp) removed clearFlag from promptParamString - now all fields can be cleared promptParamNum now accepts "." to be clear (0) added bootParamsErrorPrint01r,10jul90,dnw lint clean-up, esp to allow void to be void one day fixed incorrect declaration of promptParamString() & promptParamNum(); was void, now int declared to return int instead of void changed name of scanNum() to bootScanNum() to not conflict with routine in fioLib.c01q,02jan90,dab fixed bootStringsToParams() bug in parsing vbnum value. disabled clearing of boot device, host name, or boot file fields.01p,23may89,dnw made promptRead be LOCAL.01o,20aug88,gae documentation01n,30may88,dnw changed to v4 names.01m,29may88,dnw changed calls to atoi() to sscanf().01l,28may88,dnw moved skipSpace here from fioLib. changed calls to fioStdIn to STD_IN. made promptParam...() LOCAL again (copies in nfsLib now).01k,19apr88,llk made promptParamNum and promptParamString global routines.01j,19feb88,dnw added bootExtractNetmask().01i,18nov87,ecs lint. added include of strLib.h. documentation.01h,15nov87,dnw changed to print '?' for unprintable chars in parameters.01g,06nov87,jlf documentation01f,13oct87,dnw added flags field to boot line encoding and decoding.01e,09oct87,jlf changed to deal with new ISI boot format with ethernet adrs.01d,14may87,rdc procnum can now be defined by a line VBNUM=n or VB=n for +dnw compatability with isi bootproms. changed prompt to indicate password is for ftp only. fixed bootEncodeParams() to add EOS.01c,23mar87,jlf documentation. changed routine names to meet naming conventions.01b,20dec86,dnw added promptBootParams(). changed to not get include files from default directories.01a,18dec86,llk created.*//*DESCRIPTIONThis library contains routines for manipulating a boot line.Routines are provided to interpret, construct, print, and prompt fora boot line.When VxWorks is first booted, certain parameters can be specified,such as network addresses, boot device, host, and start-up file.This information is encoded into a single ASCII string known as the boot line.The boot line is placed at a known address (specified in config.h)by the boot ROMs so that the system being booted can discover the parametersthat were used to boot the system.The boot line is the only means of communication from the boot ROMs tothe booted system.The boot line is of the form:.CSbootdev(unitnum,procnum)hostname:filename e=# b=# h=# g=# u=userid pw=passwd f=#tn=targetname s=startupscript o=other.CEwhere:.iP <bootdev> 12the boot device (required); for example, "ex" for Excelan Ethernet, "bp" for backplane. For the backplane, this field can have an optional anchoraddress specification of the form "bp=<adrs>" (see bootBpAnchorExtract())..iP <unitnum>the unit number of the boot device (0..n)..iP <procnum>the processor number on the backplane, 0..n (required for VME boards)..iP <hostname>the name of the boot host (required)..iP <filename>the file to be booted (required)..iP "e" "" 3the Internet address of the Ethernet interface.This field can have an optional subnet maskof the form <inet_adrs>:<subnet_mask>. If DHCPis used to obtain the configuration parameters,lease timing information may also be present.This information takes the form <lease_duration>:<lease_origin>and is appended to the end of the field.(see bootNetmaskExtract() and bootLeaseExtract())..iP "b"the Internet address of the backplane interface.This field can have an optional subnet maskand/or lease timing information as "e"..iP "h"the Internet address of the boot host..iP "g"the Internet address of the gateway to the boot host.Leave this parameter blank if the host is on same network..iP "u"a valid user name on the boot host..iP "pw"the password for the user on the host.This parameter is usually left blank.If specified, FTP is used for file transfers..iP "f"the system-dependent configuration flags.This parameter contains an `or' of option bits defined insysLib.h..iP "tn"the name of the system being booted.iP "s"the name of a file to be executed as a start-up script..iP "o""other" string for use by the application..LPThe Internet addresses are specified in "dot" notation (e.g., 90.0.0.2).The order of assigned values is arbitrary.EXAMPLE.CSenp(0,0)host:/usr/wpwr/target/config/mz7122/vxWorks e=90.0.0.2 b=91.0.0.2 h=100.0.0.4 g=90.0.0.3 u=bob pw=realtime f=2 tn=target s=host:/usr/bob/startup o=any_string.CEINCLUDE FILES: bootLib.hSEE ALSO: bootConfig*//* LINTLIBRARY */#include "vxWorks.h"#include "ctype.h"#include "string.h"#include "sysLib.h"#include "bootLib.h"#include "stdio.h"#include "fioLib.h"#include "private/vmLibP.h"#include "taskLib.h"/* macros that fill in size parameter */#define GET_WORD(pp, field, delims) \ getWord (pp, field, sizeof (field), delims)#define GET_ASSIGN(pp, name, field) \ getAssign (pp, name, field, sizeof (field))#define PARAM_PRINT_WIDTH 21LOCAL char strBootDevice [] = "boot device";LOCAL char strHostName [] = "host name";LOCAL char strTargetName [] = "target name (tn)";LOCAL char strFileName [] = "file name";LOCAL char strInetOnEthernet [] = "inet on ethernet (e)";LOCAL char strInetOnBackplane [] = "inet on backplane (b)";LOCAL char strHostInet [] = "host inet (h)";LOCAL char strGatewayInet [] = "gateway inet (g)";LOCAL char strUser [] = "user (u)";LOCAL char strFtpPw [] = "ftp password (pw)";LOCAL char strFtpPwLong [] = "ftp password (pw) (blank = use rsh)";LOCAL char strUnitNum [] = "unit number";LOCAL char strProcNum [] = "processor number";LOCAL char strFlags [] = "flags (f)";LOCAL char strStartup [] = "startup script (s)";LOCAL char strOther [] = "other (o)";/* forward static functions */static STATUS bootSubfieldExtract (char *string, int *pValue, char delimeter);static void addAssignNum (char *string, char *code, int value);static void addAssignString (char *string, char *code, char *value);static BOOL getWord (char ** ppString, char *pWord, int length, char *delim);static BOOL getConst (char ** ppString, char *pConst);static BOOL getNum (char ** ppString, int *pNum);static BOOL getAssign (char ** ppString, char *valName, char *pVal, int maxLen);static BOOL getAssignNum (char ** ppString, char *valName, int *pVal);static void printClear (char *param);static void printParamNum (char *paramName, int value, BOOL hex);static void printParamString (char *paramName, char *param);static int promptParamBootDevice (char *paramName, char *param, int *pValue, int sizeParamName);static int promptParamString (char *paramName, char *param, int sizeParamName);static int promptParamNum (char *paramName, int *pValue, BOOL hex);static int promptRead (char *buf, int bufLen);static void skipSpace (char ** strptr);/********************************************************************************* bootStringToStruct - interpret the boot parameters from the boot line** This routine parses the ASCII string and returns the values into* the provided parameters.** For a description of the format of the boot line, see the manual entry * for bootLib ** RETURNS:* A pointer to the last character successfully parsed plus one* (points to EOS, if OK). The entire boot line is parsed.*/char *bootStringToStruct ( char *bootString, /* boot line to be parsed */ FAST BOOT_PARAMS *pBootParams /* where to return parsed boot line */ ) { char *p1 = bootString; char *p1Save; char *p2; char hostAndFile [BOOT_HOST_LEN + BOOT_FILE_LEN]; /* initialize boot parameters */ bzero ((char *) pBootParams, sizeof (*pBootParams)); /* get boot device and proc num */ if (!GET_WORD (&p1, pBootParams->bootDev, " \t(") || !getConst (&p1, "(") || !getNum (&p1, &pBootParams->unitNum) || !getConst (&p1, ",") || !getNum (&p1, &pBootParams->procNum) || !getConst (&p1, ")")) { return (p1); } /* get host name and boot file, if present */ p1Save = p1; GET_WORD (&p1, hostAndFile, " \t"); if (index (hostAndFile, ':') != NULL) { p2 = hostAndFile; GET_WORD (&p2, pBootParams->hostName, ":"); getConst (&p2, ":"); GET_WORD (&p2, pBootParams->bootFile, " \t"); } else p1 = p1Save; /* get optional assignments */ while (skipSpace (&p1), (*p1 != EOS)) { if (!GET_ASSIGN (&p1, "ead", pBootParams->ead) && !GET_ASSIGN (&p1, "e", pBootParams->ead) && !GET_ASSIGN (&p1, "bad", pBootParams->bad) && !GET_ASSIGN (&p1, "b", pBootParams->bad) && !GET_ASSIGN (&p1, "had", pBootParams->had) && !GET_ASSIGN (&p1, "h", pBootParams->had) && !GET_ASSIGN (&p1, "gad", pBootParams->gad) && !GET_ASSIGN (&p1, "g", pBootParams->gad) && !GET_ASSIGN (&p1, "usr", pBootParams->usr) && !GET_ASSIGN (&p1, "u", pBootParams->usr) && !GET_ASSIGN (&p1, "pw", pBootParams->passwd) && !GET_ASSIGN (&p1, "o", pBootParams->other) && !GET_ASSIGN (&p1, "tn", pBootParams->targetName) && !GET_ASSIGN (&p1, "hn", pBootParams->hostName) && !GET_ASSIGN (&p1, "fn", pBootParams->bootFile) && !GET_ASSIGN (&p1, "s", pBootParams->startupScript) && !getAssignNum (&p1, "n", &pBootParams->procNum) && !getAssignNum (&p1, "f", &pBootParams->flags)) { break; } } return (p1); }/********************************************************************************* bootStructToString - construct a boot line** This routine encodes a boot line using the specified boot parameters.** For a description of the format of the boot line, see the manual * entry for bootLib.** RETURNS: OK.*/STATUS bootStructToString ( char *paramString, /* where to return the encoded boot line */ FAST BOOT_PARAMS *pBootParams /* boot line structure to be encoded */ ) { UINT state; BOOL writeProtected = FALSE; int pageSize = 0; char *pageAddr = NULL; /* see if we need to write enable the memory */ if (vmLibInfo.vmLibInstalled) { pageSize = VM_PAGE_SIZE_GET(); pageAddr = (char *) ((UINT) paramString / pageSize * pageSize); if (VM_STATE_GET (NULL, (void *) pageAddr, &state) != ERROR) if ((state & VM_STATE_MASK_WRITABLE) == VM_STATE_WRITABLE_NOT) { writeProtected = TRUE; TASK_SAFE(); VM_STATE_SET (NULL, pageAddr, pageSize, VM_STATE_MASK_WRITABLE, VM_STATE_WRITABLE); } } if ((pBootParams->hostName[0] == EOS) && (pBootParams->bootFile[0] == EOS)) sprintf (paramString, "%s(%d,%d)", pBootParams->bootDev, pBootParams->unitNum, pBootParams->procNum); else sprintf (paramString, "%s(%d,%d)%s:%s", pBootParams->bootDev, pBootParams->unitNum, pBootParams->procNum, pBootParams->hostName, pBootParams->bootFile); addAssignString (paramString, "e", pBootParams->ead); addAssignString (paramString, "b", pBootParams->bad); addAssignString (paramString, "h", pBootParams->had); addAssignString (paramString, "g", pBootParams->gad); addAssignString (paramString, "u", pBootParams->usr); addAssignString (paramString, "pw", pBootParams->passwd); addAssignNum (paramString, "f", pBootParams->flags); addAssignString (paramString, "tn", pBootParams->targetName); addAssignString (paramString, "s", pBootParams->startupScript); addAssignString (paramString, "o", pBootParams->other); if (writeProtected) { VM_STATE_SET (NULL, pageAddr, pageSize, VM_STATE_MASK_WRITABLE, VM_STATE_WRITABLE_NOT); TASK_UNSAFE(); } return (OK); }/********************************************************************************* bootParamsShow - display boot line parameters** This routine displays the boot parameters in the specified boot string* one parameter per line.** RETURNS: N/A*/void bootParamsShow ( char *paramString /* boot parameter string */ ) { BOOT_PARAMS bootParams; char *pS; if (paramString == NULL) { printf ("No boot parameter string specified.\n"); return; } pS = bootStringToStruct (paramString, &bootParams); if (*pS != EOS) { bootParamsErrorPrint (paramString, pS); return; } printf ("\n"); printParamString (strBootDevice, bootParams.bootDev); printParamNum (strUnitNum, bootParams.unitNum, FALSE); printParamNum (strProcNum, bootParams.procNum, FALSE); printParamString (strHostName, bootParams.hostName); printParamString (strFileName, bootParams.bootFile); printParamString (strInetOnEthernet, bootParams.ead); printParamString (strInetOnBackplane, bootParams.bad); printParamString (strHostInet, bootParams.had); printParamString (strGatewayInet, bootParams.gad); printParamString (strUser, bootParams.usr); printParamString (strFtpPw, bootParams.passwd); printParamNum (strFlags, bootParams.flags, TRUE); printParamString (strTargetName, bootParams.targetName); printParamString (strStartup, bootParams.startupScript); printParamString (strOther, bootParams.other); printf ("\n"); }/********************************************************************************* bootParamsPrompt - prompt for boot line parameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -