OEM flash functions in wince eboot

Source: Internet
Author: User

OEM flash functions in wince eboot

Address: http://blog.csdn.net/nanjianhui/archive/2008/11/12/3283072.aspx

Author: arm-WinCE

The Flash operating function is provided in eboot to burn the downloaded wince image to flash, which requires some flash-related OEM functions.

These OEM functions are called in the blcommon module, that is, in the downloadimage function of the blcommon. c file. In the downloadimage function, the header of an image file is generally downloaded and parsed first. Then, call oemisflashaddr to determine the region where the image is located. If the image is in the flash Address Space, download the image file and call the flash-related OEM function to erase and write the flash. The following describes these functions:

1. bool oemisflashaddr (DWORD dwaddr)

This function is used to determine whether the downloaded wince image file is in the Flash area or in the ram area. dwaddr is the address of the image file. If true is returned in the Flash area, false is returned, here is an example of Microsoft:

# Define flash_start 0

# Define flash_length 0x02000000

Bool oemisflashaddr (DWORD dwaddr)

{

// Determine whether the address is in the Flash area based on the start address and length of the flash.

If (dwaddr> = flash_start) & (dwaddr <(flash_start + flash_length )))

{

Return (true );

}

Return (false );

}

2. bool oemstarteraseflash (DWORD dwstartaddr, DWORD dwlength)

This function is used to initialize the flash erasure. dwstartaddr indicates the start address to be erased, and dwlength indicates the length. Use these two parameters to calculate the starting block and last block to be erased in flash, and the number of blocks to be erased. Here is an example for Microsoft:

Bool oemstarteraseflash (DWORD dwstartaddr, DWORD dwlength)

{

Ulong I = 0;

Ulong nnumblocks = 0;

// Determine whether the start address and end address are in the Flash Area

If (! Oemisflashaddr (dwstartaddr) |! Oemisflashaddr (dwstartaddr + dwlength-1 ))

{

Return (false );

}

// Confirm that the starting address is block aligned

If (dwstartaddr % flash_block_size)

{

Return (false );

}

// Confirm that the length is 4 bytes aligned

If (dwlength & 0x03)

{

Return (false );

}

// Calculate the starting block to be erased and the last block to be erased Based on the flash base address and flash block size

// Block and number of blocks

Gnstartblock = (dwstartaddr-flash_base)/flash_block_size;

Gnendblock = (dwstartaddr + dwlength + (flash_block_size-1)-flash_base)/flash_block_size );

Gnblocks = (INT) (gnendblock-gnstartblock );

Gnblockcount = gnstartblock;

Edbgoutputdebugstring ("erasing flash blocks: Start block = % d end block = % d \ r \ n", gnstartblock, gnendblock );

Return (true );

}

3. Void oemcontinueeraseflash (void)

This function is used to erase the flash area. It will be called after the image is downloaded to erase the block in flash. Here is an example for Microsoft:

Void oemcontinueeraseflash (void)

{

Uchar nerasecount = block_erase_step; // block to be erased

// Confirm that all blocks to be erased are erased

If (! Gnblocks | (gnblockcount = gnendblock ))

Return;

// Erase the block

While (gnblockcount <gnendblock) & nerasecount)

{

If (cfi_erase_block (unsigned32 *) block_addr (gnblockcount), 0, null )! = Pass)

{

Edbgoutputdebugstring ("error: oemcontinueeraseflash-flash erase error (block number % d). \ r \ n", gnblockcount );

Return;

}

++ Gnblockcount;

-- Nerasecount;

}

Return;

}

4. bool oemfinisheraseflash (void)

This function is used to confirm that all blocks in Flash are erased. Here is an example for Microsoft:

Bool oemfinisheraseflash (void)

{

Edbgoutputdebugstring ("info: Finishing flash erase... \ r \ n ");

While (gnblocks & (gnblockcount! = Gnendblock ))

{

Oemcontinueeraseflash ();

}

Return (true );

}

5. bool oemwriteflash (DWORD dwimagestart, DWORD dwimagelength)

This function is used to write the downloaded image to flash. dwimagestart is the starting address of the image written into flash, and dwimagelength is the size of the image. Here is an example for Microsoft:

Bool oemwriteflash (DWORD dwimagestart, DWORD dwimagelength)

{

DWORD dwflashaddr, dwextrabytes = 0;

Lpbyte pbcache = NULL;

Uchar nnumblocks = 0;

// Confirm that the start address and length are within the flash area.

If (! Oemisflashaddr (dwimagestart) |! Oemisflashaddr (dwimagestart + dwimagelength-1 ))

{

Return (false );

}

// Confirm that the starting address is block byte aligned

If (dwimagestart % flash_block_size)

{

Return (false );

}

// Calculate the number of blocks to be written.

Nnumblocks = (uchar) (dwimagelength/flash_block_size );

Dwextrabytes = (dwimagelength % flash_block_size );

Dwflashaddr = dwimagestart;

Pbcache = oemmapmemaddr (dwimagestart, dwflashaddr );

// Write flash

While (nnumblocks)

{

If (cfi_write_block (unsigned32 *) dwflashaddr, (unsigned32 *) pbcache, flash_block_size, null )! = Pass)

{

Edbgoutputdebugstring ("error: oemwriteflash-unable to write to block (block address = 0x % x). \ r \ n", dwflashaddr );

Return (false );

}

Dwflashaddr + = flash_block_size;

Pbcache = oemmapmemaddr (dwimagestart, dwflashaddr );

-- Nnumblocks;

}

// Write additional data into flash

If (dwextrabytes)

{

If (cfi_write_block (unsigned32 *) dwflashaddr, (unsigned32 *) pbcache, dwextrabytes, null )! = Pass)

{

Edbgoutputdebugstring ("error: oemwriteflash-unable to write to block (block address = 0x % x). \ r \ n", dwflashaddr );

Return (false );

}

}

Return (true );

}

The preceding five functions are used to support flash operations in eboot. Generally, when developing BSP, if you need to implement the flash function in eboot, a flash. c file will be created in eboot, and the above functions will be implemented in this file. We recommend that you look at the downloadimage function in blcommon. C to help you understand it.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/joyzml/archive/2010/04/20/5508612.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.