none
how to flash nk.bin file provided by the WinCE application?

    Question

  • Hi all,

    I am trying to upgrade kernel from application. My application passes kernel image to the driver through IOCTL. I succeded in flashing nk.nb0 files. How to handle nk.bin files? Is there any way to convert nk.bin which is placed in a buffer to nk.nb0?

    My Application:

    ************

    handle = CreateFile( L"DSK1:",GENERIC_READ|GENERIC_WRITE,
     FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0 );


    DeviceIoControl( handle, IOCTL_FMD_WRITE_RESERVED, kernImagePtr,kernImageLen, NULL, 0, NULL,NULL );

     

    FMD.cpp

    *******

    BOOL FMD_OEMIoControl(DWORD dwIoControlCode, PBYTE pInBuf, DWORD nInBufSize,
           PBYTE pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned)
    {

    case IOCTL_FMD_WRITE_RESERVED:
     NANDWrtImgInfo.dwImgType = IMAGE_NK;
     NANDWriteImage(&NANDWrtImgInfo,pInBuf,nInBufSize);

    }

    Regards,


    kiran reddy
    Wednesday, October 12, 2011 5:59 AM

All replies

  • Hi,

    you could use "cvrtbin" tool to create nk.nb0 from nk.bin. The source code of the tool code is available with the platform builder. See path C:\WINCE600\PRIVATE\WINCEOS\COREOS\NK\TOOLS\ROMIMAGE\CVRTBIN\.

    So you possible could use the cvrtbin sources for your update mechanism.

    Best regards,

    Andreas 

    • Proposed as answer by Andreas_1981 Friday, October 14, 2011 6:45 AM
    Wednesday, October 12, 2011 6:08 AM
  • According to your post you'd like to convert the nk.bin to nk.nb0 then flash the OS image.

    Looking the thing from another point of view: since .bin format is more compact than the raw .nb0 you can flash the .bin 'as it is' and add support to the bootloader to handle the .bin format. The bootloader support libraries already provide the functions to decode the .bin file contents.


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    • Proposed as answer by Andreas_1981 Friday, October 14, 2011 6:45 AM
    • Unproposed as answer by Andreas_1981 Friday, October 14, 2011 6:45 AM
    • Proposed as answer by Andreas_1981 Friday, October 14, 2011 6:45 AM
    Wednesday, October 12, 2011 7:10 AM
  • I suspect that what you really want to do is to expand the nk.bin using your driver.   There are examples of doing this, I will let you use your search tool to find them.   But, they are in bootloaders.   The reason they are in bootloaders is that the process requires large chunks of RAM, which if not available in your OS would mean that the device could not be updated.
    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    • Proposed as answer by Andreas_1981 Friday, October 14, 2011 6:45 AM
    Wednesday, October 12, 2011 12:18 PM
  • Yes Bruce. I am expanding nk.bin using driver.  I found examples of this at CVRTBIN code and \PUBLIC\COMMON\OAK\DRIVERS\ETHDBG\BLCOMMON\blcommon.c. I do need 10 MB for nk.bin and 10 MB more for expanded image. We have enough RAM. We have to support upgrade of images through ethernet. Device can be any where in the world. This requirment requires these changes.

    Thanks all. Now I am clear in this activity.         


    kiran reddy
    Thursday, October 13, 2011 4:16 AM
  • Thanks all. It worked.
    kiran reddy
    Friday, October 14, 2011 5:53 AM
  • Hi Kiran,

    I am new to WinCE and would like to do what you did.  Would you please share your changes with me and send them to lnluan@yahoo.com.

    I appreciate your help very much.

    Luan


    Luan Le
    Tuesday, November 29, 2011 5:42 PM
  • hi,

    Please find the code below. For decoding bin files look at CVRTBIN code provided by microsoft.

    1. Get Kerenel to be flashed from application and send to FMD driver

    DownloadDLL_API int DownloadKernel( UCHAR * imagePtr, DWORD imageLen, BOOL resetRegistry  )
    {

     HANDLE handle = NULL;
     UCHAR  *OutBuf = NULL;
     UINT   outBufLen = 0;
     BOOL   bResult = TRUE; 
     BYTE hdr[BL_HDRSIG_SIZE];
     IMAGEHDR  ImageHdr; 
     RECORDHDR RecordHdr;
     
     handle = CreateFile( L"DSK1:",GENERIC_READ|GENERIC_WRITE,
      FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0 );
     if(handle == INVALID_HANDLE_VALUE)
     {
      return 1;
     }
     memcpy(hdr,imagePtr,BL_HDRSIG_SIZE);
     if (!memcmp (hdr, "B000FF\x0A", BL_HDRSIG_SIZE))//.bin files
     {
      memcpy((BYTE*)&ImageHdr,imagePtr,sizeof(IMAGEHDR));
      //FMD Driver need extra memory multiples of 128K Bytes
      outBufLen = ImageHdr.ImageLen + 4*128*1024;
     }
     else
     {
      outBufLen = imageLen+128*4*1024;
     }
     OutBuf = ( UCHAR * ) VirtualAlloc( NULL, outBufLen, MEM_COMMIT, PAGE_READWRITE );
     if(OutBuf == NULL)
     {
      return 1;
     }
     if(handle && OutBuf)
     {
      if(resetRegistry)
      {
       bResult = DeviceIoControl( handle, IOCTL_FMD_SET_REGISTRY, NULL,0, NULL, 0, NULL,NULL );
      }
      if(bResult)
      {
       bResult = DeviceIoControl( handle, IOCTL_FMD_UPDATE_NK, imagePtr,imageLen, OutBuf, outBufLen, NULL,NULL );
      }
      Sleep(1000);
      VirtualFree(OutBuf,0,MEM_RELEASE);
     }
     if(handle)
     {
      CloseHandle(handle);
     }

     return 1;

    }

    2. Write to flash

    case IOCTL_FMD_UPDATE_NK:

      if(clockset == 0)
      {
       BSPNAND_SetClock(TRUE);
       clockset = 1;
      }
      
      NANDWrtImgInfo.dwImgType = IMAGE_NK;
      //Check Whether it is nk.bin or nk.nb0
      memcpy(hdr,pInBuf,BL_HDRSIG_SIZE);
      if (!memcmp (hdr, "B000FF\x0A", BL_HDRSIG_SIZE))//.bin files
      {
       //Malloc api not availble here. User application is creating buufer -
       //and placing pointer in pOutBuf
       unsigned char* pData = NULL;
       PBYTE pIn = pInBuf;
       memcpy((BYTE*)&ImageHdr,pInBuf,sizeof(IMAGEHDR));
       pData = (unsigned char *) pOutBuf; //
       
       //Decode .bin file and convert it to .nb0 format.
       //To connver .bin file to .nb0 lood at CVRTBIN code provided by microsoft.
       //PData is a pointer to the decoded data.   

       NANDWriteImage(&NANDWrtImgInfo,pData,ImageHdr.ImageLen);
      }
      else //nb0 files
      {
       NANDWriteImage(&NANDWrtImgInfo,pInBuf,nInBufSize);
      }

      break;
     


    kiran reddy
    Thursday, December 01, 2011 4:31 AM
  • Thanks very much Kiran.

    I have a few questions about the code.

    1. Is the function DownloadKernel() in the application or in another driver that you created to interface with FMD driver?

    2. Would you please tell me the location of the file fmd.cpp?  I see several one under \WinCe600\Public\...\Block\Msflashmd\*\ and not sure which one you modified.

    3. I could not find IOCTL_FMD_SET_REGISTRY and NANDWriteImage anywhere in my search.  Did you create these or they already exist?

    With appreciation,

    Luan


    Luan Le
    Thursday, December 01, 2011 5:41 PM
  • Hi,

    1. DowloadKernel is in the application. From application I am sending an IOCTL to the FMD Driver.

    2. I am using IMX51 bsp code provided by freescale. path of the fmd.cpp is

     C:\WINCE600\PLATFORM\COMMON\SRC\SOC\COMMON_FSL_V2_PDK1_7NAND\FMDCOMMON\OCQ_INTERLEAVE

    3. Don't worry about IOCTL_FMD_SET_REGISTRY. It is specific to my application.

    IOCTL_FMD_UPDATE_NK also custom IOCTL. You need to implement custom IOCTL like this for flashing in to nand.


    kiran reddy
    Friday, December 02, 2011 3:56 AM
  • Thanks very much Kiran.

    Is it possible that you post the content of the function NANDWriteImage()?


    Luan Le
    Tuesday, December 06, 2011 12:59 AM