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...)
49 /*#if defined(CONFIG_CMD_DATE) */
54 int flags; /* connected drives ect */
55 unsigned long blnr; /* Logical block nr */
56 uchar drive; /* drive no */
57 uchar cmdlen; /* cmd length */
58 uchar cmd[16]; /* cmd desc */
59 uchar dma; /* if > 0 dma enabled */
60 uchar result[11]; /* status information */
61 uchar resultlen; /* lenght of result */
64 /* flags: only the lower 8bit used:
65 * bit 0 if set drive 0 is present
66 * bit 1 if set drive 1 is present
67 * bit 2 if set drive 2 is present
68 * bit 3 if set drive 3 is present
69 * bit 4 if set disk in drive 0 is inserted
70 * bit 5 if set disk in drive 1 is inserted
71 * bit 6 if set disk in drive 2 is inserted
72 * bit 7 if set disk in drive 4 is inserted
95 #define STATUS_TRACK 3
98 #define STATUS_SECT_SIZE 6
101 /* Register addresses */
102 #define FDC_BASE 0x3F0
103 #define FDC_SRA FDC_BASE + 0 /* Status Register A */
104 #define FDC_SRB FDC_BASE + 1 /* Status Register B */
105 #define FDC_DOR FDC_BASE + 2 /* Digital Output Register */
106 #define FDC_TDR FDC_BASE + 3 /* Tape Drive Register */
107 #define FDC_DSR FDC_BASE + 4 /* Data rate Register */
108 #define FDC_MSR FDC_BASE + 4 /* Main Status Register */
109 #define FDC_FIFO FDC_BASE + 5 /* FIFO */
110 #define FDC_DIR FDC_BASE + 6 /* Digital Input Register */
111 #define FDC_CCR FDC_BASE + 7 /* Configuration Control */
113 #define FDC_CMD_SENSE_INT 0x08
114 #define FDC_CMD_CONFIGURE 0x13
115 #define FDC_CMD_SPECIFY 0x03
116 #define FDC_CMD_RECALIBRATE 0x07
117 #define FDC_CMD_READ 0x06
118 #define FDC_CMD_READ_TRACK 0x02
119 #define FDC_CMD_READ_ID 0x0A
120 #define FDC_CMD_DUMP_REG 0x0E
121 #define FDC_CMD_SEEK 0x0F
123 #define FDC_CMD_SENSE_INT_LEN 0x01
124 #define FDC_CMD_CONFIGURE_LEN 0x04
125 #define FDC_CMD_SPECIFY_LEN 0x03
126 #define FDC_CMD_RECALIBRATE_LEN 0x02
127 #define FDC_CMD_READ_LEN 0x09
128 #define FDC_CMD_READ_TRACK_LEN 0x09
129 #define FDC_CMD_READ_ID_LEN 0x02
130 #define FDC_CMD_DUMP_REG_LEN 0x01
131 #define FDC_CMD_SEEK_LEN 0x03
133 #define FDC_FIFO_THR 0x0C
134 #define FDC_FIFO_DIS 0x00
135 #define FDC_IMPLIED_SEEK 0x01
136 #define FDC_POLL_DIS 0x00
137 #define FDC_PRE_TRK 0x00
138 #define FDC_CONFIGURE FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
139 #define FDC_MFM_MODE 0x01 /* MFM enable */
140 #define FDC_SKIP_MODE 0x00 /* skip enable */
142 #define FDC_TIME_OUT 100000 /* time out */
143 #define FDC_RW_RETRIES 3 /* read write retries */
144 #define FDC_CAL_RETRIES 3 /* calibration and seek retries */
149 unsigned int size; /* nr of sectors total */
150 unsigned int sect; /* sectors per track */
151 unsigned int head; /* nr of heads */
152 unsigned int track; /* nr of tracks */
153 unsigned int stretch; /* !=0 means double track steps */
154 unsigned char gap; /* gap1 size */
155 unsigned char rate; /* data rate. |= 0x40 for perpendicular */
156 unsigned char spec1; /* stepping rate, head unload time */
157 unsigned char fmt_gap;/* gap2 size */
158 unsigned char hlt; /* head load time */
159 unsigned char sect_code;/* Sector Size code */
160 const char * name; /* used only for predefined formats */
164 /* supported Floppy types (currently only one) */
165 const static FD_GEO_STRUCT floppy_type[2] = {
166 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" }, /* 7 1.44MB 3.5" */
167 { 0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL }, /* end of table */
170 static FDC_COMMAND_STRUCT cmd; /* global command struct */
172 /* If the boot drive number is undefined, we assume it's drive 0 */
173 #ifndef CONFIG_SYS_FDC_DRIVE_NUMBER
174 #define CONFIG_SYS_FDC_DRIVE_NUMBER 0
177 /* Hardware access */
178 #ifndef CONFIG_SYS_ISA_IO_STRIDE
179 #define CONFIG_SYS_ISA_IO_STRIDE 1
182 #ifndef CONFIG_SYS_ISA_IO_OFFSET
183 #define CONFIG_SYS_ISA_IO_OFFSET 0
186 /* Supporting Functions */
187 /* reads a Register of the FDC */
188 unsigned char read_fdc_reg(unsigned int addr)
190 volatile unsigned char *val =
191 (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
192 (addr * CONFIG_SYS_ISA_IO_STRIDE) +
193 CONFIG_SYS_ISA_IO_OFFSET);
198 /* writes a Register of the FDC */
199 void write_fdc_reg(unsigned int addr, unsigned char val)
201 volatile unsigned char *tmp =
202 (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
203 (addr * CONFIG_SYS_ISA_IO_STRIDE) +
204 CONFIG_SYS_ISA_IO_OFFSET);
208 /* waits for an interrupt (polling) */
209 int wait_for_fdc_int(void)
211 unsigned long timeout;
212 timeout = FDC_TIME_OUT;
213 while((read_fdc_reg(FDC_SRA)&0x80)==0) {
216 if(timeout==0) /* timeout occured */
222 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
223 of the MSR. returns -1 if timeout, or byte if ok */
224 int read_fdc_byte(void)
226 unsigned long timeout;
227 timeout = FDC_TIME_OUT;
228 while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
229 /* direction out and ready */
232 if(timeout==0) /* timeout occured */
235 return read_fdc_reg(FDC_FIFO);
238 /* if the direction of the FIFO is wrong, this routine is used to
239 empty the FIFO. Should _not_ be used */
240 int fdc_need_more_output(void)
243 while((read_fdc_reg(FDC_MSR)&0xC0)==0xC0) {
244 c=(unsigned char)read_fdc_byte();
245 printf("Error: more output: %x\n",c);
251 /* writes a byte to the FIFO of the FDC and checks direction and RQM bit
253 int write_fdc_byte(unsigned char val)
255 unsigned long timeout;
256 timeout = FDC_TIME_OUT;
257 while((read_fdc_reg(FDC_MSR)&0xC0)!=0x80) {
258 /* direction in and ready for byte */
261 fdc_need_more_output();
262 if(timeout==0) /* timeout occured */
265 write_fdc_reg(FDC_FIFO,val);
269 /* sets up all FDC commands and issues it to the FDC. If
270 the command causes direct results (no Execution Phase)
271 the result is be read as well. */
273 int fdc_issue_cmd(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
276 unsigned long head,track,sect,timeout;
277 track = pCMD->blnr / (pFG->sect * pFG->head); /* track nr */
278 sect = pCMD->blnr % (pFG->sect * pFG->head); /* remaining blocks */
279 head = sect / pFG->sect; /* head nr */
280 sect = sect % pFG->sect; /* remaining blocks */
281 sect++; /* sectors are 1 based */
282 PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
283 pCMD->cmd[0],track,head,sect,pCMD->drive,pCMD->blnr);
285 if(head|=0) { /* max heads = 2 */
286 pCMD->cmd[DRIVE]=pCMD->drive | 0x04; /* head 1 */
287 pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
290 pCMD->cmd[DRIVE]=pCMD->drive; /* head 0 */
291 pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
293 pCMD->cmd[TRACK]=(unsigned char) track; /* track */
294 switch (pCMD->cmd[COMMAND]) {
296 pCMD->cmd[SECTOR]=(unsigned char) sect; /* sector */
297 pCMD->cmd[SECTOR_SIZE]=pFG->sect_code; /* sector size code */
298 pCMD->cmd[LAST_TRACK]=pFG->sect; /* End of track */
299 pCMD->cmd[GAP]=pFG->gap; /* gap */
300 pCMD->cmd[DTL]=0xFF; /* DTL */
301 pCMD->cmdlen=FDC_CMD_READ_LEN;
302 pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
303 pCMD->cmd[COMMAND]|=(FDC_SKIP_MODE<<5); /* set Skip bit */
304 pCMD->resultlen=0; /* result only after execution */
307 pCMD->cmdlen=FDC_CMD_SEEK_LEN;
308 pCMD->resultlen=0; /* no result */
310 case FDC_CMD_CONFIGURE:
311 pCMD->cmd[CONFIG0]=0;
312 pCMD->cmd[CONFIG1]=FDC_CONFIGURE; /* FIFO Threshold, Poll, Enable FIFO */
313 pCMD->cmd[CONFIG2]=FDC_PRE_TRK; /* Precompensation Track */
314 pCMD->cmdlen=FDC_CMD_CONFIGURE_LEN;
315 pCMD->resultlen=0; /* no result */
317 case FDC_CMD_SPECIFY:
318 pCMD->cmd[SPEC_HUTSRT]=pFG->spec1;
319 pCMD->cmd[SPEC_HLT]=(pFG->hlt)<<1; /* head load time */
321 pCMD->cmd[SPEC_HLT]|=0x1; /* no dma */
322 pCMD->cmdlen=FDC_CMD_SPECIFY_LEN;
323 pCMD->resultlen=0; /* no result */
325 case FDC_CMD_DUMP_REG:
326 pCMD->cmdlen=FDC_CMD_DUMP_REG_LEN;
327 pCMD->resultlen=10; /* 10 byte result */
329 case FDC_CMD_READ_ID:
330 pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
331 pCMD->cmdlen=FDC_CMD_READ_ID_LEN;
332 pCMD->resultlen=7; /* 7 byte result */
334 case FDC_CMD_RECALIBRATE:
335 pCMD->cmd[DRIVE]&=0x03; /* don't set the head bit */
336 pCMD->cmdlen=FDC_CMD_RECALIBRATE_LEN;
337 pCMD->resultlen=0; /* no result */
340 case FDC_CMD_SENSE_INT:
341 pCMD->cmdlen=FDC_CMD_SENSE_INT_LEN;
345 for(i=0;i<pCMD->cmdlen;i++) {
346 /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
347 if(write_fdc_byte(pCMD->cmd[i])==FALSE) {
348 PRINTF("Error: timeout while issue cmd%d\n",i);
352 timeout=FDC_TIME_OUT;
353 for(i=0;i<pCMD->resultlen;i++) {
354 while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
357 PRINTF(" timeout while reading result%d MSR=0x%02X\n",i,read_fdc_reg(FDC_MSR));
361 pCMD->result[i]=(unsigned char)read_fdc_byte();
366 /* selects the drive assigned in the cmd structur and
367 switches on the Motor */
368 void select_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
372 val=(1<<(4+pCMD->drive))|pCMD->drive|0xC; /* set reset, dma gate and motor bits */
373 if((read_fdc_reg(FDC_DOR)&val)!=val) {
374 write_fdc_reg(FDC_DOR,val);
375 for(val=0;val<255;val++)
376 udelay(500); /* wait some time to start motor */
380 /* switches off the Motor of the specified drive */
381 void stop_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
385 val=(1<<(4+pCMD->drive))|pCMD->drive; /* sets motor bits */
386 write_fdc_reg(FDC_DOR,(read_fdc_reg(FDC_DOR)&~val));
389 /* issues a recalibrate command, waits for interrupt and
390 * issues a sense_interrupt */
391 int fdc_recalibrate(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
393 pCMD->cmd[COMMAND]=FDC_CMD_RECALIBRATE;
394 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
396 while(wait_for_fdc_int()!=TRUE);
397 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
398 return(fdc_issue_cmd(pCMD,pFG));
401 /* issues a recalibrate command, waits for interrupt and
402 * issues a sense_interrupt */
403 int fdc_seek(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
405 pCMD->cmd[COMMAND]=FDC_CMD_SEEK;
406 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
408 while(wait_for_fdc_int()!=TRUE);
409 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
410 return(fdc_issue_cmd(pCMD,pFG));
413 /* terminates current command, by not servicing the FIFO
414 * waits for interrupt and fills in the result bytes */
415 int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
419 udelay(500); /* wait 500usec for fifo overrun */
420 while((read_fdc_reg(FDC_SRA)&0x80)==0x00); /* wait as long as no int has occured */
422 pCMD->result[i]=(unsigned char)read_fdc_byte();
427 /* reads data from FDC, seek commands are issued automatic */
428 int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
430 /* first seek to start address */
431 unsigned long len,lastblk,readblk,i,timeout,ii,offset;
432 unsigned char pcn,c,retriesrw,retriescal;
433 unsigned char *bufferw; /* working buffer */
437 flags=disable_interrupts(); /* switch off all Interrupts */
438 select_fdc_drive(pCMD); /* switch on drive */
439 sect_size=0x080<<pFG->sect_code;
443 if(fdc_seek(pCMD,pFG)==FALSE) {
444 stop_fdc_drive(pCMD);
448 if((pCMD->result[STATUS_0]&0x20)!=0x20) {
449 printf("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
450 stop_fdc_drive(pCMD);
454 pcn=pCMD->result[STATUS_PCN]; /* current track */
455 /* now determine the next seek point */
456 lastblk=pCMD->blnr + blocks;
457 /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
458 readblk=pFG->sect-(pCMD->blnr%pFG->sect);
459 PRINTF("1st nr of block possible read %ld start %ld\n",readblk,pCMD->blnr);
460 if(readblk>blocks) /* is end within 1st track */
461 readblk=blocks; /* yes, correct it */
462 PRINTF("we read %ld blocks start %ld\n",readblk,pCMD->blnr);
463 bufferw = &buffer[0]; /* setup working buffer */
466 len=sect_size * readblk;
467 pCMD->cmd[COMMAND]=FDC_CMD_READ;
468 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
469 stop_fdc_drive(pCMD);
473 for (i=0;i<len;i++) {
474 timeout=FDC_TIME_OUT;
476 c=read_fdc_reg(FDC_MSR);
478 bufferw[i]=read_fdc_reg(FDC_FIFO);
481 if((c&0xC0)==0x80) { /* output */
482 PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i,c);
484 for(ii=0;ii<7;ii++) {
485 pCMD->result[ii]=bufferw[(i-7+ii)];
488 if(retriesrw++>FDC_RW_RETRIES) {
489 if (retriescal++>FDC_CAL_RETRIES) {
490 stop_fdc_drive(pCMD);
495 PRINTF(" trying to recalibrate Try %d\n",retriescal);
496 if(fdc_recalibrate(pCMD,pFG)==FALSE) {
497 stop_fdc_drive(pCMD);
503 } /* else >FDC_CAL_RETRIES */
506 PRINTF("Read retry %d\n",retriesrw);
508 } /* else >FDC_RW_RETRIES */
513 /* the last sector of a track or all data has been read,
514 * we need to get the results */
516 offset+=(sect_size*readblk); /* set up buffer pointer */
517 bufferw = &buffer[offset];
518 pCMD->blnr+=readblk; /* update current block nr */
519 blocks-=readblk; /* update blocks */
521 break; /* we are finish */
522 /* setup new read blocks */
523 /* readblk=pFG->head*pFG->sect; */
528 /* a seek is necessary */
529 if(fdc_seek(pCMD,pFG)==FALSE) {
530 stop_fdc_drive(pCMD);
534 if((pCMD->result[STATUS_0]&0x20)!=0x20) {
535 PRINTF("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
536 stop_fdc_drive(pCMD);
539 pcn=pCMD->result[STATUS_PCN]; /* current track */
540 }while(TRUE); /* start over */
541 stop_fdc_drive(pCMD); /* switch off drive */
546 /* Scan all drives and check if drive is present and disk is inserted */
547 int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
550 /* OK procedure of data book is satisfied.
551 * trying to get some information over the drives */
552 state=0; /* no drives, no disks */
553 for(drives=0;drives<4;drives++) {
555 select_fdc_drive(pCMD);
556 pCMD->blnr=0; /* set to the 1st block */
557 if(fdc_recalibrate(pCMD,pFG)==FALSE)
559 if((pCMD->result[STATUS_0]&0x10)==0x10)
561 /* ok drive connected check for disk */
563 pCMD->blnr=pFG->size; /* set to the last block */
564 if(fdc_seek(pCMD,pFG)==FALSE)
566 pCMD->blnr=0; /* set to the 1st block */
567 if(fdc_recalibrate(pCMD,pFG)==FALSE)
569 pCMD->cmd[COMMAND]=FDC_CMD_READ_ID;
570 if(fdc_issue_cmd(pCMD,pFG)==FALSE)
572 state|=(0x10<<drives);
574 stop_fdc_drive(pCMD);
576 PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i,
577 ((state&(1<<i))==(1<<i)) ? "":"not ",
578 ((state&(0x10<<i))==(0x10<<i)) ? "":"no ",
579 ((state&(0x10<<i))==(0x10<<i)) ? pFG->name : "");
586 /**************************************************************************
588 * setup the fdc according the datasheet
589 * assuming in PS2 Mode
591 int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
595 #ifdef CONFIG_SYS_FDC_HW_INIT
598 /* first, we reset the FDC via the DOR */
599 write_fdc_reg(FDC_DOR,0x00);
600 for(i=0; i<255; i++) /* then we wait some time */
602 /* then, we clear the reset in the DOR */
604 select_fdc_drive(pCMD);
605 /* initialize the CCR */
606 write_fdc_reg(FDC_CCR,pFG->rate);
607 /* then initialize the DSR */
608 write_fdc_reg(FDC_DSR,pFG->rate);
609 if(wait_for_fdc_int()==FALSE) {
610 PRINTF("Time Out after writing CCR\n");
613 /* now issue sense Interrupt and status command
614 * assuming only one drive present (drive 0) */
615 pCMD->dma=0; /* we don't use any dma at all */
617 /* issue sense interrupt for all 4 possible drives */
618 pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
619 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
620 PRINTF("Sense Interrupt for drive %d failed\n",i);
623 /* issue the configure command */
625 select_fdc_drive(pCMD);
626 pCMD->cmd[COMMAND]=FDC_CMD_CONFIGURE;
627 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
628 PRINTF(" configure timeout\n");
629 stop_fdc_drive(pCMD);
632 /* issue specify command */
633 pCMD->cmd[COMMAND]=FDC_CMD_SPECIFY;
634 if(fdc_issue_cmd(pCMD,pFG)==FALSE) {
635 PRINTF(" specify timeout\n");
636 stop_fdc_drive(pCMD);
640 /* then, we clear the reset in the DOR */
641 /* fdc_check_drive(pCMD,pFG); */
642 /* write_fdc_reg(FDC_DOR,0x04); */
647 #if defined(CONFIG_CMD_FDOS)
649 /* Low level functions for the Floppy-DOS layer */
651 /**************************************************************************
653 * initialize the FDC layer
656 int fdc_fdos_init (int drive)
658 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
659 FDC_COMMAND_STRUCT *pCMD = &cmd;
661 /* setup FDC and scan for drives */
662 if(fdc_setup(drive,pCMD,pFG)==FALSE) {
663 printf("\n** Error in setup FDC **\n");
666 if(fdc_check_drive(pCMD,pFG)==FALSE) {
667 printf("\n** Error in check_drives **\n");
670 if((pCMD->flags&(1<<drive))==0) {
671 /* drive not available */
672 printf("\n** Drive %d not available **\n",drive);
675 if((pCMD->flags&(0x10<<drive))==0) {
676 /* no disk inserted */
677 printf("\n** No disk inserted in drive %d **\n",drive);
680 /* ok, we have a valid source */
683 /* read first block */
687 /**************************************************************************
689 * parameter is a block number
691 int fdc_fdos_seek (int where)
693 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
694 FDC_COMMAND_STRUCT *pCMD = &cmd;
696 pCMD -> blnr = where ;
697 return (fdc_seek (pCMD, pFG));
699 /**************************************************************************
701 * the length is in block number
703 int fdc_fdos_read (void *buffer, int len)
705 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
706 FDC_COMMAND_STRUCT *pCMD = &cmd;
708 return (fdc_read_data (buffer, len, pCMD, pFG));
712 #if defined(CONFIG_CMD_FDC)
713 /****************************************************************************
714 * main routine do_fdcboot
716 int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
718 FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
719 FDC_COMMAND_STRUCT *pCMD = &cmd;
720 unsigned long addr,imsize;
721 image_header_t *hdr; /* used for fdc boot */
722 unsigned char boot_drive;
726 #if defined(CONFIG_FIT)
727 const void *fit_hdr = NULL;
732 addr = CONFIG_SYS_LOAD_ADDR;
733 boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
736 addr = simple_strtoul(argv[1], NULL, 16);
737 boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
740 addr = simple_strtoul(argv[1], NULL, 16);
741 boot_drive=simple_strtoul(argv[2], NULL, 10);
744 return cmd_usage(cmdtp);
746 /* setup FDC and scan for drives */
747 if(fdc_setup(boot_drive,pCMD,pFG)==FALSE) {
748 printf("\n** Error in setup FDC **\n");
751 if(fdc_check_drive(pCMD,pFG)==FALSE) {
752 printf("\n** Error in check_drives **\n");
755 if((pCMD->flags&(1<<boot_drive))==0) {
756 /* drive not available */
757 printf("\n** Drive %d not availabe **\n",boot_drive);
760 if((pCMD->flags&(0x10<<boot_drive))==0) {
761 /* no disk inserted */
762 printf("\n** No disk inserted in drive %d **\n",boot_drive);
765 /* ok, we have a valid source */
766 pCMD->drive=boot_drive;
767 /* read first block */
769 if(fdc_read_data((unsigned char *)addr,1,pCMD,pFG)==FALSE) {
770 printf("\nRead error:");
772 printf("result%d: 0x%02X\n",i,pCMD->result[i]);
776 switch (genimg_get_format ((void *)addr)) {
777 case IMAGE_FORMAT_LEGACY:
778 hdr = (image_header_t *)addr;
779 image_print_contents (hdr);
781 imsize = image_get_image_size (hdr);
783 #if defined(CONFIG_FIT)
784 case IMAGE_FORMAT_FIT:
785 fit_hdr = (const void *)addr;
786 puts ("Fit image detected...\n");
788 imsize = fit_get_size (fit_hdr);
792 puts ("** Unknown image type\n");
799 printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr);
801 if(fdc_read_data((unsigned char *)addr,nrofblk,pCMD,pFG)==FALSE) {
802 /* read image block */
803 printf("\nRead error:");
805 printf("result%d: 0x%02X\n",i,pCMD->result[i]);
808 printf("OK %ld Bytes loaded.\n",imsize);
810 flush_cache (addr, imsize);
812 #if defined(CONFIG_FIT)
813 /* This cannot be done earlier, we need complete FIT image in RAM first */
814 if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
815 if (!fit_check_format (fit_hdr)) {
816 puts ("** Bad FIT image format\n");
819 fit_print_contents (fit_hdr);
823 /* Loading ok, update default load address */
826 /* Check if we should attempt an auto-start */
827 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
830 local_args[0] = argv[0];
831 local_args[1] = NULL;
833 printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
835 do_bootm (cmdtp, 0, 1, local_args);
842 fdcboot, 3, 1, do_fdcboot,
843 "boot from floppy device",