Commits

Martin Vejnár committed b730303

shupito23: a .dfu file is now created.

  • Participants
  • Parent commits 5f1e238

Comments (0)

Files changed (4)

-f4ea27e2823dea84b9d392e784a9dbcab237c7e9 fw_common/avrlib
+516aa9d3771a47c7262395e478216d3481eeb243 fw_common/avrlib

File shupito23/fw_main_xmega/create_descriptor.py

-import struct, sys, os, os.path
+import struct, sys, os, os.path, json
 from uuid import UUID
 sys.path.insert(0, os.path.join(os.path.split(__file__)[0], '../../fw_common/avrlib'))
 
 from yb_desc import *
 hi = get_hg_info()
 
-yb_desc = make_yb_desc(UUID('093d7f33-cdc6-4928-955d-513d17a85358'),
+device_guid = '093d7f33-cdc6-4928-955d-513d17a85358'
+
+yb_desc = make_yb_desc(UUID(device_guid),
     And(
         Or(
             Config(UUID('46dbc865-b4d0-466b-9b70-2f3f5b264e65'), 1, 8,  # ICSP
         fout = open(sys.argv[1], 'w')
     print_descriptors(fout, usb_desc, rev_hash=hi.rev_hash)
     fout.close()
+
+    if len(sys.argv) > 2:
+        with open(sys.argv[2], 'w') as fout:
+            json.dump({
+                'device_guid': device_guid,
+                'fw_timestamp': hi.timestamp,
+                'dfu_padding': 64
+                }, fout)

File shupito23/fw_main_xmega/fw_main_xmega.cppproj

     <avrtool />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <PreBuildEvent>$(MSBuildProjectDirectory)\create_descriptor.py $(MSBuildProjectDirectory)\usb_descriptors.h
+    <PreBuildEvent>$(MSBuildProjectDirectory)\create_descriptor.py $(MSBuildProjectDirectory)\usb_descriptors.h $(OutputDirectory)\build_info.json
 $(MSBuildProjectDirectory)\generate_baudctrls.py &gt; $(MSBuildProjectDirectory)\baudctrls.h
 </PreBuildEvent>
     <ToolchainSettings>
         <avrgcccpp.linker.optimization.RelaxBranches>True</avrgcccpp.linker.optimization.RelaxBranches>
       </AvrGccCpp>
     </ToolchainSettings>
+    <PostBuildEvent>$(MSBuildProjectDirectory)\make_dfu.py $(OutputDirectory)\$(OutputFileName).hex $(OutputDirectory)\$(OutputFileName).dfu $(OutputDirectory)\build_info.json</PostBuildEvent>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="app.cpp">

File shupito23/fw_main_xmega/make_dfu.py

+import sys, os.path
+sys.path.append(os.path.join(os.path.split(__file__)[0], '../../fw_common/avrlib'))
+
+import dfusuffix, ihex, struct, StringIO, json
+
+if __name__ == '__main__':
+    ff = StringIO.StringIO()
+
+    with open(sys.argv[1], 'r') as fin:
+        hf = ihex.load(fin)
+    for addr, block in hf.make_big_blocks(block_size=256, pad_value=0xff):
+        header = struct.pack('<III', 1, addr, len(block)) + '\x00'*52
+        ff.write(header)
+        ff.write(block)
+
+    with open(sys.argv[3], 'r') as finfo:
+        yb_file = json.load(finfo)
+
+    with open(sys.argv[2], 'wb') as fout:
+        dfusuffix.add_suffix(StringIO.StringIO(ff.getvalue()), fout, 0x4a61, 0x679c, 0x300, yb_file)