⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkboot.c

📁 VxWorks 5.4嵌入式操作系统, Tornado II开发平台BSP包的移植
💻 C
字号:
/* mkboot.c - program to make a boot diskette *//*modification history--------------------01k,03mar98,kbw	 made changes to man page text for mkbootTffs01j,15dec97,hdn	 added support for TFFS.01i,15feb96,hdn	 renamed to mkboot.c01h,12jun95,hdn	 added support for ATA. added mkbootFd and mkbootAta.01g,24jan95,jdi	 doc cleanup.01f,25oct94,hdn	 added fdRawio() instead of using raw file system.		 swapped 1st and 2nd parameter of vxsys().01e,28may94,hdn	 updated the boot sector to DOS version.01d,27jan94,hdn	 changed the entry point 0x10000 to 0x8000.01c,16nov93,hdn	 changed name of the boot image "bootrom.dat" to "bootrom.sys".01b,07nov93,hdn	 adopted Dave Fraser's idea.01a,12oct93,hdn	 written*//*DESCRIPTIONThis library creates a boot diskette or disk.  mkbootFd() creates a bootfloppy disk, mkbootAta() creates a boot IDE/ATA disk.NOMANUAL*/#include "vxWorks.h"#include "a_out.h"#include "errnoLib.h"#include "ioLib.h"#include "stdio.h"#include "string.h"#include "usrLib.h"#include "dosFsLib.h"#include "drv/fdisk/nec765Fd.h"#include "drv/hdisk/ataDrv.h"#include "tffs/tffsDrv.h"#define VXSYS_FD	0		/* floppy disk */#define VXSYS_ATA	1		/* ATA disk */#define VXSYS_TFFS	2		/* flash memory: DOC */#define VXSYS_DOSDEV	"/vxsysdos/"#define VXSYS_FILE	"/vxsysdos/bootrom.sys"#define VXSYS_ID	"WINDRIVR"#define VXDOS		"VXDOS"#define VXEXT		"VXEXT" /* global */int vxsysDebug = 0;/* local */LOCAL BOOL vxsysBootsec = TRUE;LOCAL BOOL vxsysBootrom = TRUE;LOCAL char bootStrap[] =    {    					0x8C, 0xC8,    0x8E, 0xD8, 0x8E, 0xC0, 0xFC, 0xFA, 0x8E, 0xD0,	/* 0x040 */    0xBC, 0xFE, 0x7B, 0xFB, 0xBE, 0xD4, 0x7D, 0xE8,    0xEB, 0x00, 0x33, 0xDB, 0x8B, 0xC3, 0xA0, 0x10,	/* 0x050 */    0x7C, 0xF7, 0x26, 0x16, 0x7C, 0x8B, 0x0E, 0x0E,    0x7C, 0x03, 0x0E, 0x1C, 0x7C, 0x13, 0x16, 0x1E,	/* 0x060 */    0x7C, 0x89, 0x0E, 0x03, 0x7B, 0x89, 0x16, 0x05,    0x7B, 0x03, 0xC8, 0x13, 0xD3, 0x89, 0x0E, 0x07,	/* 0x070 */    0x7B, 0x89, 0x16, 0x09, 0x7B, 0x89, 0x0E, 0x0B,    0x7B, 0x89, 0x16, 0x0D, 0x7B, 0x52, 0xB8, 0x20,	/* 0x080 */    0x00, 0xF7, 0x26, 0x11, 0x7C, 0x8B, 0x36, 0x0B,    0x7C, 0x03, 0xC6, 0x48, 0xF7, 0xF6, 0x01, 0x06,	/* 0x090 */    0x0B, 0x7B, 0x11, 0x1E, 0x0D, 0x7B, 0xA3, 0x0F,    0x7B, 0x91, 0x5A, 0xBB, 0x00, 0x7E, 0xE8, 0xAE,	/* 0x0a0 */    0x00, 0x73, 0x03, 0xE9, 0x83, 0x00, 0xBE, 0xEC,    0x7D, 0xFC, 0x8B, 0x0E, 0x11, 0x7C, 0xBF, 0x00,	/* 0x0b0 */    0x7E, 0x51, 0x56, 0x57, 0xB9, 0x0B, 0x00, 0xF3,    0xA6, 0x5F, 0x5E, 0x59, 0x74, 0x0A, 0x83, 0xC7,	/* 0x0c0 */    0x20, 0xE2, 0xEE, 0xBE, 0xE9, 0x7D, 0xEB, 0x64,    0x8B, 0x45, 0x1C, 0x8B, 0x55, 0x1E, 0xF7, 0x36,	/* 0x0d0 */    0x0B, 0x7C, 0xD1, 0xE8, 0xD1, 0xE8, 0x40, 0xA3,    0x11, 0x7B, 0xA1, 0x0B, 0x7C, 0xD1, 0xE8, 0xD1,	/* 0x0e0 */    0xE8, 0xA3, 0x13, 0x7B, 0x8B, 0x45, 0x1A, 0x48,    0x48, 0x33, 0xC9, 0x8A, 0x0E, 0x0D, 0x7C, 0xF7,	/* 0x0f0 */    0xE1, 0x03, 0x06, 0x0B, 0x7B, 0x13, 0x16, 0x0D,    0x7B, 0xBB, 0x00, 0x08, 0x8E, 0xC3, 0x33, 0xDB,	/* 0x100 */    0xB1, 0x04, 0x50, 0x52, 0xE8, 0x48, 0x00, 0x5A,    0x58, 0x72, 0x1E, 0xBE, 0xF8, 0x7D, 0xE8, 0x24,	/* 0x110 */    0x00, 0xFF, 0x0E, 0x11, 0x7B, 0x74, 0x0E, 0x83,    0xC0, 0x04, 0x83, 0xD2, 0x00, 0x8C, 0xC3, 0x03,	/* 0x120 */    0x1E, 0x13, 0x7B, 0xEB, 0xD7, 0xFF, 0x2E, 0x39,    0x7D, 0xBE, 0xDE, 0x7D, 0xE8, 0x06, 0x00, 0xEB,	/* 0x130 */    0xFE, 0x00, 0x00, 0x00, 0x08, 0x53, 0x50, 0x80,    0x3E, 0xD3, 0x7D, 0x00, 0x75, 0x0E, 0xAC, 0x0A,	/* 0x140 */    0xC0, 0x74, 0x09, 0xB4, 0x0E, 0xBB, 0x07, 0x00,    0xCD, 0x10, 0xEB, 0xF2, 0x58, 0x5B, 0xC3, 0xB5,	/* 0x150 */    0x02, 0x57, 0x88, 0x0E, 0x00, 0x7B, 0x8B, 0xF0,    0x8B, 0xFA, 0x89, 0x1E, 0x01, 0x7B, 0x8B, 0xC6,	/* 0x160 */    0x8B, 0xD7, 0x8B, 0x1E, 0x18, 0x7C, 0xF7, 0xF3,    0x42, 0x43, 0x52, 0x02, 0xD1, 0x3B, 0xD3, 0x5A,	/* 0x170 */    0x76, 0x04, 0xFE, 0xC9, 0xEB, 0xF4, 0x8B, 0xDA,    0x51, 0x99, 0xF7, 0x36, 0x1A, 0x7C, 0x86, 0xE0,	/* 0x180 */    0xB1, 0x06, 0xD2, 0xE0, 0x91, 0x0A, 0xCB, 0x8A,    0xF2, 0x58, 0xB7, 0x05, 0x53, 0x50, 0x8B, 0x1E,	/* 0x190 */    0x01, 0x7B, 0x8A, 0x16, 0xD2, 0x7D, 0x50, 0xCD,    0x13, 0x58, 0x32, 0xE4, 0x72, 0x1F, 0x59, 0x5B,	/* 0x1a0 */    0x03, 0xF0, 0x83, 0xD7, 0x00, 0x28, 0x06, 0x00,    0x7B, 0xF7, 0x26, 0x0B, 0x7C, 0x01, 0x06, 0x01,	/* 0x1b0 */    0x7B, 0x8A, 0x0E, 0x00, 0x7B, 0x80, 0xF9, 0x00,    0x77, 0xA4, 0xF8, 0x5F, 0xC3, 0x33, 0xC0, 0xCD,	/* 0x1c0 */    0x13, 0x58, 0x5B, 0xFE, 0xCF, 0x75, 0xC5, 0xF9,    0xEB, 0xF1, 0x00, 0x00, 0x56, 0x78, 0x4C, 0x64,	/* 0x1d0 */    0x20, 0x31, 0x2E, 0x32, 0x20, 0x00, 0x52, 0x65,    0x61, 0x64, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72,	/* 0x1e0 */    0x00, 0x4E, 0x6F, 0x20, 0x42, 0x4F, 0x4F, 0x54,    0x52, 0x4F, 0x4D, 0x20, 0x53, 0x59, 0x53, 0x00,	/* 0x1f0 */    0x2E, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x55, 0xAA    };/* forward declaration */LOCAL STATUS vxsys (int device, int ctrl, int drive, int fdType, char *in);/********************************************************************************* mkbootFd - create a boot floppy disk from a specified file** This command creates a boot floppy disk from a specified file** EXAMPLES:* The following example makes a bootable floppy disk from the file named* `bootrom_uncmp' to the floppy drive 0: "a:", which contains a type 0 diskette.* .CS*     -> mkbootFd 0, 0, "bootrom_uncmp"* .CE** RETURNS:* OK, or ERROR if there is an error copying from <in> to the disk.**/STATUS mkbootFd     (    int drive,			/* drive number:	(0 - 3)		 */    int fdType,			/* type of floppy disk: (0 - 1)		 */    char *in			/* name of file to read: "bootrom_uncmp" */    )    {    return (vxsys (VXSYS_FD, 0, drive, fdType, in));    }/********************************************************************************* mkbootAta - create a boot ATA disk from a specified file** This command creates a boot ATA disk from a specified file** EXAMPLES:* The following example makes a bootable hard disk from the file named* `bootrom_uncmp' to the ATA ctrl 0, drive 0: "c:" drive.* .CS*     -> mkbootAta 0, 0, "bootrom_uncmp"* .CE** RETURNS:* OK, or ERROR if there is an error copying from <in> to the disk.**/STATUS mkbootAta     (    int ctrl,			/* controller number:	(0 - 1)		 */    int drive,			/* drive number:	(0 - 1)		 */    char *in			/* name of file to read: "bootrom_uncmp" */    )    {    return (vxsys (VXSYS_ATA, ctrl, drive, 0, in));    }/********************************************************************************* mkbootTffs - make the specified flash device a boot device** This command sets up the flash device, <drive>, as a boot device.  * The <removable> parameter expects a 1 if the flash device is removable * or a 0 if it is not. The <in> parameter specifies the name of the boot file.** EXAMPLES:* In the following example, the first zero identifies drive zero as the flash* device to be made into a boot device.  The second zero indicates that the * flash is not removable.  The 'bootrom_uncmp' parameter specifies the name * of the boot file.* .CS*     -> mkbootTffs 0, 0, "bootrom_uncmp"* .CE** RETURNS:* OK, or ERROR if there is an error copying from <in> to the disk.**/STATUS mkbootTffs     (    int drive,			/* drive number: (0 - TFFS_MAX_DRIVES - 1) */    int removable,		/* removable or not: (TRUE - FALSE)	 */    char *in			/* name of file to read: "bootrom_uncmp" */    )    {    return (vxsys (VXSYS_TFFS, 0, drive, removable, in));    }/********************************************************************************* vxsys - create a boot device from a specified file** This command changes a boot sector and copies the text and data of * a specified file to the output device.** RETURNS:* OK, or* ERROR if <in> or <out> cannot be opened/created, or if there is an* error copying from <in> to <out>.**/LOCAL STATUS vxsys     (    int device,			/* device type:		(0 - 2)	*/    int ctrl,			/* controller number:	(0 - 1)	*/    int drive,			/* drive number:	(0 - 3)	*/    int fdType,			/* type of floppy disk: (0 - 1)	*/    char *in			/* name of file to read: "xxx"	*/    )    {    BLK_DEV *pBlkDev;    int inFd;    int outFd;    int ix;    int bytes;    struct exec hdr;    char partitionSec[1024];    char bootSec[1024];    char *pSys;    FD_RAW fdRaw;    ATA_RAW ataRaw;    DOS_PART_TBL *pPart;    BOOL found		= FALSE;    int offset		= 0;    int removable	= fdType;    switch (device)	{	case VXSYS_FD:            if ((UINT)drive >= FD_MAX_DRIVES)	        {	        printErr ("drive is out of range (0-%d).\n", FD_MAX_DRIVES - 1);	        return (ERROR);	        }            fdRaw.cylinder   = 0;		/* read the boot sector */            fdRaw.head       = 0;            fdRaw.sector     = 1;            fdRaw.pBuf       = bootSec;            fdRaw.nSecs      = 1;            fdRaw.direction  = 0;            fdRawio (drive, fdType, &fdRaw);            if (vxsysBootsec)	        {	        bootSec[0] = 0xeb;		/* modify the boot sector */	        bootSec[1] = 0x3c;	        bootSec[2] = 0x90;                bcopy (VXSYS_ID,  (char *)&bootSec[0x03], DOS_SYS_ID_LEN);                bcopy (bootStrap, (char *)&bootSec[0x3e], sizeof (bootStrap));                    fdRaw.direction  = 1;		/* write the boot sector */                fdRawio (drive, fdType, &fdRaw);	        }	    if ((pBlkDev = fdDevCreate (drive, fdType, 0, 0)) == NULL)		{		printErr ("Error during fdDevCreate: %x\n", errnoGet ());		return (ERROR);		}	    break;	case VXSYS_ATA:            if ((UINT)ctrl >= ATA_MAX_CTRLS)	        {	        printErr ("ctrl is out of range (0-%d).\n", ATA_MAX_CTRLS - 1);	        return (ERROR);	        }            if ((UINT)drive >= ATA_MAX_DRIVES)	        {	        printErr ("drive is out of range (0-%d).\n", ATA_MAX_DRIVES - 1);	        return (ERROR);	        }	            ataRaw.cylinder   = 0;	/* read the master partition sector */            ataRaw.head       = 0;            ataRaw.sector     = 1;            ataRaw.pBuf       = partitionSec;            ataRaw.nSecs      = 1;            ataRaw.direction  = 0;            ataRawio (ctrl, drive, &ataRaw);	    pSys	= &partitionSec[DOS_BOOT_SYS_ID];	    pPart	= (DOS_PART_TBL *)&partitionSec[DOS_BOOT_PART_TBL];    	    if ((strncmp(pSys, VXDOS, strlen(VXDOS)) != 0) &&        	(strncmp(pSys, VXEXT, strlen(VXEXT)) != 0))        	{	        for (ix = 0; ix < 4; ix++)		    {		    if (pPart->dospt_status == 0x80)		        if ((pPart->dospt_type == 0x01) ||		            (pPart->dospt_type == 0x04) ||		            (pPart->dospt_type == 0x06))			    {			    found = TRUE;			    break;			    }		    pPart++;		    }	    	        if (!found)		    {                    printErr ("Can't find the primary DOS partition.\n");	            return (ERROR);		    }	        ataRaw.cylinder	= (pPart->dospt_startSec & 0xf0) >> 4;	        ataRaw.head    	= pPart->dospt_startHead;                ataRaw.sector  	= pPart->dospt_startSec & 0x0f;                ataRaw.pBuf	= bootSec;                ataRawio (ctrl, drive, &ataRaw); /* read the boot sector */		offset = pPart->dospt_absSec;		}	                if (vxsysBootsec)	        {	        bootSec[0] = 0xeb;		/* modify the boot sector */	        bootSec[1] = 0x3c;	        bootSec[2] = 0x90;                bcopy (VXSYS_ID,  (char *)&bootSec[0x03], DOS_SYS_ID_LEN);                bcopy (bootStrap, (char *)&bootSec[0x3e], sizeof (bootStrap));	        bootSec[0x1d2] = 0x80;		/* drive "c:" is 0x80 */                    ataRaw.direction  = 1;		/* write the boot sector */                ataRawio (ctrl, drive, &ataRaw);	        }	    if ((pBlkDev = ataDevCreate (ctrl, drive, 0, offset)) == NULL)		{		printErr ("Error during fdDevCreate: %x\n", errnoGet ());		return (ERROR);		}	    break;	case VXSYS_TFFS:            if ((UINT)drive >= TFFS_MAX_DRIVES)	        {	        printErr ("drive is out of range (0-%d).\n", TFFS_MAX_DRIVES-1);	        return (ERROR);	        }            tffsRawio (drive, TFFS_ABS_READ, 0, 1, (int)&bootSec); /* read */            if (vxsysBootsec)	        {	        bootSec[0] = 0xeb;		 /* modify the boot sector */	        bootSec[1] = 0x3c;	        bootSec[2] = 0x90;                bcopy (VXSYS_ID,  (char *)&bootSec[0x03], DOS_SYS_ID_LEN);                bcopy (bootStrap, (char *)&bootSec[0x3e], sizeof (bootStrap));                    tffsRawio (drive, TFFS_ABS_WRITE, 0, 1, (int)&bootSec); /* write */	        }	    if ((pBlkDev = tffsDevCreate (drive, removable)) == NULL)		{		printErr ("Error during fdDevCreate: %x\n", errnoGet ());		return (ERROR);		}	    break;	default:	    printErr ("unknown device (0-1).\n");	    return (ERROR);	}    if (vxsysBootrom)	{        /* read the header to get a text-size and a data-size */        if ((inFd = open (in, O_RDONLY, 0644)) == ERROR)            {            printErr ("Can't open \"%s\"\n", in);	    return (ERROR);	    }        if ((read (inFd, (char *)&hdr, sizeof(hdr))) == ERROR)	    {	    printErr ("Error during read header: %x\n", errnoGet ());	    return (ERROR);	    }        if (vxsysDebug)            printErr ("text=0x%x data=0x%x\n", hdr.a_text, hdr.a_data);        bytes = hdr.a_text + hdr.a_data;        /* create a DOS file system */        if ((dosFsDevInit (VXSYS_DOSDEV, pBlkDev, NULL)) == NULL)	    {	    printErr ("Error during dosFsDevInit: %x\n", errnoGet ());	    return (ERROR);	    }        if ((outFd = open (VXSYS_FILE, O_CREAT | O_RDWR, 0644)) == ERROR)	    {            close (inFd);            printErr ("Can't open \"%s\"\n", VXSYS_FILE);	    return (ERROR);	    }        if (ioctl (outFd, FIOCONTIG, bytes) == ERROR)	    {	    printErr ("Error during ioctl FIOCONTIG: %x\n", errnoGet ());	    return (ERROR);	    }        /* read text and data, write them to the diskette */        for (ix = 0; ix < bytes; ix += sizeof(bootSec))	    {	    if (read (inFd, bootSec, sizeof(bootSec)) == ERROR)	        {	        printErr ("Error during read file: %x\n", errnoGet ());	        return (ERROR);	        }	    if (write (outFd, bootSec, sizeof(bootSec)) == ERROR)	        {	        printErr ("Error during write fd: %x\n", errnoGet ());	        return (ERROR);	        }	    }        close (inFd);        close (outFd);        iosDevDelete (iosDevFind (VXSYS_DOSDEV, &pSys));        }    return (OK);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -