Subversion Repositories HelenOS

Rev

Rev 3260 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3260 Rev 3262
Line 30... Line 30...
30
HORD encapsulator
30
HORD encapsulator
31
"""
31
"""
32
 
32
 
33
import sys
33
import sys
34
import os
34
import os
35
import struct
-
 
36
import xstruct
35
import xstruct
37
 
36
 
38
HEADER = xstruct.convert("little: "
37
HEADER = """little:
39
    "char[4]   /* 'HORD' */ "
38
    char[4] tag            /* 'HORD' */
40
    "uint8_t   /* version */ "
39
    uint8_t version        /* version */
41
    "uint8_t   /* encoding */ "
40
    uint8_t encoding       /* encoding */
42
    "uint32_t  /* header size */ "
41
    uint32_t header_size   /* header size */
43
    "uint64_t  /* payload size */ "
42
    uint64_t payload_size  /* payload size */
44
)
43
"""
45
 
44
 
46
HORD_VERSION = 1
-
 
47
HORD_LSB = 1
45
HORD_LSB = 1
48
 
46
 
49
def align_up(size, alignment):
47
def align_up(size, alignment):
50
    "Align upwards to a given alignment"
48
    "Align upwards to a given alignment"
51
    return (((size) + ((alignment) - 1)) & ~((alignment) - 1))
49
    return (((size) + ((alignment) - 1)) & ~((alignment) - 1))
Line 74... Line 72...
74
        return
72
        return
75
   
73
   
76
    inf = file(fs_image, "rb")
74
    inf = file(fs_image, "rb")
77
    outf = file(sys.argv[3], "wb")
75
    outf = file(sys.argv[3], "wb")
78
   
76
   
79
    header_size = struct.calcsize(HEADER)
77
    header = xstruct.create(HEADER)
-
 
78
   
-
 
79
    header_size = header.size()
80
    payload_size = os.path.getsize(fs_image)
80
    payload_size = os.path.getsize(fs_image)
81
   
81
   
82
    header_size_aligned = align_up(header_size, align)
82
    header_size_aligned = align_up(header_size, align)
83
    payload_size_aligned = align_up(payload_size, align)
83
    payload_size_aligned = align_up(payload_size, align)
84
   
84
   
-
 
85
    header.tag = "HORD"
-
 
86
    header.version = 1
-
 
87
    header.encoding = HORD_LSB
-
 
88
    header.header_size = header_size_aligned
85
    outf.write(struct.pack(HEADER, "HORD", HORD_VERSION, HORD_LSB, header_size_aligned, payload_size_aligned))
89
    header.payload_size = payload_size_aligned
-
 
90
   
-
 
91
    outf.write(header.pack())
86
    outf.write(xstruct.little_padding(header_size_aligned - header_size))
92
    outf.write(xstruct.create("little: padding[%d]" % (header_size_aligned - header_size)).pack())
87
   
93
   
88
    outf.write(inf.read())
94
    outf.write(inf.read())
89
   
95
   
90
    padding = payload_size_aligned - payload_size
96
    padding = payload_size_aligned - payload_size
91
    if (padding > 0):
97
    if (padding > 0):
92
        outf.write(xstruct.little_padding(padding))
98
        outf.write(xstruct.create("little: padding[%d]" % padding).pack())
93
   
99
   
94
    inf.close()
100
    inf.close()
95
    outf.close()
101
    outf.close()
96
 
102
 
97
if __name__ == '__main__':
103
if __name__ == '__main__':