BOOL
WriteFlashLogo(
    UINT32 address,
    UINT32 size
    )
{
    BOOL rc = FALSE;
    HANDLE hFlash = NULL;
    UINT8 *pData;
    UINT32 offset;

    OALMSG(OAL_INFO, (L"\r\nWriting Splashcreen image to flash memory\r\n"));

    // Open flash storage
    hFlash = OALFlashStoreOpen(g_ulFlashBase);
    if (hFlash == NULL)
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"OALFlashStoreOpen call failed!\r\n"
            ));
        goto cleanUp;
        }

    // Check if image fit (last sector used for configuration)
    if (size > (IMAGE_BOOTLOADER_BITMAP_SIZE - OALFlashStoreSectorSize(hFlash)))
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"Logo image too big (size 0x%08x, maximum size 0x%08x)\r\n",
            size, IMAGE_BOOTLOADER_BITMAP_SIZE - OALFlashStoreBlockSize(hFlash)
            ));
        goto cleanUp;
        }

    // Get data location
    pData = OEMMapMemAddr(address, address);

    // Fill unused space with 0xFF
    if (size < IMAGE_BOOTLOADER_BITMAP_SIZE)
        {
        memset(pData + size, 0xFF, IMAGE_BOOTLOADER_BITMAP_SIZE - size);
        }

    offset = IMAGE_XLDR_BOOTSEC_NAND_SIZE + IMAGE_EBOOT_BOOTSEC_NAND_SIZE;
    if (!OALFlashStoreWrite(
            hFlash, offset, pData, IMAGE_BOOTLOADER_BITMAP_SIZE, FALSE, FALSE
            ))
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"OALFlashStoreWrite at relative address 0x%08x failed\r\n", offset
            ));
        goto cleanUp;
        }

    OALMSG(OAL_INFO, (L"Splashcreen image written\r\n"));

    // Done
    rc = TRUE;

