Add KBOOT.

This commit is contained in:
László Monda
2016-08-10 01:45:15 +02:00
commit e6c1fce5b4
9392 changed files with 3751375 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/Tools/blhost/mac/blhost Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
simple.bin - binary example
simple.hex - hex example
simple.srec - SRecord example
simple.sb - SB file example
simple.bd - SB configuration file used to generate simple.sb
demo.bin - demo example. Just do an infinite loop.
flashConfig.bin - flash config data with backdoor key 0102030405060708, and KEYEN is set.

View File

@@ -0,0 +1 @@
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@@ -0,0 +1,8 @@
sources {
inputFile = extern(0);
}
section (0) {
erase 40K..42K;
load inputFile > 0x0000A000;
}

View File

@@ -0,0 +1,96 @@
:10A000000004FF1F9DA3000073A50000A3A500008E
:10A01000B9A50000BBA50000BDA500000000000020
:10A020000000000000000000BFA50000C1A5000066
:10A0300000000000C3A50000C5A50000C7A50000E2
:10A04000C7A50000C7A50000C7A50000C7A5000060
:10A05000C7A50000C7A50000C7A50000C7A5000050
:10A06000C7A50000C7A50000C7A50000C7A5000040
:10A07000C7A50000C7A50000C7A50000C7A5000030
:10A08000C7A50000C7A50000C7A50000C7A5000020
:10A09000C7A50000C7A50000C7A50000C7A5000010
:10A0A000C7A50000C7A50000C7A50000C7A5000000
:10A0B000C7A50000C7A50000C7A50000C7A50000F0
:10A0C000C7A50000C7A50000C7A50000C7A50000E0
:10A0D000C7A50000C7A50000C7A50000C7A50000D0
:10A0E000C7A50000C7A50000C7A50000C7A50000C0
:10A0F000C7A50000C7A50000C7A50000C7A50000B0
:10A10000C7A50000C7A50000C7A50000C7A500009F
:10A11000C7A50000C7A50000C7A50000C7A500008F
:10A12000C7A50000C7A50000C7A50000C7A500007F
:10A13000C7A50000C7A50000C7A50000C7A500006F
:10A14000C7A50000C7A50000C7A50000C7A500005F
:10A15000C7A50000C7A50000C7A50000C7A500004F
:10A16000C7A50000C7A50000C7A50000C7A500003F
:10A17000C7A50000C7A50000C7A50000C7A500002F
:10A18000C7A50000C7A50000C7A50000C7A500001F
:10A19000C7A50000C7A50000C7A50000C7A500000F
:10A1A000C7A50000C7A50000C7A50000C7A50000FF
:10A1B000C7A50000C7A50000C7A50000C7A50000EF
:10A1C000C7A50000C7A50000C7A50000C7A50000DF
:10A1D000C7A50000C7A50000C7A50000C7A50000CF
:10A1E000C7A50000C7A50000C7A50000C7A50000BF
:10A1F000C7A50000C7A50000C7A50000C7A50000AF
:10A20000C7A50000C7A50000C7A50000C7A500009E
:10A21000C7A50000C7A50000C7A50000C7A500008E
:10A22000C7A50000C7A50000C7A50000C7A500007E
:10A23000C7A50000C7A50000C7A50000C7A500006E
:10A24000C7A50000C7A50000C7A50000C7A500005E
:10A25000C7A50000C7A50000C7A50000C7A500004E
:10A26000C7A50000C7A50000C7A50000C7A500003E
:10A27000C7A50000C7A50000C7A50000C7A500002E
:10A28000C7A50000C7A50000C7A50000C7A500001E
:10A29000C7A50000C7A50000C7A50000C7A500000E
:10A2A000C7A50000C7A50000C7A50000C7A50000FE
:10A2B000C7A50000C7A50000C7A50000C7A50000EE
:10A2C000C7A50000C7A50000C7A50000C7A50000DE
:10A2D000C7A50000C7A50000C7A50000C7A50000CE
:10A2E000C7A50000C7A50000C7A50000C7A50000BE
:10A2F000C7A50000C7A50000C7A50000C7A50000AE
:10A30000C7A50000C7A50000C7A50000C7A500009D
:10A31000C7A50000C7A50000C7A50000C7A500008D
:10A32000C7A50000C7A50000C7A50000C7A500007D
:10A33000C7A50000C7A50000C7A50000C7A500006D
:10A34000C7A50000C7A50000C7A50000C7A500005D
:10A35000C7A50000C7A50000C7A50000C7A500004D
:10A36000C7A50000C7A50000C7A50000C7A500003D
:10A37000C7A50000C7A50000C7A50000C7A500002D
:10A38000C7A50000C7A50000C7A50000C7A500001D
:10A39000C7A50000C7A50000C7A5000072B60E48FB
:10A3A0000E49886000220023002400250026002793
:10A3B000B846B946BA46BB46BC4609488546094830
:10A3C0008047094880470948804762B6002000213D
:10A3D000074A9047FEE7000000A0000000ED00E003
:10A3E0000004FF1F3DA5000079A4000031A5000076
:10A3F00093A500005FF0FF30334908605FF0FF3045
:10A40000324908605FF0FF30314908605FF0FF308B
:10A41000304908605FF0FF302F4908605FF0FF307F
:10A420002E4908605FF0FF302D4908605FF0FF3073
:10A430002C49086070475FF0FF302B4908605FF0DF
:10A44000FF302A4908605FF0FF30294908605FF05B
:10A45000FF30284908605FF0FF30274908605FF04F
:10A46000FF30264908605FF0FF30254908605FF043
:10A47000FF30244908607047234824490860244875
:10A480002449254A521A884207D004E00B78037009
:10A49000491C401C521E002AF8D1204820490A1AA3
:10A4A00003E000210170401C521E002AF9D11D4812
:10A4B0001D491E4A521A04E00B780370491C401CC7
:10A4C000521E002AF8D1704780E100E084E100E0EC
:10A4D00088E100E08CE100E090E100E094E100E040
:10A4E00098E100E09CE100E080E200E084E200E02E
:10A4F00088E200E08CE200E090E200E094E200E01C
:10A5000098E200E09CE200E000A0000008ED00E01E
:10A51000000000000000000000000000000000003B
:10A52000000000000000FF1FD4A50000D4A500001B
:10A5300080B5FFF75FFFFFF77EFF01BD03480068AE
:10A5400050F4700001490860704700BF88ED00E0DA
:10A550004EF68851CEF20001086840F470000860A1
:10A56000BFF34F8FBFF36F8F4FF00070E1EE100A13
:10A570007047FEE700F00BF8002801D0C046C04647
:10A580000020C046C04600F004F800F003F80120A7
:10A590007047FEE700F000B80746384600F002F8C2
:10A5A000FBE7FEE780B5C046C046024A110018200E
:10A5B000ABBEFBE726000200FEE7FEE7FEE7FEE794
:10A5C000FEE7FEE7FEE7FEE7C046C046FFF7C0FF36
:04A5D000FFF7D0FFC2
:040000050000A5C989
:00000001FF

View File

@@ -0,0 +1,96 @@
S01A00006C65645F64656D6F5F4652444D2D4B3634462E7372656321
S113A0000004FF1F9DA3000073A50000A3A500008A
S113A010B9A50000BBA50000BDA50000000000001C
S113A0200000000000000000BFA50000C1A5000062
S113A03000000000C3A50000C5A50000C7A50000DE
S113A040C7A50000C7A50000C7A50000C7A500005C
S113A050C7A50000C7A50000C7A50000C7A500004C
S113A060C7A50000C7A50000C7A50000C7A500003C
S113A070C7A50000C7A50000C7A50000C7A500002C
S113A080C7A50000C7A50000C7A50000C7A500001C
S113A090C7A50000C7A50000C7A50000C7A500000C
S113A0A0C7A50000C7A50000C7A50000C7A50000FC
S113A0B0C7A50000C7A50000C7A50000C7A50000EC
S113A0C0C7A50000C7A50000C7A50000C7A50000DC
S113A0D0C7A50000C7A50000C7A50000C7A50000CC
S113A0E0C7A50000C7A50000C7A50000C7A50000BC
S113A0F0C7A50000C7A50000C7A50000C7A50000AC
S113A100C7A50000C7A50000C7A50000C7A500009B
S113A110C7A50000C7A50000C7A50000C7A500008B
S113A120C7A50000C7A50000C7A50000C7A500007B
S113A130C7A50000C7A50000C7A50000C7A500006B
S113A140C7A50000C7A50000C7A50000C7A500005B
S113A150C7A50000C7A50000C7A50000C7A500004B
S113A160C7A50000C7A50000C7A50000C7A500003B
S113A170C7A50000C7A50000C7A50000C7A500002B
S113A180C7A50000C7A50000C7A50000C7A500001B
S113A190C7A50000C7A50000C7A50000C7A500000B
S113A1A0C7A50000C7A50000C7A50000C7A50000FB
S113A1B0C7A50000C7A50000C7A50000C7A50000EB
S113A1C0C7A50000C7A50000C7A50000C7A50000DB
S113A1D0C7A50000C7A50000C7A50000C7A50000CB
S113A1E0C7A50000C7A50000C7A50000C7A50000BB
S113A1F0C7A50000C7A50000C7A50000C7A50000AB
S113A200C7A50000C7A50000C7A50000C7A500009A
S113A210C7A50000C7A50000C7A50000C7A500008A
S113A220C7A50000C7A50000C7A50000C7A500007A
S113A230C7A50000C7A50000C7A50000C7A500006A
S113A240C7A50000C7A50000C7A50000C7A500005A
S113A250C7A50000C7A50000C7A50000C7A500004A
S113A260C7A50000C7A50000C7A50000C7A500003A
S113A270C7A50000C7A50000C7A50000C7A500002A
S113A280C7A50000C7A50000C7A50000C7A500001A
S113A290C7A50000C7A50000C7A50000C7A500000A
S113A2A0C7A50000C7A50000C7A50000C7A50000FA
S113A2B0C7A50000C7A50000C7A50000C7A50000EA
S113A2C0C7A50000C7A50000C7A50000C7A50000DA
S113A2D0C7A50000C7A50000C7A50000C7A50000CA
S113A2E0C7A50000C7A50000C7A50000C7A50000BA
S113A2F0C7A50000C7A50000C7A50000C7A50000AA
S113A300C7A50000C7A50000C7A50000C7A5000099
S113A310C7A50000C7A50000C7A50000C7A5000089
S113A320C7A50000C7A50000C7A50000C7A5000079
S113A330C7A50000C7A50000C7A50000C7A5000069
S113A340C7A50000C7A50000C7A50000C7A5000059
S113A350C7A50000C7A50000C7A50000C7A5000049
S113A360C7A50000C7A50000C7A50000C7A5000039
S113A370C7A50000C7A50000C7A50000C7A5000029
S113A380C7A50000C7A50000C7A50000C7A5000019
S113A390C7A50000C7A50000C7A5000072B60E48F7
S113A3A00E4988600022002300240025002600278F
S113A3B0B846B946BA46BB46BC460948854609482C
S113A3C08047094880470948804762B60020002139
S113A3D0074A9047FEE7000000A0000000ED00E0FF
S113A3E00004FF1F3DA5000079A4000031A5000072
S113A3F093A500005FF0FF30334908605FF0FF3041
S113A400324908605FF0FF30314908605FF0FF3087
S113A410304908605FF0FF302F4908605FF0FF307B
S113A4202E4908605FF0FF302D4908605FF0FF306F
S113A4302C49086070475FF0FF302B4908605FF0DB
S113A440FF302A4908605FF0FF30294908605FF057
S113A450FF30284908605FF0FF30274908605FF04B
S113A460FF30264908605FF0FF30254908605FF03F
S113A470FF30244908607047234824490860244871
S113A4802449254A521A884207D004E00B78037005
S113A490491C401C521E002AF8D1204820490A1A9F
S113A4A003E000210170401C521E002AF9D11D480E
S113A4B01D491E4A521A04E00B780370491C401CC3
S113A4C0521E002AF8D1704780E100E084E100E0E8
S113A4D088E100E08CE100E090E100E094E100E03C
S113A4E098E100E09CE100E080E200E084E200E02A
S113A4F088E200E08CE200E090E200E094E200E018
S113A50098E200E09CE200E000A0000008ED00E01A
S113A5100000000000000000000000000000000037
S113A520000000000000FF1FD4A50000D4A5000017
S113A53080B5FFF75FFFFFF77EFF01BD03480068AA
S113A54050F4700001490860704700BF88ED00E0D6
S113A5504EF68851CEF20001086840F4700008609D
S113A560BFF34F8FBFF36F8F4FF00070E1EE100A0F
S113A5707047FEE700F00BF8002801D0C046C04643
S113A5800020C046C04600F004F800F003F80120A3
S113A5907047FEE700F000B80746384600F002F8BE
S113A5A0FBE7FEE780B5C046C046024A110018200A
S113A5B0ABBEFBE726000200FEE7FEE7FEE7FEE790
S113A5C0FEE7FEE7FEE7FEE7C046C046FFF7C0FF32
S107A5D0FFF7D0FFBE
S903A5C98E

View File

@@ -0,0 +1,33 @@
<!--
* Copyright (C) 2010-2015, Freescale Semiconductor, Inc. All Rights Reserved.
*
* The CFG element contains a list of recognized usb devices.
* DEV elements provide a name, class, vid and pid for each device.
*
* Each LIST element contains a list of update instructions.
*
* Each CMD element contains one update instruction of attribute type.
* "find" - Waits for "timeout" seconds for the "body" device to connect.
* "blhost" - Executes a blhost command.
-->
<UCL>
<CFG>
<STATE name="BootStrap" dev="KBL-CDC" vid="1366" pid="0105"/> <!--JLINK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="0d28" pid="0204"/> <!--mBed CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0707"/> <!--OpenSDK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0089"/> <!--OpenSDA CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1a86" pid="7523"/> <!--CH340 CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="067b" pid="2303"/> <!--PL2303 CDC-->
<STATE name="BootStrap" dev="KBL-HID" vid="15A2" pid="0073"/> <!--KBL USB-HID-->
</CFG>
<!--
The following Lists are for Kinetis Bootloader chips
-->
<LIST name="Kinetis-bootloader" desc="Choose Flash as media">
<CMD state="BootStrap" type="find" body="BootStrap" timeout="180"/>
<CMD state="BootStrap" type="blhost" body="flash-image \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.hex\" erase">Flash Image</CMD>
<CMD state="BootStrap" type="blhost" body="Update Completed!">Done</CMD>
</LIST>
</UCL>

View File

@@ -0,0 +1,35 @@
<!--
* Copyright (C) 2010-2015, Freescale Semiconductor, Inc. All Rights Reserved.
*
* The CFG element contains a list of recognized usb devices.
* DEV elements provide a name, class, vid and pid for each device.
*
* Each LIST element contains a list of update instructions.
*
* Each CMD element contains one update instruction of attribute type.
* "find" - Waits for "timeout" seconds for the "body" device to connect.
* "blhost" - Executes a blhost command.
-->
<UCL>
<CFG>
<STATE name="BootStrap" dev="KBL-CDC" vid="1366" pid="0105"/> <!--JLINK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="0d28" pid="0204"/> <!--mBed CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0707"/> <!--OpenSDK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0089"/> <!--OpenSDA CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1a86" pid="7523"/> <!--CH340 CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="067b" pid="2303"/> <!--PL2303 CDC-->
<STATE name="BootStrap" dev="KBL-HID" vid="15A2" pid="0073"/> <!--KBL USB-HID-->
</CFG>
<!--
The following Lists are for Kinetis Bootloader chips
-->
<LIST name="Kinetis-bootloader" desc="Choose Flash as media">
<CMD state="BootStrap" type="find" body="BootStrap" timeout="180"/>
<!--Suggest including erser command in SB file-->
<!--CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x800">Flash Erase Region</CMD-->
<CMD state="BootStrap" type="blhost" body="receive-sb-file \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.sb\"">Receive SB File</CMD>
<CMD state="BootStrap" type="blhost" body="Update Completed!">Done</CMD>
</LIST>
</UCL>

View File

@@ -0,0 +1,33 @@
<!--
* Copyright (C) 2010-2015, Freescale Semiconductor, Inc. All Rights Reserved.
*
* The CFG element contains a list of recognized usb devices.
* DEV elements provide a name, class, vid and pid for each device.
*
* Each LIST element contains a list of update instructions.
*
* Each CMD element contains one update instruction of attribute type.
* "find" - Waits for "timeout" seconds for the "body" device to connect.
* "blhost" - Executes a blhost command.
-->
<UCL>
<CFG>
<STATE name="BootStrap" dev="KBL-CDC" vid="1366" pid="0105"/> <!--JLINK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="0d28" pid="0204"/> <!--mBed CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0707"/> <!--OpenSDK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0089"/> <!--OpenSDA CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1a86" pid="7523"/> <!--CH340 CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="067b" pid="2303"/> <!--PL2303 CDC-->
<STATE name="BootStrap" dev="KBL-HID" vid="15A2" pid="0073"/> <!--KBL USB-HID-->
</CFG>
<!--
The following Lists are for Kinetis Bootloader chips
-->
<LIST name="Kinetis-bootloader" desc="Choose Flash as media">
<CMD state="BootStrap" type="find" body="BootStrap" timeout="180"/>
<CMD state="BootStrap" type="blhost" body="flash-image \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.srec\" erase">Flash Image</CMD>
<CMD state="BootStrap" type="blhost" body="Update Completed!">Done</CMD>
</LIST>
</UCL>

View File

@@ -0,0 +1,34 @@
<!--
* Copyright (C) 2010-2015, Freescale Semiconductor, Inc. All Rights Reserved.
*
* The CFG element contains a list of recognized usb devices.
* DEV elements provide a name, class, vid and pid for each device.
*
* Each LIST element contains a list of update instructions.
*
* Each CMD element contains one update instruction of attribute type.
* "find" - Waits for "timeout" seconds for the "body" device to connect.
* "blhost" - Executes a blhost command.
-->
<UCL>
<CFG>
<STATE name="BootStrap" dev="KBL-CDC" vid="1366" pid="0105"/> <!--JLINK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="0d28" pid="0204"/> <!--mBed CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0707"/> <!--OpenSDK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0089"/> <!--OpenSDA CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1a86" pid="7523"/> <!--CH340 CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="067b" pid="2303"/> <!--PL2303 CDC-->
<STATE name="BootStrap" dev="KBL-HID" vid="15A2" pid="0073"/> <!--KBL USB-HID-->
</CFG>
<!--
The following Lists are for Kinetis Bootloader chips
-->
<LIST name="Kinetis-bootloader" desc="Choose Flash as media">
<CMD state="BootStrap" type="find" body="BootStrap" timeout="180"/>
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x800">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="write-memory 0xA000 \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\demo.bin\"">Write Memory</CMD>
<CMD state="BootStrap" type="blhost" body="Update Completed!">Done</CMD>
</LIST>
</UCL>

View File

@@ -0,0 +1,155 @@
<!--
* Copyright (C) 2010-2015, Freescale Semiconductor, Inc. All Rights Reserved.
*
* The CFG element contains a list of recognized usb devices.
* DEV elements provide a name, class, vid and pid for each device.
*
* Each LIST element contains a list of update instructions.
*
* Each CMD element contains one update instruction of attribute type.
* "find" - Waits for "timeout" seconds for the "body" device to connect.
* "blhost" - Executes a blhost command.
-->
<UCL>
<CFG>
<STATE name="BootStrap" dev="KBL-CDC" vid="1366" pid="0105"/> <!--JLINK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="0d28" pid="0204"/> <!--mBed CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0707"/> <!--OpenSDK CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1357" pid="0089"/> <!--OpenSDA CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="1a86" pid="7523"/> <!--CH340 CDC-->
<STATE name="BootStrap" dev="KBL-CDC" vid="067b" pid="2303"/> <!--PL2303 CDC-->
<STATE name="BootStrap" dev="KBL-HID" vid="15A2" pid="0073"/> <!--KBL USB-HID-->
</CFG>
<!--
The following Lists are for Kinetis Bootloader chips
-->
<LIST name="Kinetis-bootloader" desc="Choose Flash as media">
<CMD state="BootStrap" type="find" body="BootStrap" timeout="180"/>
<!--Get/Set bootloader property-->
<CMD state="BootStrap" type="blhost" body="get-property 1">Get Property 1</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 2">Get Property 2</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 3">Get Property 3</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 4">Get Property 4</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 5">Get Property 5</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 6">Get Property 6</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 7">Get Property 7</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 8">Get Property 8</CMD>
<!--Default is 1(enable verify flash program)-->
<CMD state="BootStrap" type="blhost" body="get-property 10">Get Property 10</CMD>
<CMD state="BootStrap" type="blhost" body="set-property 10 0">Set Property 10</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 10">Get Property 10</CMD>
<CMD state="BootStrap" type="blhost" body="set-property 10 1">Set Property 10</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 10">Get Property 10</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 11">Get Property 11</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 12">Get Property 12</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 14">Get Property 14</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 15">Get Property 15</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 16">Get Property 16</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 18">Get Property 18</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 19">Get Property 19</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 20">Get Property 20</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 21">Get Property 21</CMD>
<!--Default is 1(user margin)-->
<CMD state="BootStrap" type="blhost" body="get-property 22">Get Property 22</CMD>
<CMD state="BootStrap" type="blhost" body="set-property 22 0">Set Property 22</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 22">Get Property 22</CMD>
<CMD state="BootStrap" type="blhost" body="set-property 22 1">Set Property 22</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 22">Get Property 22</CMD>
<!--Please check the target device's reference manual to check whether these properties are supported.-->
<!--CMD state="BootStrap" type="blhost" body="get-property 23">Get Property 23</CMD-->
<!--CMD state="BootStrap" type="blhost" body="get-property 24">Get Property 24</CMD-->
<!--CMD state="BootStrap" type="blhost" body="get-property 25 1">Get Property 25</CMD-->
<!--Fill flash memory-->
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x10">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="fill-memory 0xA000 0x10 0x5a byte">Fill Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x10">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="fill-memory 0xA000 0x10 0x55aa short">Fill Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x10">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="fill-memory 0xA000 0x10 0x5555aaaa word">Fill Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<!--Write memory-->
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x10">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="write-memory 0xA000 {{00112233445566778899aabbccddeeff}}">Write Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x800">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="write-memory 0xA000 \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.bin\"">Write Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<!--Flash HEX/Srecord image file-->
<CMD state="BootStrap" type="blhost" body="flash-image \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.srec\" erase">Flash Image</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="flash-image \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.hex\" erase">Flash Image</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<!--Send SB file-->
<CMD state="BootStrap" type="blhost" body="receive-sb-file \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\simple.sb\"">Receive SB File</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<!--Erase all flash memory-->
<!--CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0x400 0x10">Read Memory</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-all">Flash Erase All</CMD>
<CMD state="BootStrap" type="blhost" body="read-memory 0xA000 0x800">Read Memory</CMD-->
<!--For ROM bootloader, FTFx.FSEC will be cleared(1),-->
<!--For Flash bootloader, FTFx.FSEC locates at reserved region, no change.-->
<!--CMD state="BootStrap" type="blhost" body="read-memory 0x400 0x10">Read Memory</CMD-->
<!--For ROM bootloader, after reset, device will fall into secure state.-->
<!--For Flash bootloader, security will not be changed.-->
<!--CMD state="BootStrap" type="blhost" body="reset">Reset</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD-->
<!--Erase all flash memory and unsecure the device(for ROM only)-->
<!--Flash bootloader doesn't support this command.-->
<!--CMD state="BootStrap" type="blhost" body="flash-erase-all-unsecure">Flash Erase All Unsecure</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD-->
<!--Unlock device by backdoor key(for ROM only)-->
<!--For Flash bootloader, FTFx.FSEC locates at reserved region.-->
<!--CMD state="BootStrap" type="blhost" body="flash-erase-all">Flash Erase All</CMD>
<CMD state="BootStrap" type="blhost" body="write-memory 0x400 \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\flashConfig.bin\"">Write Memory</CMD>
<CMD state="BootStrap" type="blhost" body="reset">Reset</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD>
<CMD state="BootStrap" type="blhost" body="flash-security-disable 0102030405060708">Flash Security Disable</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD>
<CMD state="BootStrap" type="blhost" body="reset">Reset</CMD>
<CMD state="BootStrap" type="blhost" body="get-property 17">Get Property 17</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-all-unsecure">Flash Erase All Unsecure</CMD-->
<!--Program IFR-->
<!--This command is not supported by all kinetis bootloader devices. Please refer to device's reference manual
to check whether it is supported and the supported index and length-->
<!--CMD state="BootStrap" type="blhost" body="flash-read-once 0x30 4">Flash Read Once</CMD>
<CMD state="BootStrap" type="blhost" body="flash-program-once 0x30 4 12345678">Flash Program Once</CMD>
<CMD state="BootStrap" type="blhost" body="flash-read-once 0x30 4">Flash Read Once</CMD>
<CMD state="BootStrap" type="blhost" body="flash-erase-all-unsecure">Flash Erase All Unsecure</CMD>
<CMD state="BootStrap" type="blhost" body="flash-read-once 0x30 4">Flash Read Once</CMD-->
<CMD state="BootStrap" type="blhost" body="flash-erase-region 0xA000 0x800">Flash Erase Region</CMD>
<CMD state="BootStrap" type="blhost" body="write-memory 0xA000 \"Profiles\\Kinetis Bootloader\\OS Firmware\\files\\demo.bin\"">Write Memory</CMD>
<CMD state="BootStrap" type="blhost" body="execute 0xA39D 0 0x1fff0400">Execute</CMD>
<CMD state="BootStrap" type="blhost" body="Update Completed!">Done</CMD>
</LIST>
</UCL>

View File

@@ -0,0 +1,9 @@
[PROFILE]
PLAYER=Kinetis Update
VERSION=2
[OPERATIONS]
UTP_UPDATE=OS Firmware,120,0
[OS Firmware]

View File

@@ -0,0 +1,2 @@
[UICfg]
PortMgrDlg=1

View File

@@ -0,0 +1,8 @@
[profiles]
chip = Kinetis Bootloader
[platform]
board =
[LIST]
name = Kinetis-bootloader

96
bin/create_fl_image.py Normal file
View File

@@ -0,0 +1,96 @@
#! /usr/bin/env python
# Copyright (c) 2013-2014 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import os
import elf
# usage: create_fl_image.py <elffile> <binfile> <cfile>
def main(argv):
# Collect arguments
if len(sys.argv) != 4:
print 'usage: create_fl_image.py <elffile> <binfile> <cfile>'
sys.exit(2)
elfFilename = argv[0]
binFilename = argv[1]
cFilename = argv[2]
# Open files
try:
binFile = open(binFilename, 'rb')
except IOError:
print 'cannot open file %s' % binFilename
sys.exit(2)
try:
cFile = open(cFilename, 'w')
except IOError:
print 'cannot open file %s' % cFilename
sys.exit(2)
elfData = elf.ELFObject()
try:
with open(elfFilename, 'rb') as elfFile:
elfData.fromFile(elfFile)
if elfData.e_type != elf.ELFObject.ET_EXEC:
raise Exception("No executable")
resetHandler = elfData.getSymbol("Reset_Handler")
vectors = elfData.getSymbol("__Vectors")
stack = elfData.getSymbol("CSTACK$$Limit")
except:
print 'cannot process file %s' % elfFilename
sys.exit(2)
# Print header
print >> cFile, '/* Created by create_fl_image.py, do not edit */\n'
print >> cFile, '#include "bootloader_common.h"\n'
print >> cFile, 'const uint8_t g_flashloaderImage[] = {'
# Print byte data
totalBytes = 0
while True:
data = binFile.read(16)
dataLen = len(data)
if dataLen == 0: break
totalBytes += dataLen;
cFile.write(' ')
for i in range(dataLen):
cFile.write('0x%02x, ' % ord(data[i]))
print >> cFile
print >> cFile, '};\n'
# Print size and other info
cFile.write('const uint32_t g_flashloaderSize = %dU;\n' % totalBytes)
cFile.write('const uint32_t g_flashloaderBase = 0x%x;\n' % vectors.st_value)
cFile.write('const uint32_t g_flashloaderEntry = 0x%x;\n' % resetHandler.st_value)
cFile.write('const uint32_t g_flashloaderStack = 0x%x;\n' % stack.st_value)
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -0,0 +1,96 @@
#! /usr/bin/env python
# Copyright (c) 2013-2014 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import os
import elf
# usage: create_fl_image.py <elffile> <binfile> <cfile>
def main(argv):
# Collect arguments
if len(sys.argv) != 4:
print 'usage: create_fl_image.py <elffile> <binfile> <cfile>'
sys.exit(2)
elfFilename = argv[0]
binFilename = argv[1]
cFilename = argv[2]
# Open files
try:
binFile = open(binFilename, 'rb')
except IOError:
print 'cannot open file %s' % binFilename
sys.exit(2)
try:
cFile = open(cFilename, 'w')
except IOError:
print 'cannot open file %s' % cFilename
sys.exit(2)
elfData = elf.ELFObject()
try:
with open(elfFilename, 'rb') as elfFile:
elfData.fromFile(elfFile)
if elfData.e_type != elf.ELFObject.ET_EXEC:
raise Exception("No executable")
resetHandler = elfData.getSymbol("Reset_Handler")
vectors = elfData.getSymbol("__isr_vector")
stack = elfData.getSymbol("__StackTop")
except:
print 'cannot process file %s' % elfFilename
sys.exit(2)
# Print header
print >> cFile, '/* Created by create_fl_image.py, do not edit */\n'
print >> cFile, '#include "bootloader_common.h"\n'
print >> cFile, 'const uint8_t g_flashloaderImage[] = {'
# Print byte data
totalBytes = 0
while True:
data = binFile.read(16)
dataLen = len(data)
if dataLen == 0: break
totalBytes += dataLen;
cFile.write(' ')
for i in range(dataLen):
cFile.write('0x%02x, ' % ord(data[i]))
print >> cFile
print >> cFile, '};\n'
# Print size and other info
cFile.write('const uint32_t g_flashloaderSize = %dU;\n' % totalBytes)
cFile.write('const uint32_t g_flashloaderBase = 0x%x;\n' % vectors.st_value)
cFile.write('const uint32_t g_flashloaderEntry = 0x%x;\n' % resetHandler.st_value)
cFile.write('const uint32_t g_flashloaderStack = 0x%x;\n' % stack.st_value)
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -0,0 +1,96 @@
#! /usr/bin/env python
# Copyright (c) 2013-2014 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import os
import elf
# usage: create_fl_image.py <elffile> <binfile> <cfile>
def main(argv):
# Collect arguments
if len(sys.argv) != 4:
print 'usage: create_fl_image.py <elffile> <binfile> <cfile>'
sys.exit(2)
elfFilename = argv[0]
binFilename = argv[1]
cFilename = argv[2]
# Open files
try:
binFile = open(binFilename, 'rb')
except IOError:
print 'cannot open file %s' % binFilename
sys.exit(2)
try:
cFile = open(cFilename, 'w')
except IOError:
print 'cannot open file %s' % cFilename
sys.exit(2)
elfData = elf.ELFObject()
try:
with open(elfFilename, 'rb') as elfFile:
elfData.fromFile(elfFile)
if elfData.e_type != elf.ELFObject.ET_EXEC:
raise Exception("No executable")
resetHandler = elfData.getSymbol("Reset_Handler")
vectors = elfData.getSymbol("__Vectors")
stack = elfData.getSymbol("Image$$ARM_LIB_STACK$$ZI$$Limit")
except:
print 'cannot process file %s' % elfFilename
sys.exit(2)
# Print header
print >> cFile, '/* Created by create_fl_image.py, do not edit */\n'
print >> cFile, '#include "bootloader_common.h"\n'
print >> cFile, 'const uint8_t g_flashloaderImage[] = {'
# Print byte data
totalBytes = 0
while True:
data = binFile.read(16)
dataLen = len(data)
if dataLen == 0: break
totalBytes += dataLen;
cFile.write(' ')
for i in range(dataLen):
cFile.write('0x%02x, ' % ord(data[i]))
print >> cFile
print >> cFile, '};\n'
# Print size and other info
cFile.write('const uint32_t g_flashloaderSize = %dU;\n' % totalBytes)
cFile.write('const uint32_t g_flashloaderBase = 0x%x;\n' % vectors.st_value)
cFile.write('const uint32_t g_flashloaderEntry = 0x%x;\n' % resetHandler.st_value)
cFile.write('const uint32_t g_flashloaderStack = 0x%x;\n' % stack.st_value)
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -0,0 +1,4 @@
rem Pass in full path and Release|Debug to iar project directory
cd /d %1
ielftool --bin output\%2\flashloader.elf flashloader.bin
python ..\..\..\..\bin\create_fl_image.py output\%2\flashloader.elf flashloader.bin output\%2\flashloader_image.c

