forked from projectceladon/device-intel-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootloader_from_zip
executable file
·114 lines (98 loc) · 3.51 KB
/
bootloader_from_zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Generates a VFAT EFI System partition image from a provided
zip file containing its contents relative to the root directory
-i, --size Size of partition in bytes (required)
-s, --block-size Block size in bytes
-z, --zipfile Source zipfile containing root contents (required)
-b, --fastboot Path to Fastboot boot image
-B, --bootimage Path to additonal boot images, can call multiple times
-u, --bootable Flag indicating this is bootable USB image,
creates sentinel file for loader
"""
import sys
import tempfile
import zipfile
import os
import shutil
if sys.hexversion < 0x02040000:
print >> sys.stderr, "Python 2.4 or newer is required."
sys.exit(1)
# Android Release Tools
sys.path.append("build/tools/releasetools")
import common
sys.path.append("device/intel/build/releasetools")
import intel_common
OPTIONS = common.OPTIONS
OPTIONS.bootable = False
OPTIONS.zipfile = None
OPTIONS.bootimage = []
OPTIONS.size = 0;
OPTIONS.block_size = None;
OPTIONS.extra_size = 0;
def main(argv):
def option_handler(o, a):
if o in ("-i", "--size"):
OPTIONS.size = int(a)
elif o in ("-s", "--block-size"):
OPTIONS.block_size = int(a)
elif o in ("-z", "--zipfile"):
OPTIONS.zipfile = a
elif o in ("-b", "--fastboot"):
OPTIONS.bootimage.append((a, "fastboot.img"))
elif o in ("-B", "--bootimage"):
OPTIONS.bootimage.append((a, os.path.basename(a)))
elif o in ("-u", "--bootable"):
OPTIONS.bootable = True
elif o in ("-e", "--extra-size"):
OPTIONS.extra_size = int(a)
else:
return False
return True
args = common.ParseOptions(argv, __doc__,
extra_opts="i:s:z:b:B:ue:",
extra_long_opts=["size=", "block-size=", "zipfile=", "bootimage=", "fastboot=",
"bootable", "extra-size="],
extra_option_handler=option_handler)
if len(args) != 1:
common.Usage(__doc__)
sys.exit(1)
if not OPTIONS.zipfile:
print "--zipfile is required"
common.Usage(__doc__)
sys.exit(1)
tf = tempfile.NamedTemporaryFile()
tf.write("foo")
tf.flush()
extra_files = OPTIONS.bootimage
if OPTIONS.bootable:
extra_files.append((tf.name, "force_fastboot"))
intel_common.MakeVFATFilesystem(OPTIONS.zipfile, args[0], size=OPTIONS.size,
block_size=OPTIONS.block_size,
extra_files=extra_files,
extra_size=OPTIONS.extra_size)
tf.close()
common.Cleanup()
if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except common.ExternalError, e:
print
print " ERROR: %s" % (e,)
print
sys.exit(1)