Changeset b3105ff6 in mainline for tools/mkhord.py


Ignore:
Timestamp:
2008-08-09T20:16:47Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
838e14e2
Parents:
8c25a4a
Message:

support comments in structures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/mkhord.py

    r8c25a4a rb3105ff6  
    3434import os
    3535import struct
     36import xstruct
     37
     38HEADER = xstruct.convert("little: "
     39        "char[4]   /* 'HORD' */ "
     40        "uint8_t   /* version */ "
     41        "uint8_t   /* encoding */ "
     42        "uint32_t  /* header size */ "
     43        "uint64_t  /* payload size */ "
     44)
     45
     46HORD_VERSION = 1
     47HORD_LSB = 1
    3648
    3749def align_up(size, alignment):
     
    5365       
    5466        align = int(sys.argv[1], 0)
     67        if (align <= 0):
     68                print "<ALIGNMENT> must be positive"
     69                return
     70       
    5571        fs_image = os.path.abspath(sys.argv[2])
    5672        if (not os.path.isfile(fs_image)):
     
    6177        outf = file(sys.argv[3], "wb")
    6278       
    63         header_size = align_up(18, align)
    64         aligned_size = align_up(os.path.getsize(fs_image), align)
     79        header_size = struct.calcsize(HEADER)
     80        payload_size = os.path.getsize(fs_image)
    6581       
    66         outf.write(struct.pack("<4sBBLQ", "HORD", 1, 1, header_size, aligned_size))
    67         outf.write(struct.pack("<" + ("%d" % (header_size - 18)) + "x"))
     82        header_size_aligned = align_up(header_size, align)
     83        payload_size_aligned = align_up(payload_size, align)
     84       
     85        outf.write(struct.pack(HEADER, "HORD", HORD_VERSION, HORD_LSB, header_size_aligned, payload_size_aligned))
     86        outf.write(xstruct.little_padding(header_size_aligned - header_size))
    6887       
    6988        outf.write(inf.read())
    7089       
    71         padding = aligned_size - os.path.getsize(fs_image)
     90        padding = payload_size_aligned - payload_size
    7291        if (padding > 0):
    73                 outf.write(struct.pack("<" + ("%d" % padding) + "x"))
     92                outf.write(xstruct.little_padding(padding))
    7493       
    7594        inf.close()
Note: See TracChangeset for help on using the changeset viewer.