cleanUp:
    if (hFlash != NULL) OALFlashStoreClose(hFlash);
    return rc;
}
Example #2
0
//------------------------------------------------------------------------------
//
//  Function:  ShowLogo
//
//  This function shows the logo splash screen
//
VOID ShowLogo(UINT32 flashAddr, UINT32 offset)
{
    HANDLE  hFlash = NULL;
    DWORD  framebuffer;
    DWORD  framebufferPA;
    PUCHAR  pChar;
    ULONG   x, y;
    WORD    wSignature = 0;
    DWORD   dwOffset = 0;
    DWORD   dwLcdWidth,
            dwLcdHeight;
    DWORD   dwLength;


    //  Get the LCD width and height
    LcdPdd_LCD_GetMode( NULL, &dwLcdWidth, &dwLcdHeight, NULL );

    dwLength = BYTES_PER_PIXEL * LOGO_WIDTH * LOGO_HEIGHT;

    //  Get the video memory
    LcdPdd_GetMemory( NULL, &framebufferPA );
    framebuffer = (DWORD) OALPAtoUA(framebufferPA);
    pChar = (PUCHAR)framebuffer;
    
    if (flashAddr != -1)
    {
        // Open flash storage
        hFlash = OALFlashStoreOpen(flashAddr);
        if( hFlash != NULL )
        {
            //  The LOGO reserved NAND flash region contains the BMP file
            OALFlashStoreBufferedRead( hFlash, offset, (UCHAR*) &wSignature, sizeof(wSignature), FALSE );

            //  Check for 'BM' signature
            if( wSignature == 0x4D42 )  
            {
                //  Read the offset to the pixel data
                OALFlashStoreBufferedRead( hFlash, offset + 10, (UCHAR*) &dwOffset, sizeof(dwOffset), FALSE );

                //  Read the pixel data with the given offset
                OALFlashStoreBufferedRead( hFlash, offset + dwOffset, pChar, dwLength, FALSE );
            }
           
            //  Close store
            OALFlashStoreClose(hFlash);
        
            //  Compute position and size of logo image 
            g_dwLogoPosX   = (dwLcdWidth - LOGO_WIDTH)/2;
            g_dwLogoPosY   = (dwLcdHeight - LOGO_HEIGHT)/2;
            g_dwLogoWidth  = LOGO_WIDTH;
            g_dwLogoHeight = LOGO_HEIGHT;
            
            //As BMP are stored upside down, we need to flip the frame buffer's content
            FlipFrameBuffer((PUCHAR)framebuffer,LOGO_HEIGHT,LOGO_WIDTH*BYTES_PER_PIXEL,(PUCHAR)framebuffer + dwLength);
        }
    }

    //  If bitmap signature is valid, display the logo, otherwise fill screen with pattern
    if( wSignature != 0x4D42 )
    {
        //  Adjust color bars to LCD size
        g_dwLogoPosX   = 0;
        g_dwLogoPosY   = 0;
        g_dwLogoWidth  = dwLcdWidth;
        g_dwLogoHeight = dwLcdHeight;
        
        for (y= 0; y < dwLcdHeight; y++)
        {
            for( x = 0; x < dwLcdWidth; x++ )
            {
                if( y < dwLcdHeight/2 )
                {
                    if( x < dwLcdWidth/2 )
                    {
                        *pChar++ = 0xFF;    //  Blue
                        *pChar++ = 0x00;    //  Green
                        *pChar++ = 0x00;    //  Red
                    }
                    else
                    {
                        *pChar++ = 0xFF;    //  Blue
                        *pChar++ = 0x00;    //  Green
                        *pChar++ = 0x00;    //  Red
                    }
                }
                else
                {
                    if( x < dwLcdWidth/2 )
                    {
                        *pChar++ = 0xFF;    //  Blue
                        *pChar++ = 0x00;    //  Green
                        *pChar++ = 0x00;    //  Red
                    }
                    else
                    {
                        *pChar++ = 0xFF;    //  Blue
                        *pChar++ = 0x00;    //  Green
                        *pChar++ = 0x00;    //  Red
                    }
                }
            }
        }
    }

    //  Fire up the LCD
    lcd_config(framebufferPA);       
}
BOOL
WriteFlashXLDR(
    UINT32 address,
    UINT32 size
    )
{
    BOOL rc = FALSE;
    HANDLE hFlash = NULL;
    ROMHDR *pTOC;
    UINT32 offset, xldrSize, blocknum, blocksize;
    UINT8 *pData;

	UNREFERENCED_PARAMETER(size);

    OALMSG(OAL_INFO, (L"\r\nWriting XLDR image to flash memory\r\n"));

    // Open flash storage
    hFlash = OALFlashStoreOpen(g_ulFlashBase);
    if (hFlash == NULL)
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"OALFlashStoreOpen call failed!\r\n"
            ));
        goto cleanUp;
        }

    // Get data location
    pData = OEMMapMemAddr(address, address);

    // Verify image
    if (!VerifyImage(pData, &pTOC))
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"XLDR image signature not found\r\n"
            ));
        }

    // Verify that this is XLDR image
    if (pTOC->numfiles > 0 || pTOC->nummods > 1)
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"XLDR image must have only one module and no file\r\n"
            ));
        goto cleanUp;
        }

    // Check for maximal XLRD size
    xldrSize = pTOC->physlast - pTOC->physfirst;
    if (xldrSize > (IMAGE_XLDR_CODE_SIZE - 2*sizeof(DWORD)) )
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"XLDR image size 0x%04x doesn't fit to limit 0x%04x\r\n", size, IMAGE_XLDR_CODE_SIZE - 2*sizeof(DWORD)
            ));
        goto cleanUp;
        }
        
    blocksize = OALFlashStoreBlockSize(hFlash);
    
    if (blocksize < IMAGE_XLDR_CODE_SIZE)
        {
        OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
            L"XLDR image size 0x%04x doesn't fit to flash block size 0x%04x\r\n", IMAGE_XLDR_CODE_SIZE, blocksize
            ));
        goto cleanUp;
        }

    // First we have to offset image by 2 DWORDS to insert BootROM header 
    memmove(pData + 2*sizeof(DWORD), pData, xldrSize);
    
    // Insert BootROM header
    ((DWORD*)pData)[0] = IMAGE_XLDR_CODE_SIZE - 2*sizeof(DWORD);    // Max size of image
    ((DWORD*)pData)[1] = IMAGE_XLDR_CODE_PA;                        // Load address

    // Now copy into first four blocks per boot ROM requirement.
    // Internal boot ROM expects the loader to be duplicated in the first 4 blocks for
    // data redundancy. Note that block size of memory used on this platform is larger 
    // than xldr size so there will be a gap in each block.
    offset = 0;
    for (blocknum = 0; blocknum < 4; blocknum++)
        {
        if (!OALFlashStoreWrite(
                hFlash, offset, pData, IMAGE_XLDR_CODE_SIZE, FALSE, FALSE
                ))
            {
            OALMSG(OAL_ERROR, (L"ERROR: OEMWriteFlash: "
                L"OALFlashStoreWrite at relative address 0x%08x failed\r\n",
                offset
                ));
            }
        offset += blocksize;
        }

    OALMSG(OAL_INFO, (L"XLDR image written\r\n"));

    // Done
    rc = TRUE;

cleanUp:
    if (hFlash != NULL) OALFlashStoreClose(hFlash);
    return rc;
}