3 * Denis Peter, MPL AG, d.peter@mpl.ch.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 #define PRINTF(fmt,args...) printf (fmt ,##args)
39 #define PRINTF(fmt,args...)
50 /*#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_CMD_DATE) */
54 #if (CONFIG_COMMANDS & CFG_CMD_FDC) || defined(CONFIG_CMD_FDC) \
55 || (CONFIG_COMMANDS & CFG_CMD_FDOS) || defined(CONFIG_CMD_FDOS)
59 int flags; /* connected drives ect */
60 unsigned long blnr; /* Logical block nr */
61 uchar drive; /* drive no */
62 uchar cmdlen; /* cmd length */
63 uchar cmd[16]; /* cmd desc */
64 uchar dma; /* if > 0 dma enabled */
65 uchar result[11];/* status information */
66 uchar resultlen; /* lenght of result */
68 /* flags: only the lower 8bit used:
69 * bit 0 if set drive 0 is present
70 * bit 1 if set drive 1 is present
71 * bit 2 if set drive 2 is present
72 * bit 3 if set drive 3 is present
73 * bit 4 if set disk in drive 0 is inserted
74 * bit 5 if set disk in drive 1 is inserted
75 * bit 6 if set disk in drive 2 is inserted
76 * bit 7 if set disk in drive 4 is inserted
100 #define STATUS_TRACK 3
101 #define STATUS_HEAD 4
102 #define STATUS_SECT 5
103 #define STATUS_SECT_SIZE 6
106 /* Register addresses */
107 #define FDC_BASE 0x3F0
108 #define FDC_SRA FDC_BASE + 0 /* Status Register A */
109 #define FDC_SRB FDC_BASE + 1 /* Status Register B */
110 #define FDC_DOR FDC_BASE + 2 /* Digital Output Register */
111 #define FDC_TDR FDC_BASE + 3 /* Tape Drive Register */
112 #define FDC_DSR FDC_BASE + 4 /* Data rate Register */
113 #define FDC_MSR FDC_BASE + 4 /* Main Status Register */
114 #define FDC_FIFO FDC_BASE + 5 /* FIFO */
115 #define FDC_DIR FDC_BASE + 6 /* Digital Input Register */
116 #define FDC_CCR FDC_BASE + 7 /* Configuration Control */
118 #define FDC_CMD_SENSE_INT 0x08
119 #define FDC_CMD_CONFIGURE 0x13
120 #define FDC_CMD_SPECIFY 0x03
121 #define FDC_CMD_RECALIBRATE 0x07
122 #define FDC_CMD_READ 0x06
123 #define FDC_CMD_READ_TRACK 0x02
124 #define FDC_CMD_READ_ID 0x0A
125 #define FDC_CMD_DUMP_REG 0x0E
126 #define FDC_CMD_SEEK 0x0F
128 #define FDC_CMD_SENSE_INT_LEN 0x01
129 #define FDC_CMD_CONFIGURE_LEN 0x04
130 #define FDC_CMD_SPECIFY_LEN 0x03
131 #define FDC_CMD_RECALIBRATE_LEN 0x02
132 #define FDC_CMD_READ_LEN 0x09
133 #define FDC_CMD_READ_TRACK_LEN 0x09
134 #define FDC_CMD_READ_ID_LEN 0x02
135 #define FDC_CMD_DUMP_REG_LEN 0x01
136 #define FDC_CMD_SEEK_LEN 0x03
138 #define FDC_FIFO_THR 0x0C
139 #define FDC_FIFO_DIS 0x00
140 #define FDC_IMPLIED_SEEK 0x01
141 #define FDC_POLL_DIS 0x00
142 #define FDC_PRE_TRK 0x00
143 #define FDC_CONFIGURE FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
144 #define FDC_MFM_MODE 0x01 /* MFM enable */
145 #define FDC_SKIP_MODE 0x00 /* skip enable */
147 #define FDC_TIME_OUT 100000 /* time out */
148 #define FDC_RW_RETRIES 3 /* read write retries */
149 #define FDC_CAL_RETRIES 3 /* calibration and seek retries */
154 unsigned int size; /* nr of sectors total */
155 unsigned int sect; /* sectors per track */
156 unsigned int head; /* nr of heads */
157 unsigned int track; /* nr of tracks */
158 unsigned int stretch; /* !=0 means double track steps */
159 unsigned char gap; /* gap1 size */
160 unsigned char rate; /* data rate. |= 0x40 for perpendicular */
161 unsigned char spec1; /* stepping rate, head unload time */
162 unsigned char fmt_gap; /* gap2 size */
163 unsigned char hlt; /* head load time */
164 unsigned char sect_code; /* Sector Size code */
165 const char * name; /* used only for predefined formats */
169 /* supported Floppy types (currently only one) */
170 const static FD_GEO_STRUCT floppy_type[2] = {
171 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" }, /* 7 1.44MB 3.5" */
172 { 0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL }, /* end of table */
175 static FDC_COMMAND_STRUCT cmd; /* global command struct */
177 /* If the boot drive number is undefined, we assume it's drive 0 */
178 #ifndef CFG_FDC_DRIVE_NUMBER
179 #define CFG_FDC_DRIVE_NUMBER 0
182 /* Hardware access */
183 #ifndef CFG_ISA_IO_STRIDE
184 #define CFG_ISA_IO_STRIDE 1
187 #ifndef CFG_ISA_IO_OFFSET
188 #define CFG_ISA_IO_OFFSET 0
192 #ifdef CONFIG_AMIGAONEG3SE
193 unsigned char INT6_Status;
195 void fdc_interrupt(void)
200 /* waits for an interrupt (polling) */
201 int wait_for_fdc_int(void)
203 unsigned long timeout;
204 timeout = FDC_TIME_OUT;
205 while(((volatile)INT6_Status & 0x80) == 0) {
208 if(timeout == 0) /* timeout occured */
216 /* Supporting Functions */
217 /* reads a Register of the FDC */
218 unsigned char read_fdc_reg(unsigned int addr)
220 volatile unsigned char *val =
221 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS +
222 (addr * CFG_ISA_IO_STRIDE) +
228 /* writes a Register of the FDC */
229 void write_fdc_reg(unsigned int addr, unsigned char val)
231 volatile unsigned char *tmp =
232 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS +
233 (addr * CFG_ISA_IO_STRIDE) +
238 #ifndef CONFIG_AMIGAONEG3SE
239 /* waits for an interrupt (polling) */
240 int wait_for_fdc_int(void)
242 unsigned long timeout;
243 timeout = FDC_TIME_OUT;
244 while((read_fdc_reg(FDC_SRA)&0x80)==0) {
247 if(timeout==0) /* timeout occured */
255 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
256 of the MSR. returns -1 if timeout, or byte if ok */
257 int read_fdc_byte(void)
259 unsigned long timeout;
260 timeout = FDC_TIME_OUT;
261 while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
262 /* direction out and ready */
265 if(timeout==0) /* timeout occured */
268 return read_fdc_reg(FDC_FIFO);
271 /* if the direction of the FIFO is wrong, this routine is used to
272 empty the FIFO. Should _not_ be used */
273 int fdc_need_more_output(void)
276 while((read_fdc_reg(FDC_MSR)&0xC0)==0xC0) {
277 c=(unsigned char)read_fdc_byte();
278 printf("Error: more output: %x\n",c);
284 /* writes a byte to the FIFO of the FDC and checks direction and RQM bit
286 int write_fdc_byte(unsigned char val)
288 unsigned long timeout;
289 timeout = FDC_TIME_OUT;
290 while((read_fdc_reg(FDC_MSR)&0xC0)!=0x80) {
291 /* direction in and ready for byte */
294 fdc_need_more_output();
295 if(timeout==0) /* timeout occured */
298 write_fdc_reg(FDC_FIFO,val);
302 /* sets up all FDC commands and issues it to the FDC. If
303 the command causes direct results (no Execution Phase)
304 the result is be read as well. */
306 int fdc_issue_cmd(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
309 unsigned long head,track,sect,timeout;
310 track = pCMD->blnr / (pFG->sect * pFG->head); /* track nr */
311 sect = pCMD->blnr % (pFG->sect * pFG->head); /* remaining blocks */
312 head = sect / pFG->sect; /* head nr */
313 sect = sect % pFG->sect; /* remaining blocks */
314 sect++; /* sectors are 1 based */
315 PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
316 pCMD->cmd[0],track,head,sect,pCMD->drive,pCMD->blnr);
318 if(head|=0) { /* max heads = 2 */
319 pCMD->cmd[DRIVE]=pCMD->drive | 0x04; /* head 1 */
320 pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
323 pCMD->cmd[DRIVE]=pCMD->drive; /* head 0 */
324 pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
326 pCMD->cmd[TRACK]=(unsigned char) track; /* track */
327 switch (pCMD->cmd[COMMAND]) {
329 pCMD->cmd[SECTOR]=(unsigned char) sect; /* sector */
330 pCMD->cmd[SECTOR_SIZE]=pFG->sect_code; /* sector size code */
331 pCMD->cmd[LAST_TRACK]=pFG->sect; /* End of track */
332 pCMD->cmd[GAP]=pFG->gap; /* gap */
333 pCMD->cmd[DTL]=0xFF; /* DTL */
334 pCMD->cmdlen=FDC_CMD_READ_LEN;
335 pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
336 pCMD->cmd[COMMAND]|=(FDC_SKIP_MODE<<5); /* set Skip bit */
337 pCMD->resultlen=0; /* result only after execution */
340 pCMD->cmdlen=FDC_CMD_SEEK_LEN;
341 pCMD->resultlen=0; /* no result */
343 case FDC_CMD_CONFIGURE:
344 pCMD->cmd[CONFIG0]=0;
345 pCMD->cmd[CONFIG1]=FDC_CONFIGURE; /* FIFO Threshold, Poll, Enable FIFO */
346 pCMD->cmd[CONFIG2]=FDC_PRE_TRK; /* Precompensation Track */
347 pCMD->cmdlen=FDC_CMD_CONFIGURE_LEN;
348 pCMD->resultlen=0; /* no result */
350 case FDC_CMD_SPECIFY:
351 pCMD->cmd[SPEC_HUTSRT]=pFG->spec1;
352 pCMD->cmd[SPEC_HLT]=(pFG->hlt)<<1; /* head load time */
354 pCMD->cmd[SPEC_HLT]|=0x1; /* no dma */
355 pCMD->cmdlen=FDC_CMD_SPECIFY_LEN;
356 pCMD->resultlen=0; /* no result */
358 case FDC_CMD_DUMP_REG:
359 pCMD->cmdlen=FDC_CMD_DUMP_REG_LEN;
360 pCMD->resultlen=10; /* 10 byte result */
362 case FDC_CMD_READ_ID:
363 pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
364 pCMD->cmdlen=FDC_CMD_READ_ID_LEN;
365 pCMD->resultlen=7; /* 7 byte result */
367 case FDC_CMD_RECALIBRATE:
368 pCMD->cmd[DRIVE]&=0x03; /* don't set the head bit */
369 pCMD->cmdlen=FDC_CMD_RECALIBRATE_LEN;
370 pCMD->resultlen=0; /* no result */
373 case FDC_CMD_SENSE_INT:
374 pCMD->cmdlen=FDC_CMD_SENSE_INT_LEN;
378 for(i=0;i<pCMD->cmdlen;i++) {
379 /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
380 if(write_fdc_byte(pCMD->cmd[i])==FALSE) {
381 PRINTF("Error: timeout while issue cmd%d\n",i);
385 timeout=FDC_TIME_OUT;
386 for(i=0;i<pCMD->resultlen;i++) {
387 while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
390 PRINTF(" timeout while reading result%d MSR=0x%02X\n",i,read_fdc_reg(FDC_MSR));
394 pCMD->result[i]=(unsigned char)read_fdc_byte();
399 /* selects the drive assigned in the cmd structur and
400 switches on the Motor */
401 void select_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
405 val=(1<<(4+pCMD->drive))|pCMD->drive|0xC; /* set reset, dma gate and motor bits */
406 if((read_fdc_reg(FDC_DOR)&val)!=val) {
407 write_fdc_reg(FDC_DOR,val);
408 for(val=0;val<255;val++)
409 udelay(500); /* wait some time to start motor */
413 /* switches off the Motor of the specified drive */
414 void stop_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
418 val=(1<<(4+pCMD->drive))|pCMD->drive; /* sets motor bits */
419 write_fdc_reg(FDC_DOR,(read_fdc_reg(FDC_DOR)&~val));
422 /* issues a recalibrate command, waits for interrupt and
423 * issues a sense_interrupt */
424 int fdc_recalibrate(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
426 pCMD->cmd[COMMAND]=FDC_CMD_RECALIBRATE;
427 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
429 while(wait_for_fdc_int()!=TRUE);
430 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
431 return(fdc_issue_cmd(pCMD,pFG));
434 /* issues a recalibrate command, waits for interrupt and
435 * issues a sense_interrupt */
436 int fdc_seek(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
438 pCMD->cmd[COMMAND]=FDC_CMD_SEEK;
439 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
441 while(wait_for_fdc_int()!=TRUE);
442 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
443 return(fdc_issue_cmd(pCMD,pFG));
446 #ifndef CONFIG_AMIGAONEG3SE
447 /* terminates current command, by not servicing the FIFO
448 * waits for interrupt and fills in the result bytes */
449 int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
453 udelay(500); /* wait 500usec for fifo overrun */
454 while((read_fdc_reg(FDC_SRA)&0x80)==0x00); /* wait as long as no int has occured */
456 pCMD->result[i]=(unsigned char)read_fdc_byte();
461 #ifdef CONFIG_AMIGAONEG3SE
462 int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
466 udelay(500); /* wait 500usec for fifo overrun */
467 while((INT6_Status&0x80)==0x00); /* wait as long as no int has occured */
469 pCMD->result[i]=(unsigned char)read_fdc_byte();
477 #ifdef CONFIG_AMIGAONEG3SE
478 #define disable_interrupts() 0
479 #define enable_interrupts() (void)0
482 /* reads data from FDC, seek commands are issued automatic */
483 int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
485 /* first seek to start address */
486 unsigned long len,lastblk,readblk,i,timeout,ii,offset;
487 unsigned char pcn,c,retriesrw,retriescal;
488 unsigned char *bufferw; /* working buffer */
492 flags=disable_interrupts(); /* switch off all Interrupts */
493 select_fdc_drive(pCMD); /* switch on drive */
494 sect_size=0x080<<pFG->sect_code;
498 if(fdc_seek(pCMD,pFG)==FALSE) {
499 stop_fdc_drive(pCMD);
503 if((pCMD->result[STATUS_0]&0x20)!=0x20) {
504 printf("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
505 stop_fdc_drive(pCMD);
509 pcn=pCMD->result[STATUS_PCN]; /* current track */
510 /* now determine the next seek point */
511 lastblk=pCMD->blnr + blocks;
512 /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
513 readblk=pFG->sect-(pCMD->blnr%pFG->sect);
514 PRINTF("1st nr of block possible read %ld start %ld\n",readblk,pCMD->blnr);
515 if(readblk>blocks) /* is end within 1st track */
516 readblk=blocks; /* yes, correct it */
517 PRINTF("we read %ld blocks start %ld\n",readblk,pCMD->blnr);
518 bufferw=&buffer[0]; /* setup working buffer */
521 len=sect_size * readblk;
522 pCMD->cmd[COMMAND]=FDC_CMD_READ;
523 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
524 stop_fdc_drive(pCMD);
528 for (i=0;i<len;i++) {
529 timeout=FDC_TIME_OUT;
531 c=read_fdc_reg(FDC_MSR);
533 bufferw[i]=read_fdc_reg(FDC_FIFO);
536 if((c&0xC0)==0x80) { /* output */
537 PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i,c);
539 for(ii=0;ii<7;ii++) {
540 pCMD->result[ii]=bufferw[(i-7+ii)];
543 if(retriesrw++>FDC_RW_RETRIES) {
544 if (retriescal++>FDC_CAL_RETRIES) {
545 stop_fdc_drive(pCMD);
550 PRINTF(" trying to recalibrate Try %d\n",retriescal);
551 if(fdc_recalibrate(pCMD,pFG)==FALSE) {
552 stop_fdc_drive(pCMD);
558 } /* else >FDC_CAL_RETRIES */
561 PRINTF("Read retry %d\n",retriesrw);
563 } /* else >FDC_RW_RETRIES */
568 /* the last sector of a track or all data has been read,
569 * we need to get the results */
571 offset+=(sect_size*readblk); /* set up buffer pointer */
572 bufferw=&buffer[offset];
573 pCMD->blnr+=readblk; /* update current block nr */
574 blocks-=readblk; /* update blocks */
576 break; /* we are finish */
577 /* setup new read blocks */
578 /* readblk=pFG->head*pFG->sect; */
583 /* a seek is necessary */
584 if(fdc_seek(pCMD,pFG)==FALSE) {
585 stop_fdc_drive(pCMD);
589 if((pCMD->result[STATUS_0]&0x20)!=0x20) {
590 PRINTF("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
591 stop_fdc_drive(pCMD);
594 pcn=pCMD->result[STATUS_PCN]; /* current track */
595 }while(TRUE); /* start over */
596 stop_fdc_drive(pCMD); /* switch off drive */
601 #ifdef CONFIG_AMIGAONEG3SE
602 #undef disable_interrupts()
603 #undef enable_interrupts()
606 /* Scan all drives and check if drive is present and disk is inserted */
607 int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
610 /* OK procedure of data book is satisfied.
611 * trying to get some information over the drives */
612 state=0; /* no drives, no disks */
613 for(drives=0;drives<4;drives++) {
615 select_fdc_drive(pCMD);
616 pCMD->blnr=0; /* set to the 1st block */
617 if(fdc_recalibrate(pCMD,pFG)==FALSE)
619 if((pCMD->result[STATUS_0]&0x10)==0x10)
621 /* ok drive connected check for disk */
623 pCMD->blnr=pFG->size; /* set to the last block */
624 if(fdc_seek(pCMD,pFG)==FALSE)
626 pCMD->blnr=0; /* set to the 1st block */
627 if(fdc_recalibrate(pCMD,pFG)==FALSE)
629 pCMD->cmd[COMMAND]=FDC_CMD_READ_ID;
630 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
632 state|=(0x10<<drives);
634 stop_fdc_drive(pCMD);
636 PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i,
637 ((state&(1<<i))==(1<<i)) ? "":"not ",
638 ((state&(0x10<<i))==(0x10<<i)) ? "":"no ",
639 ((state&(0x10<<i))==(0x10<<i)) ? pFG->name : "");
646 /**************************************************************************
648 * setup the fdc according the datasheet
649 * assuming in PS2 Mode
651 int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
655 #ifdef CONFIG_AMIGAONEG3SE
656 irq_install_handler(6, (interrupt_handler_t *)fdc_interrupt, NULL);
660 #ifdef CFG_FDC_HW_INIT
663 /* first, we reset the FDC via the DOR */
664 write_fdc_reg(FDC_DOR,0x00);
665 for(i=0; i<255; i++) /* then we wait some time */
667 /* then, we clear the reset in the DOR */
669 select_fdc_drive(pCMD);
670 /* initialize the CCR */
671 write_fdc_reg(FDC_CCR,pFG->rate);
672 /* then initialize the DSR */
673 write_fdc_reg(FDC_DSR,pFG->rate);
674 if(wait_for_fdc_int()==FALSE) {
675 PRINTF("Time Out after writing CCR\n");
678 /* now issue sense Interrupt and status command
679 * assuming only one drive present (drive 0) */
680 pCMD->dma=0; /* we don't use any dma at all */
682 /* issue sense interrupt for all 4 possible drives */
683 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
684 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
685 PRINTF("Sense Interrupt for drive %d failed\n",i);
688 /* issue the configure command */
690 select_fdc_drive(pCMD);
691 pCMD->cmd[COMMAND]=FDC_CMD_CONFIGURE;
692 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
693 PRINTF(" configure timeout\n");
694 stop_fdc_drive(pCMD);
697 /* issue specify command */
698 pCMD->cmd[COMMAND]=FDC_CMD_SPECIFY;
699 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
700 PRINTF(" specify timeout\n");
701 stop_fdc_drive(pCMD);
705 /* then, we clear the reset in the DOR */
706 /* fdc_check_drive(pCMD,pFG); */
707 /* write_fdc_reg(FDC_DOR,0x04); */
711 #endif /* ((CONFIG_COMMANDS & CFG_CMD_FDC)||(CONFIG_COMMANDS & CFG_CMD_FDOS))*/
713 #if (CONFIG_COMMANDS & CFG_CMD_FDOS) || defined(CONFIG_CMD_FDOS)
715 /* Low level functions for the Floppy-DOS layer */
717 /**************************************************************************
719 * initialize the FDC layer
722 int fdc_fdos_init (int drive)
724 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
725 FDC_COMMAND_STRUCT *pCMD = &cmd;
727 /* setup FDC and scan for drives */
728 if(fdc_setup(drive,pCMD,pFG)==FALSE) {
729 printf("\n** Error in setup FDC **\n");
732 if(fdc_check_drive(pCMD,pFG)==FALSE) {
733 printf("\n** Error in check_drives **\n");
736 if((pCMD->flags&(1<<drive))==0) {
737 /* drive not available */
738 printf("\n** Drive %d not available **\n",drive);
741 if((pCMD->flags&(0x10<<drive))==0) {
742 /* no disk inserted */
743 printf("\n** No disk inserted in drive %d **\n",drive);
746 /* ok, we have a valid source */
749 /* read first block */
753 /**************************************************************************
755 * parameter is a block number
757 int fdc_fdos_seek (int where)
759 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
760 FDC_COMMAND_STRUCT *pCMD = &cmd;
762 pCMD -> blnr = where ;
763 return (fdc_seek (pCMD, pFG));
765 /**************************************************************************
767 * the length is in block number
769 int fdc_fdos_read (void *buffer, int len)
771 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
772 FDC_COMMAND_STRUCT *pCMD = &cmd;
774 return (fdc_read_data (buffer, len, pCMD, pFG));
776 #endif /* (CONFIG_COMMANDS & CFG_CMD_FDOS) */
778 #if (CONFIG_COMMANDS & CFG_CMD_FDC) || defined(CONFIG_CMD_FDC)
779 /****************************************************************************
780 * main routine do_fdcboot
782 int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
784 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
785 FDC_COMMAND_STRUCT *pCMD = &cmd;
786 unsigned long addr,imsize;
787 image_header_t *hdr; /* used for fdc boot */
788 unsigned char boot_drive;
795 addr = CFG_LOAD_ADDR;
796 boot_drive=CFG_FDC_DRIVE_NUMBER;
799 addr = simple_strtoul(argv[1], NULL, 16);
800 boot_drive=CFG_FDC_DRIVE_NUMBER;
803 addr = simple_strtoul(argv[1], NULL, 16);
804 boot_drive=simple_strtoul(argv[2], NULL, 10);
807 printf ("Usage:\n%s\n", cmdtp->usage);
810 /* setup FDC and scan for drives */
811 if(fdc_setup(boot_drive,pCMD,pFG)==FALSE) {
812 printf("\n** Error in setup FDC **\n");
815 if(fdc_check_drive(pCMD,pFG)==FALSE) {
816 printf("\n** Error in check_drives **\n");
819 if((pCMD->flags&(1<<boot_drive))==0) {
820 /* drive not available */
821 printf("\n** Drive %d not availabe **\n",boot_drive);
824 if((pCMD->flags&(0x10<<boot_drive))==0) {
825 /* no disk inserted */
826 printf("\n** No disk inserted in drive %d **\n",boot_drive);
829 /* ok, we have a valid source */
830 pCMD->drive=boot_drive;
831 /* read first block */
833 if(fdc_read_data((unsigned char *)addr,1,pCMD,pFG)==FALSE) {
834 printf("\nRead error:");
836 printf("result%d: 0x%02X\n",i,pCMD->result[i]);
839 hdr = (image_header_t *)addr;
840 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
841 printf ("Bad Magic Number\n");
844 print_image_hdr(hdr);
846 imsize= ntohl(hdr->ih_size)+sizeof(image_header_t);
850 printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr);
852 if(fdc_read_data((unsigned char *)addr,nrofblk,pCMD,pFG)==FALSE) {
853 /* read image block */
854 printf("\nRead error:");
856 printf("result%d: 0x%02X\n",i,pCMD->result[i]);
859 printf("OK %ld Bytes loaded.\n",imsize);
861 flush_cache (addr, imsize);
862 /* Loading ok, update default load address */
865 if(hdr->ih_type == IH_TYPE_KERNEL) {
866 /* Check if we should attempt an auto-start */
867 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
869 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
871 local_args[0] = argv[0];
872 local_args[1] = NULL;
874 printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
876 do_bootm (cmdtp, 0, 1, local_args);
884 #endif /* CONFIG_COMMANDS & CFG_CMD_FDC */
887 /***************************************************/
890 #if (CONFIG_COMMANDS & CFG_CMD_FDC) || defined(CONFIG_CMD_FDC)
893 fdcboot, 3, 1, do_fdcboot,
894 "fdcboot - boot from floppy device\n",