recommendations for secure bootloaders


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default recommendations for secure bootloaders

    Hi Guys ,

    i am looking for a secure bootloader code either prefer free but will look at ones that require a license purchase , to be incorporated into my project for 18F chips , so users can update via the net via the usb / serial

    Can someone with experience with it being used in PBP and the code overhead issues if any that need to be considered

    please advise


    Regards

    Sheldon

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    I just finish my first bootloader and it use simple data encription. I isn't so hard to make one. I put bootloader on end of program memory(DEFINE RESET_ORG), so main app isn't affected with bootloader. If you want to jump to bootloader just execute @ GOTO 1EC00h in main app.
    Code for bootloader is simple. Here is part of code for PIC:
    Code:
        DEFINE RESET_ORG 1EC00h
        'Var definition and 
        'Set registers
        BlockSize       VAR BYTE BANKA SYSTEM
        'Get BLOCK SIZE from ASM
        @ MovLW BLOCK_SIZE 
        @ MovWF BlockSize
        MemSize=79999' Used first 80000 bytes of FLASH
        PAUSE 6
        FOR Adr=0 TO MemSize STEP BlockSize 
            ERASECODE Adr
        NEXT Adr
        FOR Adr=0 TO MemSize STEP 128
                Err=0
                FwReceive:
                Err=Err+1
                IF Err=5THEN 'If PC doesn't respond, do something...
                   
                ENDIF
                HSEROUT2 ["A:",DEC6 Adr,13,10] 'Send address to PC
                HSERIN2 100, FwReceive, [WAIT("D:"), Tmp0, Tmp1] 'Receive same byte twice, to eliminate communication errors..
                IF Tmp0<>Tmp1 THEN GOTO FwReceive 
                GOSUB ByteDecode
                WRITE Adr, Tmp0 'Write will first fill up table then it will write 64 or 128 bytes to memory. depending on BlockSize, Check PBP manual
        NEXT Adr
        HSEROUT2 ["C"]
        @ RESET
    You can add EEPROM, yust using READ and WRITE
    Or you can add config bytes, thanks to Darrel Taylor.
    http://www.picbasic.co.uk/forum/showthread.php?t=4093
    For PC side you can use http://www.microchip.com/stellent/id...pnote=en012031 as starting point.
    I menage to translate this app to VB .net, get FLASH, EEPROM and CONFIG data from hex file. From that point it was easy to add simple byte encryption and communication.
    Communication code in Vb.net
    Code:
        Private Sub tmrWriteToDevice_Tick(sender As Object, e As EventArgs) Handles tmrWriteToDevice.Tick
            Static RxBuffer As String
            If SerialPort1.IsOpen = True Then
                RxBuffer += SerialPort1.ReadExisting
                If RxBuffer.Length > 0 Then
                    If InStr(RxBuffer, "A:", CompareMethod.Text) > 0 And Mid(RxBuffer, Len(RxBuffer), 1) = Chr(3) Then
                        Dim Adr As Integer, DataPos As Integer
                        DataPos = InStr(RxBuffer, "A:")
                        RxBuffer = Mid(RxBuffer, DataPos + 2, 6) 'Adress string
                        Adr =  Convert.ToInt32(RxBuffer, 10)
                        RxBuffer = ""
                        ByteArray(0) = HexFileByte(Adr) 'HexFileByte if loaded with flesh data from hex, and encoded.
                        ByteArray(1) = HexFileByte(Adr)
                        SerialPort1.Write("D:")
                        SerialPort1.Write(ByteArray, 0, 2)
                        ToolStripProgressBar1.Value = Adr / 800
                        ToolStripStatusLabel1.Text = ToolStripProgressBar1.Value.ToString & "% Complited"
    
                    ElseIf InStr(RxBuffer, "C" & Chr(3), CompareMethod.Text) > 0 Then
                        ToolStripStatusLabel1.Text = "Data Transfer Complite"
                        ToolStripProgressBar1.Value = 100
                    End If
                End If
            End If
        End Sub
    I tried to put bootloader in main app, but that was very hard. Only way that it could be done is to compile your bootloader, then get flash memory from hex, remove part before and after bootloader, then use ORG 1EC00h and dw(thanks to DT http://www.picbasic.co.uk/forum/show...php?t=3891#LAB) to put data to flash directly.
    From this I created another one to boot from I2C memory, so in bootloader there is only I2C communication so it is only about 1K. Another advantige is that you can load I2C memory from any communication that you have on your application(eg serial port, bluetooth, usb etc..) and still be able to use same bootloader. Idea taken from Mike

    I hope this will be enough to create your bootloader.
    Last edited by pedja089; - 14th August 2014 at 09:57.

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    thanks , there is bit there to understand ,

    I have some of the same issues in that i need to load code that writes to an external flash chip the data required , clears that code then loads the operational code. would also like to make it robust in that if the load fails it restores the orginal , is this something you allowed for as well ?

  4. #4
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    With I2C bootloader you have that protection. If data in external I2C memory isn't complete or if it is corrupted then main app won't start bootloader, simple as that... Erasing and writing to flash isn't started until you have all data in external memory.
    Also another advantage of this is approach is that interrupt vector isn't affected by bootloader. And PIC is able to erase and write memory with code protect turned on.
    Only possible drawback of this is that bootloader isn't run before main app. So if you have bug's in your main app, there is possibility that you won't be able to start bootloader.
    But I didn't need that, I just needed that user can load another firmware version.

  5. #5
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    On the PC side - i have not worked on vb for ages , but i need a nice GUI for the interface , have you seen / done any that would suit this

  6. #6
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    No, that is reason why I converted to VB.net.

  7. #7
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    This is latest free MS offering

    http://www.microsoft.com/en-gb/downl....aspx?id=40787

    Need help with it? Just ask as usual.

  8. #8
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    looks interesting

  9. #9
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    Here is a podcast related to bootloaders, some really good information there...

    http://traffic.libsyn.com/makingembe...s/mes-ep34.mp3

    There are several other very interesting topics there on Embedded.fm
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  10. #10
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: recommendations for secure bootloaders

    thanks guys , it part of the project i need to do , just not had time to to do it , examples are good ,like to buy the finished code , just to save time to do this but in the end i am sure ill have to write it

    like most projects using flash i need to have hex just for the programming of the flash chip , simply cos the code that generates the data for the flash is too big to fit into the cpu as well as the main running code
    then the actual code.

    i am also looking at spiting up functions over 2 cpus for other reasons , so making the updates a bit more interesting

Similar Threads

  1. Replies: 9
    Last Post: - 5th June 2013, 13:17
  2. Logic Probe Recommendations
    By retepsnikrep in forum Off Topic
    Replies: 3
    Last Post: - 12th June 2011, 20:35
  3. Replies: 10
    Last Post: - 15th April 2009, 14:38
  4. Recommendations - Model Train Controller
    By malc-c in forum mel PIC BASIC Pro
    Replies: 101
    Last Post: - 8th March 2007, 08:17
  5. fast programmer recommendations
    By markedwards in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th September 2005, 14:12

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts