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

📄 main.c

📁 6410BSP3
💻 C
📖 第 1 页 / 共 5 页
字号:
{
    DWORD i;
    SectorInfo si;  
    DWORD StartSector;

    // to keep bootpart off of our reserved blocks we must mark it as bad, reserved & read-only
    si.bOEMReserved = ~(OEM_BLOCK_RESERVED | OEM_BLOCK_READONLY);
    si.bBadBlock    = BADBLOCKMARK;
    //                si.bBadBlock    = 0xff;
    si.dwReserved1  = 0xffffffff;
    si.wReserved2   = 0xffff;

    EdbgOutputDebugString("Reserving Blocks [0x%x - 0x%x] ... Wait for completion\r\n", 0, IMAGE_START_BLOCK-1);

#ifdef _IROMBOOT_
    StartSector = (IS_LB)? 64: 32;
#else
    StartSector = 0;
#endif  // !_IROMBOOT_

    for (i = StartSector; i < IMAGE_START_SECTOR; i++) {
        FMD_WriteSector(i, NULL, &si, 1);
    }
    EdbgOutputDebugString("Reserving is completed.\r\n");
}

static void EraseNANDBlockRegion(UINT32 StartBlock, UINT32 EndBlock, const char*RegionName)
{
    UINT32 i;
    EdbgOutputDebugString ("NAND Blocks Erasing for %s [0x%x - 0x%x] ... Wait for completion\r\n", RegionName, StartBlock, EndBlock-1);
    for (i = StartBlock; i < EndBlock; i++) {
        FMD_EraseBlock(i);
    }
    EdbgOutputDebugString ("Erasing is completed.\r\n");
}


