Hi!

On Sun, 11 May 2008, jiwen zhang wrote:

> Hello Razvan ME:
>
> 2008/5/9 Razvan Musaloiu-E. <[EMAIL PROTECTED]>:
>
>> Hi!
>>
>> On Wed, 7 May 2008, jiwen zhang wrote:
>>
>> Hello all :
>>>  when i read the file TOSBootM.nc , there are some things i can' t
>>> understand !
>>>
>>>  1. The external flash is divided into three slots , *i want to know the 
>>> size of every slot ? are they identical ?*
>>>  from reading the TOSBootM , i think the *structure of every slot *is that:
>>>
>>> for example , slot 0 :
>>>                ----------------------------------------------------
>>>                         DELUGE_IDENT_SIZE (128 Bytes)
>>>                ----------------------------------------------------
>>>
>>>                     DELUGE_CRC_BLOCK_SIZE(256 Bytes)
>>>
>>>                -----------------------------------------------------
>>>                                  PAGE 0
>>>                                  PAGE 1
>>>                                  ...........
>>>                                  ...........
>>>
>>>
>>> and *PAGE structure* is that :
>>>
>>>                 ---------------------------------------------
>>>                       Internal flash Address  (4 Bytes)
>>>                 ---------------------------------------------
>>>                              Page length(4 Byte)
>>>                 --------------------------------------------
>>>                          Effective Image data()
>>>                  -------------------------------------------
>>> Am i right ?  i am not sure the page structure , if i am not right , can
>>> someone give me an explain ?
>>>
>>
>> You are almost right: what you call pages are called sections.
>>
>>
>> 2. Question about the function of  programImage(ex_flash_addr_t startAddr)
>>>
>>>     .....
>>>     .....
>>>
>>>
>>>   while ( secLength ) {
>>>
>>>     pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
>>>
>>>     call ExtFlash.startRead(curAddr);
>>>     // fill in ram buffer for internal program flash sector
>>>     do {
>>>
>>> // check if secLength is all ones
>>> if ( secLength == 0xffffffff ) {
>>>  call ExtFlash.stopRead();
>>>  return FAIL;
>>> }
>>>
>>> buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte();
>>> intAddr++; curAddr++;
>>>
>>> if ( --secLength == 0 ) {
>>>  intAddr = extFlashReadAddr();
>>>  secLength = extFlashReadAddr();
>>>  curAddr = curAddr + 8;
>>> }
>>>
>>> newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
>>>
>>>     } while ( pageAddr == newPageAddr && secLength );
>>>     call ExtFlash.stopRead();
>>>
>>>     call Leds.set(pageAddr);
>>>
>>>     // write out page
>>>     if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf,
>>>         TOSBOOT_INT_PAGE_SIZE) == FAIL) {
>>> return R_PROGRAMMING_ERROR;
>>>     }
>>>   }
>>>
>>> i don't know *how the programme jump out the while cycle*.  because the
>>> condition of jumping out the while cycle is that "secLength <= 0" , but in
>>> the while  , there is some sentences :
>>>
>>>    if ( --secLength == 0 ) {
>>>  intAddr = extFlashReadAddr();
>>>  secLength = extFlashReadAddr();
>>>  curAddr = curAddr + 8;
>>> }
>>>
>>> *so when secLength == 0 , it will be given a new value (which is the next
>>> page size ?) , how does it jump out ?*
>>>
>>> *is it possible that it jump out from here ? :*
>>>
>>> if ( secLength == 0xffffffff ) {
>>>  call ExtFlash.stopRead();
>>>  return FAIL;
>>> }
>>>
>>> i am not sure, can someone give me an explain ?
>>>
>>
>> The secLength will be zero because the image is padded with zeros. If the
>> image is an exact number of pages the reprogramming might fail. I'll try to
>> reproduce this bug tomorrow.
>> is it to say that when reading to the end of the image , the secLength of
>> the page is setted to zero , so the programme can jump out ?
>
> what is the meaning of "If the image is an exact number of pages the
> reprogramming might fail" ? and what is the bug you say in your emial ? i
> can't find the bug :-)

In order to generate the bug you need to craft an image which doesn't need 
any padding. These happens in lines 177-179 in tos-build-deluge-image:

    171  all_data = []
    172  for (addr, data) in all:
    173    all_data += encode(addr, 4) + \
    174                encode(len(data), 4) + \
    175                data
    176  all_data += encode(0, 4) + encode(0, 4) # Add the marker for the end 
of an image
    177  padding = [0] * (DELUGE_BYTES_PER_PAGE - len(all_data) % 
DELUGE_BYTES_PER_PAGE)
    178  if len(padding) < DELUGE_BYTES_PER_PAGE:
    179    all_data += padding
    180  all_data = deluge_crc(all_data)
    181  ident['size'] = DELUGE_IDENT_SIZE + len(all_data)
    182  sys.stdout.write(int2byte(deluge_ident(all_data)) + int2byte(all_data))

I did exactly that and, as expected, the programImage failed. The exit 
from that loop was on the secLength == 0xffffffff condition. In just 
committed a fix for this case in deluge branch from here:
        git://hinrg.cs.jhu.edu/git/deluge/tinyos-2.x.git
        http://hinrg.cs.jhu.edu/git/?p=deluge/tinyos-2.x.git  (gitweb)

Thanks for finding this bug! :-)
Razvan ME

>> 2008/5/7, jiwen zhang <[EMAIL PROTECTED]>:
>>>
>>>>
>>>> Hello :
>>>>   thank you very much for your reply, Razvan ME.
>>>>   i have found it .
>>>>
>>>>
>>>>
>>>>
>>>> 2008/5/7, Razvan Musaloiu-E. <[EMAIL PROTECTED]>:
>>>>
>>>>>
>>>>> Hi!
>>>>>
>>>>> On Tue, 6 May 2008, jiwen zhang wrote:
>>>>>
>>>>> Hello all :
>>>>>
>>>>>>  Recently , i an researching the deluge, and find a problem in TOSBootM.
>>>>>>  In the function programImage(ex_flash_addr_t startAddr) , there is a 
>>>>>> sentence
>>>>>>  #if defined(PLATFORM_TELOSB)
>>>>>>  if (intAddr != TOSBOOT_END) {
>>>>>> #elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS)
>>>>>>  if (intAddr != 0) {
>>>>>>     ....
>>>>>>     ....
>>>>>>
>>>>>>  I can't find where TOSBOOT_END is defined . if i am using the platform 
>>>>>> telosb , maybe it does't work .
>>>>>>  can someone give me an answer ?
>>>>>>
>>>>>>
>>>>> TOSBOOT_END is defined in tinyos-2.x/tos/lib/tosboot/Makefile.
>>>>>
>>>>> --
>>>>> Razvan ME
>>>>>
>>>>>  I am using Tinyos2.x .
>>>>>
>>>>>>  thank you !!
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to