View File

@@ -0,0 +1,5 @@
rem Pass in full path and Release|Debug to iar project directory
cd /d %1
arm-none-eabi-objcopy -I elf32-littlearm -O binary flashloader.elf flashloader.bin
python ..\..\..\..\..\bin\create_fl_image_kds.py flashloader.elf flashloader.bin flashloader_image.c

View File

@@ -0,0 +1,8 @@
rem Pass in full path and Release|Debug to iar project directory
cd /d %1
arm-none-eabi-objcopy -I elf32-littlearm -O binary output\release\flashloader.elf flashloader.bin
python ..\..\..\..\bin\create_fl_image_kds.py output\release\flashloader.elf flashloader.bin flashloader_image.c
arm-none-eabi-objcopy -I elf32-littlearm -O binary output\debug\flashloader.elf flashloader.bin
python ..\..\..\..\bin\create_fl_image_mdk.py output\debug\flashloader.elf flashloader.bin flashloader_image.c

442
bin/elf.py Normal file
View File

@@ -0,0 +1,442 @@
#!/usr/bin/env python
#
# ORIGINAL AUTHOR, COPYRIGHT and LICENSE
#
# Copyright (c) 2003-2010 Chris Liechti <cliechti@gmx.net>
# All Rights Reserved.
# Simplified BSD License (see LICENSE.txt for full text)
#
#
# MODIFICATIONS
#
# Copyright (c) 2014 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""\
ELF object file reader.
"""
import struct
# size alignment
# Elf32_Addr 4 4 Unsigned program address
# Elf32_Half 2 2 Unsigned medium integer
# Elf32_Off 4 4 Unsigned file offset
# Elf32_Sword 4 4 Signed large integer
# Elf32_Word 4 4 Unsigned large integer
# unsignedchar 1 1 Unsigned small integer
#define EI_NIDENT 16
#~ typedef struct{
#~ unsigned char e_ident[EI_NIDENT];
#~ Elf32_Half e_type;
#~ Elf32_Half e_machine;
#~ Elf32_Word e_version;
#~ Elf32_Addr e_entry;
#~ Elf32_Off e_phoff;
#~ Elf32_Off e_shoff;
#~ Elf32_Word e_flags;
#~ Elf32_Half e_ehsize;
#~ Elf32_Half e_phentsize;
#~ Elf32_Half e_phnum;
#~ Elf32_Half e_shentsize;
#~ Elf32_Half e_shnum;
#~ Elf32_Half e_shstrndx;
#~ } Elf32_Ehdr;
#Section Header
#~ typedef struct {
#~ Elf32_Word sh_name;
#~ Elf32_Word sh_type;
#~ Elf32_Word sh_flags;
#~ Elf32_Addr sh_addr;
#~ Elf32_Off sh_offset;
#~ Elf32_Word sh_size;
#~ Elf32_Word sh_link;
#~ Elf32_Word sh_info;
#~ Elf32_Word sh_addralign;
#~ Elf32_Word sh_entsize;
#~ } Elf32_Shdr;
#~ typedef struct {
#~ Elf32_Word p_type;
#~ Elf32_Off p_offset;
#~ Elf32_Addr p_vaddr;
#~ Elf32_Addr p_paddr;
#~ Elf32_Word p_filesz;
#~ Elf32_Word p_memsz;
#~ Elf32_Word p_flags;
#~ Elf32_Word p_align;
#~ } Elf32_Phdr;
# struct Elf32_Sym
# {
# Elf32_Word st_name; //!< Index into file's string table.
# Elf32_Addr st_value; //!< Value associated with the symbol. Depends on context.
# Elf32_Word st_size; //!< Size associated with symbol. 0 if the symbol has no size or an unknown size.
# unsigned char st_info; //!< Specified the symbol's type and binding attributes.
# unsigned char st_other; //!< Currently 0 (reserved).
# Elf32_Half st_shndx; //!< Section header table index for this symbol.
# };
class ELFException(Exception): pass
class ELFSymbol:
Elf32_Sym = "<IIIBBH"
STB_LOCAL = 0, # Local symbol not visible outside the object file.
STB_GLOBAL = 1 # Symbol is visible to all object files being linked together.
STB_WEAK = 2 # Like global symbols, but with lower precedence.
STB_LOPROC = 13
STB_HIPROC = 15
STT_NOTYPE = 0 # The symbol's type is not specified.
STT_OBJECT = 1 # The symbol is associated with a data object, such as a variable or array.
STT_FUNC = 2 # The symbol is associated with a function or other executable code.
STT_SECTION = 3 # The synmbol is associated with a section. Primarily used for relocation.
STT_FILE = 4 # A file symbol has STB_LOCAL binding, its section index is SHN_ABS, and it precedes the other STB_LOCAL symbols for the file, if it is present.
STT_LOPROC = 13 # Low bound of processor-specific symbol types.
STT_HIPROC = 15 # High bound of processor-specific symbol types.
ARM_SEQUENCE_MAPSYM = "$a"
DATA_SEQUENCE_MAPSYM = "$d"
THUMB_SEQUENCE_MAPSYM = "$t"
THUMB_BL_TAGSYM = "$b"
FN_PTR_CONST_TAGSYM = "$f"
INDIRECT_FN_CALL_TAGSYM = "$p"
MAPPING_SYMBOL_COUNT_TAGSYM = "$m"
def __init__(self):
(self.st_name, self.st_value, self.st_size, self.st_info,
self.st_other, self.st_shndx, self.st_bind, self.st_type) = [0] * 8
self.name = None
def fromString(self, s):
(self.st_name, self.st_value, self.st_size, self.st_info,
self.st_other, self.st_shndx) = struct.unpack(self.Elf32_Sym, s)
self.st_bind = (self.st_info >> 4) & 0x0f
self.st_type = self.st_info & 0x0f
def __repr__(self):
return "%s(%s, st_value=0x%08x, st_size=%d, st_bind=%d, st_type=%d, st_shndx=%d)" % (
self.__class__.__name__,
self.name is not None and "%r" % self.name or "st_name=%s" % self.st_name,
self.st_value, self.st_size, self.st_bind, self.st_type, self.st_shndx)
class ELFSection:
"""read and store a section"""
Elf32_Shdr = "<IIIIIIIIII" #header format
#section types
SHT_NULL = 0
SHT_PROGBITS = 1
SHT_SYMTAB = 2
SHT_STRTAB = 3
SHT_RELA = 4
SHT_HASH = 5
SHT_DYNAMIC = 6
SHT_NOTE = 7
SHT_NOBITS = 8
SHT_REL = 9
SHT_SHLIB = 10
SHT_DYNSYM = 11
SHT_LOPROC = 0x70000000L
SHT_HIPROC = 0x7fffffffL
SHT_LOUSER = 0x80000000L
SHT_HIUSER = 0xffffffffL
#section attribute flags
SHF_WRITE = 0x1
SHF_ALLOC = 0x2
SHF_EXECINSTR = 0x4
SHF_MASKPROC = 0xf0000000
def __init__(self):
"""creat a new empty section object"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = [0]*10
self.name = None
self.data = None
self.lma = None
def fromString(self, s):
"""get section header from string"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = struct.unpack(self.Elf32_Shdr, s)
def __repr__(self):
"""pretty print for debug..."""
return "%s(%s, sh_type=%s, sh_flags=%s, "\
"sh_addr=0x%04x, sh_offset=0x%04x, sh_size=%s, sh_link=%s, "\
"sh_info=%s, sh_addralign=%s, sh_entsize=%s, lma=0x%04x)" % (
self.__class__.__name__,
self.name is not None and "%r" % self.name or "sh_name=%s" % self.sh_name,
self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize, self.lma)
class ELFProgramHeader:
"""Store and parse a program header"""
Elf32_Phdr = "<IIIIIIII" #header format
#segmet types
PT_NULL = 0
PT_LOAD = 1
PT_DYNAMIC = 2
PT_INTERP = 3
PT_NOTE = 4
PT_SHLIB = 5
PT_PHDR = 6
PT_LOPROC = 0x70000000L
PT_HIPROC = 0x7fffffffL
#segment flags
PF_R = 0x4 #segment is readable
PF_W = 0x2 #segment is writable
PF_X = 0x1 #segment is executable
def __init__(self):
"""create a new, empty segment/program header"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags, self.p_align) = [0]*8
self.data = None
def fromString(self, s):
"""parse header info from string"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align) = struct.unpack(self.Elf32_Phdr, s)
def __repr__(self):
"""pretty print for debug..."""
return "%s(p_type=%s, p_offset=0x%04x, p_vaddr=0x%04x, p_paddr=0x%04x, "\
"p_filesz=%s, p_memsz=%s, p_flags=%s, "\
"p_align=%s)" % (
self.__class__.__name__,
self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align)
class ELFObject:
"""Object to read and handle an LEF object file"""
#header information
Elf32_Ehdr = "<16sHHIIIIIHHHHHH"
#offsets within e_ident
EI_MAG0 = 0 #File identification
EI_MAG1 = 1 #File identification
EI_MAG2 = 2 #File identification
EI_MAG3 = 3 #File identification
EI_CLASS = 4 #File class
EI_DATA = 5 #Data encoding
EI_VERSION = 6 #File version
EI_PAD = 7 #Start of padding bytes
EI_NIDENT = 16 #Size of e_ident[]
#elf file type flags
ET_NONE = 0 #No file type
ET_REL = 1 #Relocatable file
ET_EXEC = 2 #Executable file
ET_DYN = 3 #Shared object file
ET_CORE = 4 #Core file
ET_LOPROC = 0xff00 #Processor-specific
ET_HIPROC = 0xffff #Processor-specific
#ELF format
ELFCLASSNONE = 0 #Invalid class
ELFCLASS32 = 1 #32-bit objects
ELFCLASS64 = 2 #64-bit objects
#encoding
ELFDATANONE = 0 #Invalid data encoding
ELFDATA2LSB = 1 #See below
ELFDATA2MSB = 2 #See below
def __init__(self):
"""create a new elf object"""
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = [0]*14
def fromFile(self, fileobj):
"""read all relevant data from fileobj.
the file must be seekable"""
fileobj.seek(0)
#get file header
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = struct.unpack(
self.Elf32_Ehdr, fileobj.read(struct.calcsize(self.Elf32_Ehdr)))
#verify if its a known format and realy an ELF file
if self.e_ident[0:4] != '\x7fELF' and\
self.e_ident[self.EI_CLASS] != self.ELFCLASS32 and\
self.e_ident[self.EI_DATA] != self.ELFDATA2LSB and\
self.e_ident[self.EI_VERSION] != 1:
raise ELFException("Not a valid ELF file")
#load programm headers
self.programmheaders = []
if self.e_phnum:
#load program headers
fileobj.seek(self.e_phoff)
for sectionnum in range(self.e_phnum):
shdr = (fileobj.read(self.e_phentsize) + '\0'* struct.calcsize(ELFProgramHeader.Elf32_Phdr))[0:struct.calcsize(ELFProgramHeader.Elf32_Phdr)]
psection = ELFProgramHeader()
psection.fromString(shdr)
if psection.p_offset: #skip if section has invalid offset in file
self.programmheaders.append(psection)
#~ #get the segment data from the file for each prg header
#~ for phdr in self.programmheaders:
#~ fileobj.seek(phdr.p_offset)
#~ phdr.data = fileobj.read(phdr.p_filesz)
#~ #pad if needed
#~ if phdr.p_filesz < phdr.p_memsz:
#~ phdr.data = phdr.data + '\0' * (phdr.p_memsz-phdr.p_filesz)
#load sections
self.sections = []
fileobj.seek(self.e_shoff)
for sectionnum in range(self.e_shnum):
shdr = (fileobj.read(self.e_shentsize) + '\0'* struct.calcsize(ELFSection.Elf32_Shdr))[0:struct.calcsize(ELFSection.Elf32_Shdr)]
elfsection = ELFSection()
elfsection.fromString(shdr)
self.sections.append(elfsection)
#load data for all sections
for section in self.sections:
fileobj.seek(section.sh_offset)
data = fileobj.read(section.sh_size)
section.data = data
if section.sh_type == ELFSection.SHT_STRTAB:
section.values = data.split('\0')
section.lma = self.getLMA(section)
#get section names
for section in self.sections:
# start = self.sections[self.e_shstrndx].data[section.sh_name:]
# section.name = start.split('\0')[0]
section.name = self.getString(self.e_shstrndx, section.sh_name)
# Load symbols.
symtab = self.getSection('.symtab')
symsize = symtab.sh_entsize
self.symbolCount = symtab.sh_size / symsize
self.symbols = []
self.symbolDict = {}
for symnum in range(self.symbolCount):
# Compute range
start = symnum * symsize
end = start + symsize
# Create symbol
sym = ELFSymbol()
sym.fromString(symtab.data[start:end])
# Read symbol name string
sym.name = self.getString(symtab.sh_link, sym.st_name)
# Add to symbol list
self.symbols.append(sym)
self.symbolDict[sym.name] = sym
def getString(self, table, index):
start = self.sections[table].data[index:]
return start.split('\0')[0]
def getSection(self, name):
"""get section by name"""
for section in self.sections:
if section.name == name:
return section
def getSymbol(self, name):
return self.symbolDict[name]
def getProgrammableSections(self):
"""get all program headers that are marked as executable and
have suitable attributes to be code"""
res = []
for p in self.programmheaders:
#~ print p
#~ if section.sh_flags & self.SHF_ALLOC and section.name not in ('.data', '.data1', '.bss'):
#~ if p.p_type == ELFProgramHeader.PT_LOAD:# and p.p_paddr == p.p_vaddr and p.p_flags & ELFProgramHeader.PF_X:
if p.p_type == ELFProgramHeader.PT_LOAD:
res.append(p)
return res
def getLMA(self, section):
#magic load memory address calculation ;-)
for p in self.programmheaders:
if (p.p_paddr != 0 and \
p.p_type == ELFProgramHeader.PT_LOAD and \
p.p_vaddr != p.p_paddr and \
p.p_vaddr <= section.sh_addr and \
(p.p_vaddr + p.p_memsz >= section.sh_addr + section.sh_size) \
and (not (section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS) \
or (p.p_offset <= section.sh_offset \
and (p.p_offset + p.p_filesz >= section.sh_offset + section.sh_size)))):
return section.sh_addr + p.p_paddr - p.p_vaddr
return section.sh_addr
def getSections(self):
"""get sections relevant for the application"""
res = []
for section in self.sections:
if section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS:
res.append(section)
return res
def __repr__(self):
"""pretty print for debug..."""
return "%s(self.e_type=%r, self.e_machine=%r, self.e_version=%r, sections=%r)" % (
self.__class__.__name__,
self.e_type, self.e_machine, self.e_version,
[section.name for section in self.sections])
if __name__ == '__main__':
print "This is only a module test!"
elf = ELFObject()
elf.fromFile(open("test.elf"))
if elf.e_type != ELFObject.ET_EXEC:
raise Exception("No executable")
print elf
#~ print repr(elf.getSection('.text').data)
#~ print [(s.name, hex(s.sh_addr)) for s in elf.getSections()]
print "-"*20
for p in elf.sections: print p
print "-"*20
for p in elf.getSections(): print p
print "-"*20
for p in elf.getProgrammableSections(): print p

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/mmcau/cm4/mmcau_cm4.bin Normal file

Binary file not shown.