Shop OBEX P1 Docs P2 Docs Learn Events
boot loader — Parallax Forums

boot loader

mctriviamctrivia Posts: 3,772
edited 2009-06-30 12:58 in Propeller 1
I really quickly threw together some code to act as a bootloader for a board with a 512k eeprom and sd card like my propmodules to allow for eeprom images to be installed from the sd card.

I need to write the pasm copy routine still to copy the top half of eeprom to hub ram but in the roughing out of the code I realized I am not sure how I can start the prop running the eeprom image after copying hence the

start prop???? line.


any ideas?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.

Post Edited (mctrivia) : 6/30/2009 8:25:33 AM GMT
«1

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-26 12:48
    First you have to start converting (or find a PASM replacement) of the Basic_I2C_Driver as this is completely written in SPIN.

    Second thing is ... maybe you shouldn't start at adress 32768 for reading the upper part of the EEPROM. Instead you have to select the right adress (instead of i2C#EEPROM). At least this is my experience with my 64kB FRAM. It has adress $A0 for lower part and $A2 for upper part. Ok ... maybe not a real issue for you because you write the same way - having a 512k EEPROM which uses all available EEPROM adresses. But if you want to run your code on different setups it might be a problem.

    For the starting of a new image, have a look at the Femto SD card driver. It provides exactly that functionality - load complete 32k image and run the SPIN interpreter. If you simply don't do a cogstop before, the drivers you loaded with the boot-loader can stay.

    I plan to do the same thing somewhen, so if I don't find a PASM I2C driver I'll propably write one ... only I can't say when.
  • KyeKye Posts: 2,200
    edited 2009-06-26 13:44
    I wrote one of those a while back, it was in an incomplete form however, but the code is there for I2C acess... just not anything else.

    Search for post by me mentioning I2C.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Chad GeorgeChad George Posts: 138
    edited 2009-06-26 16:47
    I pulled something from the archives...but I haven't dusted it off yet...

    Its a serial bootloader that I used on a robot project last year. I'm going to be reworking this in the next few weeks so I didn't take the time to make an entire working demo of the program, but maybe it'll have what you're looking for.

    The python script attached is capable of handling the PC side of things...the only non-standard library you'll need is PySerial.

    and the whole project needs a better name... [noparse]:)[/noparse]
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-27 08:21
    Well I have no hardware at the moment to test it but I have converted all the necisary spin to psam and it assembles. now to build more modules and see if it works.

    What I am really not sure if it will work is the reseting of the prop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.

    Post Edited (mctrivia) : 6/30/2009 8:26:06 AM GMT
  • AribaAriba Posts: 2,690
    edited 2009-06-27 11:01
    mctriva

    To reboot the propeller from Assembly, write a new clkreg setting with bit7 set:
            ...
            'restart the prop
            CLKSET startre
    
            'no need to stop any cog here        
            ...
    startre LONG  $80
    
    



    Andy
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 11:03
    i have run the code finaly. It takes about 14sec to load the code onto the top half of the eeprom but either my code to copy the top half of the eeprom to ram does not work or the reset code from Ariba is reloading the bottom half from the eeprom because after the first load it just keeps rebooting running the boot loader instead of running the code that was copied to hubram.

    Changed the code to use .bin instead of .eeprom because it does not detect the longer extensions. added some code to let me see what is going on.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.

    Post Edited (mctrivia) : 6/30/2009 8:26:32 AM GMT
  • kuronekokuroneko Posts: 3,623
    edited 2009-06-28 11:12
    The reset he mentioned does exactly that:
    The Manual said...
    Same as a hardware reset – reboots the chip.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 11:16
    ok anyone know how i can make the prop reset to the begining of the code but not reload the code from eeprom since the code i want to run is what i just copied to ram?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • kuronekokuroneko Posts: 3,623
    edited 2009-06-28 11:36
    mctrivia said...
    ok anyone know how i can make the prop reset to the begining of the code but not reload the code from eeprom since the code i want to run is what i just copied to ram?
    IIRC fsrw offers boot from EEPROM and boot from SDCard. Either dig out the relevant bits or use it directly.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 11:38
    i saw boot from sdcard but could not figure out how it worked. did not see boot from eeprom. i will go look for that

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 11:43
    i am looking at femto fsrw. can't find iirc fsrw.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • kuronekokuroneko Posts: 3,623
    edited 2009-06-28 11:56
    mctrivia said...
    i am looking at femto fsrw. can't find iirc fsrw.
    Have a look at sdspiFemto.spin (they all fall under fsrw in my book [noparse]:)[/noparse]
  • hover1hover1 Posts: 1,929
    edited 2009-06-28 12:48
    iirc = "If I Recall Correctley"
    mctrivia said...
    i am looking at femto fsrw. can't find iirc fsrw.

  • AribaAriba Posts: 2,690
    edited 2009-06-28 18:36
    When you have copied the code to the HubRAM beginning at address 0, then you can start the code with:
            ...
            cogid  self
            coginit interpreter     'start Spin Interpreter in Cog 0
            cogstop self             'and stop this ASM cog
    
    interpreter     long    ($0004 << 16) | ($F004 << 2) | %0000
    self    res 1
    
    


    In this case you need to stop all the other running cogs before restarting the interpreter.

    Andy
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-28 19:38
    The sdspiFemto driver includes both a bootloader for EEPROM and for an SD card. The code that finishes up after the data file is read into memory is common to both functions.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 20:24
    well it would be nice to just use sdspiFemto then but I have read through the file and can not seem to figure out how to call it to boot from the code stored in the top half of a 512kb EEPROM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • jazzedjazzed Posts: 11,803
    edited 2009-06-28 20:36
    @mctrivia, don't feel bad. I also have trouble following that code.

    To me, the amount of commentary actually gets in the way of understanding what is important to know about using it ... sorry Mike. I specifically remember having trouble understanding the COG interface method, and thus went off and did something else.

    Maybe Mike can explain in a few sentences what needs to be done with the object to fit your need?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-28 20:51
    The following is the EEPROM boot routine from FemtoBasic's sdspiFemto.spin object. This routine does everything you need to do to boot from any EEPROM address on any pair of I/O pins. It starts up the object, stops any running cogs other than the one calling this routine and the one it starts with the assembly loader in it, then starts the boot operation. To boot from the top half of a 64K byte boot EEPROM, if you declare sdspiFemto as the object "sdspi", you'd just call:

    sdspi.bootEEPROM(sdspi#bootAddr + $8000)

    PUB bootEEPROM(addr) | t, c0, c1                       '' Load and run a new SPIN program
      if not start(@c0)                                    ' Start up the I/O routines using a
        abort                                              '  local control block
      long[noparse][[/noparse]control][noparse][[/noparse] 1] := 0                                ' Check for the presence of EEPROM
      long[noparse][[/noparse]control][noparse][[/noparse] 0] := (ioReadCmd | ioLowSpeed) << 24 | (addr & $FFFFFF)
      repeat while long[noparse][[/noparse]control][noparse][[/noparse]0] & ioTestRdy            ' Wait for check to complete and
      if long[noparse][[/noparse]control][noparse][[/noparse] 0] & ioTestErr                      '  abort if there's an error
        abort
      repeat t from 0 to 7                                 ' Stop all COGs except this one and
        if (t <> cogid) and (t <> (cog-1))                 '  the one with the I2C driver in it
          cogstop(t)
      t := ioBootCmd | ioLowSpeed | ioStopLdr | cogid      ' Tell the I2C driver to load 32K
      long[noparse][[/noparse]control][noparse][[/noparse] 1] := $80000000                        '  into HUB RAM after stopping
      long[noparse][[/noparse]control][noparse][[/noparse] 0] := (t << 24) | (addr & $FFFFFF)     '   this calling cog
      repeat while long[noparse][[/noparse]control][noparse][[/noparse] 0] & ioTestRdy            ' Wait for this to finish
      return (long[noparse][[/noparse]control][noparse][[/noparse] 0] & ioTestErr) <> 0           ' Return any error code
    



    The sdspi#bootAddr specifies the EEPROM on I/O pins 28/29 and the $8000 is the starting address of the .binary image in the EEPROM.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 20:56
    i must have an old version(2.003) then because there is not bootEEPROM function.

    Thanks for the help will try right now

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 21:23
    well i think i am going to have to see if viewport still offers free trial. I have found the newest version of sdspiFemto and assuing Mike's code works(which I have no reason to think it wouldn't) then my code copying the eeprom image to the top half is not working.

    When I run the program led 5 turns off(pin driven high) then 6,7,8,9,10 in order showing that it finds the card, code, copies it then tries to boot but then all lights turn off and nothing more happens. the image i am copying should run a test patern checking all io lines functionality.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.

    Post Edited (mctrivia) : 6/30/2009 8:27:00 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-28 21:36
    You might use FemtoBasic or one of its other variations to copy a program from an SD card file to EEPROM. I've used a technique where I load a program into EEPROM (1st 32K), then load DongleBasic into RAM and use its COPY statement to copy the program from the 1st 32K to some other 32K area. You can also use FemtoBasic to examine the contents of EEPROM, perhaps compare what your code does with another area of EEPROM that FemtoBasic copies. There's a DUMP statement that will do a hex/ASCII dump of any area of any EEPROM. DongleBasic has the advantage that it uses pins 30/31 as the console and some kind of PC terminal program on the other end rather than a display and keyboard. You can save the terminal window and print it out if you want.

    When you copy to EEPROM, you have to be careful of "page" boundaries, usually 128 bytes in the larger EEPROMs. Have a look at FemtoBasic's COPY statement for examples. It's roughly at line 1080 in FemtoBasic.spin.

    Post Edited (Mike Green) : 6/28/2009 9:42:59 PM GMT
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-28 21:56
    Thanks a terminal ap to see top half of eeprom is exactly what I need.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-29 03:03
    having trouble with Dongle Basic I type in

    DUMP 32768 200

    and get an error message.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-30 06:40
    well i have goten dongle basic working proper command to see top half of eeprom is

    dump [noparse][[/noparse]$8000],32
    




    shows first 32 bytes

    attached code sucessfully copies the code into the top half of eeprom but does not yet copy top half of eeprom to hub ram and start it. Assembly routines are never used they were my attempt to do what

    PRI loadTop
      light(10)
    
      sdspi.bootEEPROM(sdspi#bootAddr + $8000)
    
    



    is suppose to do.

    [noparse]:([/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-30 08:41
    In·· 'Load EEPROM code from uSD card
    you should wait for the EEPROM after writing each page. EEPROMs need a while to do the write. First it has to clear the page and then write it. That's why it'll send an ACK after it's done. But you have to wait for it. So, maybe the first 32 bytes are correct, but I'd bet the next page won't be correct.
    You have to add something like that:
            start_time := cnt ' prepare to check for a timeout
            repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, sstart)
              if cnt - start_time > clkfreq / 10
                ' vga.str(string("Copy EEPROM wait error",13))
                i:=false
                quit
    
    

    sstart is the EEPROM-adress ($800+(j*PAGESIZE)) in your case.

    ·
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-30 08:56
    you are exactly right. it works perfectly now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-30 09:14
    Is now in OBEX. obex.parallax.com/objects/473/

    thank you to everyone for the help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-30 09:23
    seems i jumped the gun. for some reason hangs if no sd card in

    added a watch dog timer during checking for sd card. now it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.

    Post Edited (mctrivia) : 6/30/2009 9:58:29 AM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-30 11:49
    Bad style for an Object to have the SD-pins fixed. You should add more constants to make it more flexible and keep the configuration data in the constant block.

    'maincog:=cogid
    is commented out - why?

    You don't have error handling for the part waiting for the EEPROM. quit only stops the inner loop ... the outer one will still continue. But the content of the EEPROM might be rubbish.

    It's a good idea to let the forum do a code review before you add some code to the ObjectExchange.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-30 12:24
    PS: Just another thought ...

    The boot-loader has a small footprint. So, there is no need to have a 64kB EEPROM. As long as the own code + bootloader code fits into the 32kB EEPROM why not update it in the normal EEPROM location?

    pub bootLoader
    ....
    if EEPROM_ADRESS>32191
    · loadtop
    else
    · main


    pub main
    ' here comes the user code in case you only have a 32kB EEPROM
    ' otherwise it stays empty

    Post Edited (MagIO2) : 6/30/2009 12:32:36 PM GMT
Sign In or Register to comment.