Subversion Repositories HelenOS

Rev

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

Rev 3046 Rev 3244
Line 32... Line 32...
32
 
32
 
33
import sys
33
import sys
34
import os
34
import os
35
import struct
35
import struct
36
 
36
 
37
def align_up(size, alignment):
-
 
38
    "Align upwards to a given alignment"
-
 
39
    return (((size) + ((alignment) - 1)) & ~((alignment) - 1))
-
 
40
 
-
 
41
def usage(prname):
37
def usage(prname):
42
    "Print usage syntax"
38
    "Print usage syntax"
43
    print prname + " <ALIGNMENT> <PATH> <IMAGE>"
39
    print prname + " <ALIGNMENT> <PATH> <IMAGE>"
44
 
40
 
45
def recursion(root, outf):
41
def recursion(root, outf):
Line 74... Line 70...
74
            payload_size += 5
70
            payload_size += 5
75
   
71
   
76
    return payload_size
72
    return payload_size
77
 
73
 
78
def main():
74
def main():
79
    if (len(sys.argv) < 4):
75
    if (len(sys.argv) < 3):
80
        usage(sys.argv[0])
76
        usage(sys.argv[0])
81
        return
77
        return
82
   
78
   
83
    if (not sys.argv[1].isdigit()):
-
 
84
        print "<ALIGNMENT> must be a number"
-
 
85
        return
-
 
86
   
-
 
87
    align = int(sys.argv[1], 0)
-
 
88
    path = os.path.abspath(sys.argv[2])
79
    path = os.path.abspath(sys.argv[1])
89
    if (not os.path.isdir(path)):
80
    if (not os.path.isdir(path)):
90
        print "<PATH> must be a directory"
81
        print "<PATH> must be a directory"
91
        return
82
        return
92
   
83
   
93
    header_size = align_up(18, align)
-
 
94
    outf = file(sys.argv[3], "w")
84
    outf = file(sys.argv[2], "w")
95
    outf.write(struct.pack("<" + ("%d" % header_size) + "x"))
-
 
96
   
85
   
97
    outf.write(struct.pack("<5s", "TMPFS"))
86
    outf.write(struct.pack("<5s", "TMPFS"))
98
    payload_size = 5
-
 
99
   
-
 
100
    payload_size += recursion(path, outf)
87
    recursion(path, outf)
101
       
-
 
102
    outf.write(struct.pack("<BL", 0, 0))
88
    outf.write(struct.pack("<BL", 0, 0))
103
    payload_size += 5
-
 
104
   
-
 
105
    aligned_size = align_up(payload_size, align)
-
 
106
   
-
 
107
    if (aligned_size - payload_size > 0):
-
 
108
        outf.write(struct.pack("<" + ("%d" % (aligned_size - payload_size)) + "x"))
-
 
109
       
-
 
110
    outf.seek(0)
-
 
111
    outf.write(struct.pack("<4sBBLQ", "HORD", 1, 1, header_size, aligned_size))
-
 
112
    outf.close()
-
 
113
 
89
 
-
 
90
    outf.close()
-
 
91
       
114
if __name__ == '__main__':
92
if __name__ == '__main__':
115
    main()
93
    main()