Shop OBEX P1 Docs P2 Docs Learn Events
Is PBASIC "Position Independent"? — Parallax Forums

Is PBASIC "Position Independent"?

Julie in TexasJulie in Texas Posts: 21
edited 2009-12-09 02:26 in BASIC Stamp
In another forum (the one I usually live in for discussing the target of the product I have under development), the issue of updating the "firmware" for the product I'm building came up.

I want to disconnect the standard programming port once these devices ship, but I still want to be able to have customers update the if needed.

The thought at this point in time is that I enable downloading the firmware via the same RS-232 interface that is going to control the device. Once downloaded (and I may have found a use for some of that SRAM Mike suggested!), I'd need to overwrite the existing PBASIC code. Which tells me that I need to have a bootstrap loader somewhere in my code. And I need to be able to move the bootstrap loader DOWN in memory so that control can be transferred to it when it goes to overwrite the existing code with the updated code. And that usually requires "position independent code" -- software that runs correctly regardless of where it is loaded into, and executed from, in memory.

So, if I have a block of code that starts at some symbol, can I use that symbol with a READ / WRITE FOR loop, move the data to another address, then GOTO that address and it runs properly? Please say "Yes". But be honest [noparse]:)[/noparse]

burger.gif

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-12-07 22:06
    There is a bootstrap loader built into the Stamp. That is the one the IDE uses to program the device. If you revise the firmware, you can choose "File/Generate Object Code" to make a file that you can email to your customer and that they can subsequently run on a PC to update the firmware. There is also the Stache module that can do field upgrades without a PC.

    Stamp code in general cannot be relocated using READ/WRITE. However, you are in luck if you have a BS2P (or pe or px). You can READ code from one slot and WRITE it at the same offset in another slot, and the RUN it, no worry. That technique can be helpful when the data has to go through a modem or come off a flash card, something like that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-12-08 15:20
    And no, I'm pretty sure BS2 "compiled basic token code" is not position independent -- a 'label' from a GOTO line is replaced by a fixed address to the target of the GOTO -- it's not a relative offset.

    Why 'disable the programming port'? The only thing on the BS2 is "compiled basic token code", and THAT can't be downloaded through the programming port unless YOU put code in to do that.
  • Julie in TexasJulie in Texas Posts: 21
    edited 2009-12-08 17:26
    Are there any other tokens that are encoded to an absolute address? And while in the neighborhood, is there a reference for all the PBASIC tokens? I've about reached my limits of patience for programming in the PBASIC language and am on the verge of writing a compiler for a different language that outputs PBASIC tokens ...

    On the other hand, I may not need to do anything -- copying a piece of code having an absolute address to the correct absolute address works after relocation, but not before.

    But the PBASIC token reference manual would still be very handy to have.
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-12-08 19:55
    I think Tracy Allen's website has that sort of thing.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-12-09 02:26
    I see now that you asked to update through a channel other than the debug/programming port. If it is possible for the application to use one the multislot stamps in the BS2p family, then the task is not hard at all. The bootstrap loader resides in one slot acts to load code into a different slot. Plenty of memory for that. You only have to come up with a scheme for error checking so that it doesn't end up running corrupted code.

    To pursue an interest in how the tokens are built (which is pretty awesome), look at Inside the BASIC Stamp II, and/or Decoding the BASIC Stamp I.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.