static USHORT InputNumericalString(CHAR *szCount, UINT32 length)
{
    USHORT cwNumChars = 0;
    USHORT InChar = 0;
    
    while(!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
        {
            // If it's a number or a period, add it to the string.
            //
            if ((InChar >= '0' && InChar <= '9')) 
            {
                if (cwNumChars < length) 
                {
                    szCount[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up.
            //
            else if (InChar == 8) 
            {
                if (cwNumChars > 0) 
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }
 
    // If it's a carriage return with an empty string, don't change anything.
    //
    if (cwNumChars) 
    {
        szCount[cwNumChars] = '\0';
    }
    else
    {
        szCount[0] = '\0';
    }
    return cwNumChars;
}

INT32 SetBlockPage(void)
{
    CHAR szCount[16];
    USHORT cwNumChars = 0;
    USHORT InChar = 0;
    UINT32 block=0, page=0;

    EdbgOutputDebugString("\r\nPress only Enter-key to return to menu\r\n");
    EdbgOutputDebugString("Enter Block # : ");

    cwNumChars = InputNumericalString(szCount, 16);

    // If it's a carriage return with an empty string, don't change anything.
    //
    if (cwNumChars) 
    {
        block = atoi(szCount);
    }
    else
    {
        return -1;
    }
 
    EdbgOutputDebugString("\r\nEnter Page # : ");

    memset(szCount, 0, sizeof(szCount));
    cwNumChars = InputNumericalString(szCount, 16);

    // If it's a carriage return with an empty string, don't change anything.
    //
    if (cwNumChars) 
    {
        page = atoi(szCount);
    }
    else
    {
        return -1;
    }
  
    if (IS_LB) return ((block<<6)|page);
    else       return ((block<<5)|page);
}
 
void PrintPageData(DWORD nMData, DWORD nSData, UINT8* pMBuf, UINT8* pSBuf)
{
    DWORD i;
 
    EdbgOutputDebugString ("=========================================================");
    for (i=0;i<nMData;i++)
    {
        if ((i%16)==0)
        {
            OALMSG(TRUE,(TEXT("\r\n 0x%03x |"), i));
        }
        OALMSG(TRUE, (TEXT(" %02x"), pMBuf[i]));
        if ((i%512)==511)
        {
            EdbgOutputDebugString ("\r\n ------------------------------------------------------- ");
        }
    }
    for (i=0;i<nSData;i++)
    {
        if ((i%16)==0)
            OALMSG(TRUE, (TEXT("\r\n 0x%03x |"), i));
        OALMSG(TRUE, (TEXT(" %02x"), pSBuf[i]));
    }
    EdbgOutputDebugString ("\r\n=========================================================");
}

char* BootDeviceString[NUM_BOOT_DEVICES] =
{
    "Ethernet", "USB_Serial", "USB_RNDIS", "*USB_DNW"
};

/* 
    @func   BOOL | PrintMainMenu | Print out the Samsung bootloader main menu.
    @rdesc  void return
    @comm
    @xref
*/
static void PrintMainMenu(PBOOT_CFG pBootCfg)
{
    int i=0;
    EdbgOutputDebugString ( "\r\nEthernet Boot Loader Configuration:\r\n\r\n");
    EdbgOutputDebugString ( "----------- Connectivity Settings ------------\r\n");
    EdbgOutputDebugString ( "0) IP address  : [%s]\r\n",inet_ntoa(pBootCfg->EdbgAddr.dwIP));
    EdbgOutputDebugString ( "1) Subnet mask : [%s]\r\n", inet_ntoa(pBootCfg->SubnetMask));
    EdbgOutputDebugString ( "2) DHCP : [%s]\r\n", (pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP)?"*Enabled":"Disabled");
    EdbgOutputDebugString ( "3) Program CS8900 MAC address : [%B:%B:%B:%B:%B:%B]\r\n",
                           pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, pBootCfg->EdbgAddr.wMAC[0] >> 8,
                           pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, pBootCfg->EdbgAddr.wMAC[1] >> 8,
                           pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, pBootCfg->EdbgAddr.wMAC[2] >> 8);

    EdbgOutputDebugString ( "--------- Boot Configuration Section ---------\r\n");
    EdbgOutputDebugString ( "4) Reset to factory default configuration\r\n");    
    EdbgOutputDebugString ( "5) Startup Action after Boot delay : [%s]\r\n", (pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT) ? "Launch Existing OS image from Storage" : "*Download New image");
    EdbgOutputDebugString ( "6) Boot delay: %d seconds\r\n", pBootCfg->BootDelay);    
    EdbgOutputDebugString ( "R) Read Configuration(TOC) \r\n");
    EdbgOutputDebugString ( "W) Write Configuration Data(TOC) Right Now\r\n");

    EdbgOutputDebugString ( "------- Kernel Booting Option Section --------\r\n");
    EdbgOutputDebugString ( "K) KITL Configuration           : [%s]\r\n", (pBootCfg->ConfigFlags & CONFIG_FLAGS_KITL) ? "*Enabled" : "Disabled");    
    EdbgOutputDebugString ( "I) KITL Connection Mode         : [%s]\r\n", (pBootCfg->ConfigFlags & CONFIG_FLAGS_KITLPOLL) ? "Polling" : "*Interrupt");
    EdbgOutputDebugString ( "C) Force Clean Boot Option      : [%s]\r\n", (pBootCfg->ConfigFlags & BOOT_OPTION_CLEAN)?"*True":"False");
    EdbgOutputDebugString ( "H) Hive Clean on Boot-time      : [%s]\r\n",  (pBootCfg->ConfigFlags & BOOT_OPTION_HIVECLEAN)?"True":"*False");
    EdbgOutputDebugString ( "P) Format Partition on Boot-time: [%s]\r\n",  (pBootCfg->ConfigFlags & BOOT_OPTION_FORMATPARTITION)?"True":"*False");

    EdbgOutputDebugString ( "------------- NAND Flash Section -------------\r\n");
    // N.B: we need this option here since BinFS is really a RAM image, where you "format" the media
    // with an MBR. There is no way to parse the image to say it's ment to be BinFS enabled.
    EdbgOutputDebugString ( "A) Erase All Blocks \r\n");
    EdbgOutputDebugString ( "E) Erase Reserved Block(Stepldr+Eboot) \r\n");    
    EdbgOutputDebugString ( "F) Format Boot Media for BINFS with BadBlock Marking to Reserved Block\r\n");
    EdbgOutputDebugString ( "N) Nand Information and Dump NAND Flash\r\n");

    EdbgOutputDebugString ( "--------- Download and Launch Section --------\r\n");
    // This selection option can configure Download connectivity and KITL connectivity
    EdbgOutputDebugString ( "S) Switch Boot Device : [%s]  \r\n", BootDeviceString[pBootCfg->BootDevice]);
    EdbgOutputDebugString ( "        { Options :");
    for (i=0; i<NUM_BOOT_DEVICES; i++)
    {
        EdbgOutputDebugString ( " %s,", BootDeviceString[i]);
    }
    EdbgOutputDebugString ( "\b }\r\n");
    // We did not check TARGET_TYPE_RAMIMAGE
    EdbgOutputDebugString ( "T) Download Target: [%s]\r\n", (pBootCfg->ConfigFlags & TARGET_TYPE_NAND) ? "Write to NAND Storage" : "*Download to RAM");
    EdbgOutputDebugString ( "D) Download or Program image(OS image will be launched)\r\n");
    EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n");

    EdbgOutputDebugString ( "\r\nEnter your selection: ");
}

/*
    @func   BOOL | ConfirmProcess | Check if continue or not
    @rdesc  TRUE == Success and FALSE == Failure.
    @comm
    @xref
*/
static BOOL ConfirmProcess(const char *msg)
{
    BYTE KeySelect = 0;

    EdbgOutputDebugString ( msg);            
    while (! ( ( (KeySelect == 'Y') || (KeySelect == 'y') ) ||
               ( (KeySelect == 'N') || (KeySelect == 'n') ) ))
    {
        KeySelect = OEMReadDebugByte();
    }
    
    if(KeySelect == 'Y' || KeySelect == 'y')
    {
        return TRUE;
    }
    return FALSE;
}
/*
    @func   BOOL | MainMenu | Manages the Samsung bootloader main menu.
    @rdesc  TRUE == Success and FALSE == Failure.
    @comm
    @xref
*/
static BOOL MainMenu(PBOOT_CFG pBootCfg)
{
    BYTE KeySelect = 0;
    BOOL bConfigChanged = FALSE;
    BOOLEAN bDownload = TRUE;

    if (pBootCfg->BootDevice > NUM_BOOT_DEVICES)
    {
        pBootCfg->BootDevice = g_DefaultBootDevice;
    }

    while(TRUE)
    {
        PrintMainMenu(pBootCfg);    
        
        KeySelect = 0;
        while (! ( ( (KeySelect >= '0') && (KeySelect <= '6') ) ||
                   ( (KeySelect == 'A') || (KeySelect == 'a') ) ||
                   ( (KeySelect == 'C') || (KeySelect == 'c') ) ||
                   ( (KeySelect == 'D') || (KeySelect == 'd') ) ||
                   ( (KeySelect == 'E') || (KeySelect == 'e') ) ||
                   ( (KeySelect == 'F') || (KeySelect == 'f') ) ||
                   ( (KeySelect == 'H') || (KeySelect == 'h') ) ||
                   ( (KeySelect == 'K') || (KeySelect == 'k') ) ||
                   ( (KeySelect == 'I') || (KeySelect == 'i') ) ||
                   ( (KeySelect == 'L') || (KeySelect == 'l') ) ||
                   ( (KeySelect == 'N') || (KeySelect == 'n') ) ||
                   ( (KeySelect == 'P') || (KeySelect == 'p') ) ||
                   ( (KeySelect == 'R') || (KeySelect == 'r') ) ||
                   ( (KeySelect == 'S') || (KeySelect == 's') ) ||
                   ( (KeySelect == 'T') || (KeySelect == 't') ) ||                   
                   ( (KeySelect == 'W') || (KeySelect == 'w') ) ))
        {
            KeySelect = OEMReadDebugByte();
        }

        EdbgOutputDebugString ( "%c\r\n", KeySelect);

        switch(KeySelect)
        {
        case '0':           // Change IP address.
            SetIP(pBootCfg);
            pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP;   // clear DHCP flag
            bConfigChanged = TRUE;
            break;
        case '1':           // Change subnet mask.
            SetMask(pBootCfg);
            bConfigChanged = TRUE;
            break;
        case '2':           // Toggle static/DHCP mode.
            pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DHCP);
            bConfigChanged = TRUE;
            break;
        case '3':           // Configure Crystal CS8900 MAC address.
            SetCS8900MACAddress(pBootCfg);
            bConfigChanged = TRUE;
            break;
        case '4':           // Reset the bootloader configuration to defaults.
            EdbgOutputDebugString("Resetting default TOC...Wait to complete\r\n");
            TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
            if ( !TOC_Write() ) {
                OALMSG(OAL_ERROR, (TEXT("TOC_Write Failed!\r\n")));
            }
            EdbgOutputDebugString("...TOC complete\r\n");
            break;
        case '5':           // Toggle download/launch status.
            pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ BOOT_TYPE_DIRECT);
            bConfigChanged = TRUE;
            break;
        case '6':           // Change autoboot delay.
            SetDelay(pBootCfg);
            bConfigChanged = TRUE;
            break;
        case 'A':
        case 'a':
            if(ConfirmProcess("CAUTION! This will erase all DATA(Bootloader and OS) in storage!\n" \
                              "Do you really want to erase all? (Yes or No)\r\n"))
            {
                EraseNANDBlockRegion(0, wNUM_BLOCKS, "All Block");
            }
            break;
        case 'C':    // Toggle image storage to Smart Media.
        case 'c':
            pBootCfg->ConfigFlags= (pBootCfg->ConfigFlags ^ BOOT_OPTION_CLEAN);
            bConfigChanged = TRUE;
            break;
        case 'D':           // Download? Yes.
        case 'd':
            bDownload = TRUE;
            goto MENU_DONE;
        case 'E':
        case 'e':
            if(ConfirmProcess("CAUTION! This will erase all BOOTLOADER Data(StepLoader and EBOOT) in storage!\n" \
                              "Do you really want to erase all? (Yes or No)\r\n"))
            {
            
                // This will erase reserved block for steploader and eboot
                if ( !g_bBootMediaExist ) {
                    OALMSG(OAL_ERROR, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
                    continue;
                } else {
                    EraseNANDBlockRegion(NBOOT_BLOCK, NBOOT_BLOCK+NBOOT_BLOCK_SIZE, "StepLoader");
                    EraseNANDBlockRegion(EBOOT_BLOCK, EBOOT_BLOCK+EBOOT_BLOCK_SIZE, "EBOOT");
                }
            }
            break;
        case 'F':
        case 'f':
            if(ConfirmProcess("CAUTION! This will erase all OS IMAGE in storage!\n" \
                              "Do you really want to erase all? (Yes or No)\r\n"))
            {
    /*            
                // low-level format NAND Erasing            
                // format the boot media for BinFS
                // N.B: this does not destroy our OEM reserved sections (TOC, bootloaders, etc)
                if ( !g_bBootMediaExist ) {
                    OALMSG(OAL_ERROR, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
                    break;
                }
                
                EraseNANDBlockRegion(IMAGE_START_BLOCK, wNUM_BLOCKS, "OS System");
    */
                MarkReservedBlockWithBadBlock();
                // N.B: this erases images, BinFs, FATFS, user data, etc.
                // N.B: format offset by # of reserved blocks,
                // decrease the ttl # blocks available by that amount.
                if ( !BP_LowLevelFormat( IMAGE_START_BLOCK,
                                         wNUM_BLOCKS - IMAGE_START_BLOCK,
                                         FORMAT_SKIP_BLOCK_CHECK) )
                {
                    OALMSG(OAL_ERROR, (TEXT("ERROR: BootMonitor: Low-level boot media format failed.\r\n")));

⌨️ 快捷键说明

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