📄 main.c.new
字号:
/***************************************** Copyright (c) 2001-2002 Sigma Designs, Inc. All Rights Reserved Proprietary and Confidential *****************************************//* This is file is part of the Jasper DVD boot loader */#include "config.h"#include "fipuser.h"#include "fip_scancodes.h"#include "uart.h"#include "atapi.h"#include "util.h"//// external functions//// from bootflash.cunsigned int try_boot_flash(unsigned int kload, unsigned int addr);// from bootdisc.cunsigned int try_boot_disc(unsigned int kload);// from bootmenu.cint bootmenu(unsigned int kload);unsigned int boot_status;unsigned short buffer[2048];#if 0void dump(unsigned short *buf, int count){ int i; char str[16]; char c; for(i=0; i<count; i++) { if((i&0x7)==0) { PrintShort(i); PrintUart(" >| ",4); } PrintShort(buf[i]); c=buf[i]&0xFF; if(c<32 || c>=128) c='.'; str[2*(i&7)]=c; c=buf[i]>>8; if(c<32 || c>=128) c='.'; str[2*(i&7)+1]=c; PrintUart(" ",1); if((i&0x7)==7) { PrintUart(" |< ",4); PrintUart(str,16); PrintUart("\r\n",2); } }}#endif#if 1void wait_a_bit(){ int i,j; for(i=0;i<8;i++) {#ifndef QUICKTURN#ifndef ENABLE_CACHE for(j=0;j<300000;j++);#else for(j=0;j<300000*30;j++); #endif#endif }}#endif#ifdef QUICKTURN#include "jasper.h"#define PIO_SET_BIT1 0x00020002void InitPioInt(void){// Prepare PIO controller for generating an interrupt upon detecting// a TRIG_OUT signal // Set PIO0 pin 1 and 2 as INPUT pins *(PIO_0_DIR_REG) = 0x6FFF9; // Set polarity for falling edge detection *(PIO_0_POL_REG) = PIO_SET_BIT1; // Clear PIO interrupt at PIO0 pin 1 *(PIO_0_INT_STATUS_REG) = PIO_SET_BIT1; // Enable PIO interrupt at PIO0 pin 1 *(PIO_0_INT_ENABLE_REG) = PIO_SET_BIT1; // Read initial value of PIO_0 bit 2 switch// PIO0_2 = *(PIO_0_DATA_REG) & 0x00000004;}#endif //QUICKTURN// return non zero if a key is pressedint keypressed(void){ int i,k; k = fip_read_keys(0); for(i=0;i<=10000;i++);/* PrintUart("Fipkeys = ",30); PrintLong(k); PrintUart("\r\n",30);*/ return k;}void reset(void){ while(1);}#ifdef BOOT_TESTS//#include "jasper.h"int boot_tests(void){ char *buffer1, *buffer2; int tmp; int i,j; int cmd=0; InitUart(); PrintUart("\r\n*** UART INITIALIZATION DONE ***\r\n", 40);#ifdef QUASAR_SDRAM_TEST PrintUart("Doing the Quasar Sdram Test (QDT)\r\n",40); CQuasar__HwTimingInit(); testquasardram(0x100,0x1000); testquasardram(0xcf8,0x4000); testquasardram(0x8000,4*1024*1024); testquasardram(0x1000,1024*1024); /* testquasardram(1,0x1000); testquasardram(1,0x1000); */ /* failing tests */ testquasardram(0x100,0x1000); testquasardram(0xcf8,0x4000); PrintUart("All QDT Tests doone\r\n",40);#endif PrintUart("Whiling\r\n",30); while(1); }#endif // BOOT_TESTS#ifdef SUPPORT_BOOT_FROM_CDunsigned int try_boot_disc_pass(unsigned int kload, int pass){ if (pass == 0) { IdeInit (); if (keypressed() == SC_PANEL_EJECT) { PrintUart ("key pressed - tray ejected\r\n", 256); // for emergencies, just to be sure a disc will never be // stuck in the loader ... IdeTray (1); } if (keypressed() == SC_PANEL_STOP) { PrintUart ("Attempting to boot from cd\r\n", 256); fip_display_character (1, 'B'); fip_display_character (2, 'O'); fip_display_character (3, 'O'); fip_display_character (4, 'T'); fip_display_character (5, 'C'); fip_display_character (6, 'D'); wait_a_bit (); if (try_boot_disc(kload)) return 1; } } else { IdeInit(); IdeTray(1); while(keypressed() != SC_PANEL_EJECT); IdeTray(0); if(try_boot_disc(kload)) return 1; else PrintUart("boot_disc failed - insert bootable cd and reset\r\n",60); } return 0;}#endif // SUPPORT_BOOT_FROM_CD// XXX this is the normal entryint entry(void){#ifdef BOOT_TESTS boot_tests();#else unsigned long kload = KERNEL_LOAD_ADDRESS; // int h,m,s,t,c; // packet_command pc; // unsigned char sensedata[18];#ifdef QUICKTURN InitPioInt();#endif#ifdef ENABLE_UART InitUart(); PrintUart("\r\n*** UART INITIALIZATION DONE ***\r\n", 40); PrintUart("\r\nJasper Bootloader v" BOOTLOADER_VERSIONSTR " (" __DATE__ " " __TIME__ ")\r\n", -1); PrintUart("\r\nJasper Bootloader v" BOOTLOADER_VERSIONSTR " (" __DATE__ " " __TIME__ ")\r\n", -1); PrintUart(" Supports ", -1);#ifdef SUPPORT_BOOT_MENU PrintUart("BootMenu ", -1);#endif#ifdef SUPPORT_BOOT_FROM_CD PrintUart("CD_Boot ", -1);#endif#ifdef SUPPORT_FLASH PrintUart("Flash ", -1);#endif#ifdef SUPPORT_NETWORK PrintUart("Network ", -1);#endif PrintUart("\r\n", -1);#endif fip_loadmodule(); fip_open(); fip_clear();#ifdef PLAYER_PROSONIC fip_display_character (1, 'H'); fip_display_character (2, 'E'); fip_display_character (3, 'L'); fip_display_character (4, 'L'); fip_display_character (5, 'O');#else fip_display_text(FIP_TEXT_LOADING);#endif#if defined(ENABLE_UART) && defined(SUPPORT_BOOT_MENU) DELAY(50000); if (PeekChar() >= 0) { if (bootmenu(kload)) goto do_boot; }#endif#if 0 // ABS - Anti Blocking System (to avoid locking a disc in the player) IdeInit(); wait_a_bit(); IdeWaitReady(10000); wait_a_bit(); IdeTray(1); wait_a_bit(); IdeTray(0); wait_a_bit();#endif /* DVD Boot sequence : - If keypressed() returns true this means the user want to boot from the CD, so we try that first, and then we fall back to flash boot. - Otherwise we do the reverse, first boot from flash, and if it fails trye the CD - If boot fails, we open the CD tray at the end */#ifdef SUPPORT_BOOT_FROM_CD if (try_boot_disc_pass(kload, 0)) goto do_boot; if (1) {// we always try to boot from the cd first// drawback: this takes some extra time// advantage: it makes it "easier" for the user to do firmware upgrades // wait_a_bit ();// if(!try_boot_disc(kload)) { PrintUart("boot_disc failed - eject and try to boot from flash\r\n",60); if(!try_boot_flash(kload, ROMFS_START_ADDRESS)) { PrintUart("boot_flash failed - insert bootable cd and reset\r\n",60); goto boot_failed; } // } } else #endif { // try flash first if(!try_boot_flash(kload, ROMFS_START_ADDRESS)) {#ifdef SUPPORT_BOOT_FROM_CD PrintUart("boot_flash failed - try to boot from CD\r\n",60); if (try_boot_disc_pass(kload, 1)) goto do_boot;#else PrintUart("boot_flash failed\r\n", 60); goto boot_failed;#endif // SUPPORT_BOOT_FROM_CD } } do_boot: // return the adress to jump to PrintLong((unsigned long)kload); return (int)kload; boot_failed: // What to do when everything fails fip_clear(); fip_display_text(FIP_TEXT_ERROR); // eject disc#ifdef SUPPORT_BOOT_FROM_CD IdeTray(1);#endif // SUPPORT_BOOT_FROM_CD // Wait for key while(keypressed() != SC_PANEL_EJECT); // reset (this will close the tray) reset();#endif // BOOT_TESTS while(1);}#ifdef QUICKTURN#define PIO_0_DATA_REG ((volatile unsigned int *)0x00500604)#define PIO_1_DATA_REG ((volatile unsigned int *)0x00500A04)void fiq_handler(void) { int addr = 0x20; int timer =0, first=0; int range, i; int *address; int *destination; int pio2, pio3; int *end_bp=0x1F00; // end_bp[0] = from adress // end_bp[1] = to adress // end_bp[2] = word count // Clear PIO interrupt at PIO0 pin 1 *(PIO_0_INT_STATUS_REG) = PIO_SET_BIT1; *(PIO_1_DIR_REG)=0xFFFFFFFF; *(PIO_1_DATA_REG) = 0xFFFF1111; pio2 = (*(PIO_0_DATA_REG) & 4); pio3 = (*(PIO_0_DATA_REG) & 8); // Check if start switch was activated while((*(PIO_0_DATA_REG) & 4) == pio2 ) { // Constantly toggle PIO1 OUTPUT between 0xFFFF and 0x0000 *(PIO_1_DATA_REG) = 0xFFFF2222; if((*(PIO_0_DATA_REG) & 8) != pio3) { *(PIO_1_DATA_REG) = 0xFFFF3333; address = (int *)(end_bp[0]); destination = (int *)(end_bp[1]); range = end_bp[2]; for(i=0;i<range;i++) *destination++ = *address++; *(PIO_1_DATA_REG) = 0xFFFF4444; } *(PIO_1_DATA_REG) = 0xFFFF5555; } *(PIO_1_DATA_REG) = 0xFFFF6666; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -