forked from mozilla-b2g/B2G
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-flash-fota.py
executable file
·86 lines (74 loc) · 3.67 KB
/
build-flash-fota.py
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
#!/usr/bin/env python
#
# Copyright (C) 2012 Mozilla Foundation
#
# 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.
#
# Build A FOTA update zip that flashes the system partition
import argparse
import os
import sys
import tempfile
import update_tools
def build_flash_fota(args):
security_dir = os.path.join(update_tools.b2g_dir, "build", "target",
"product", "security")
public_key = args.public_key or os.path.join(security_dir,
args.dev_key + ".x509.pem")
private_key = args.private_key or os.path.join(security_dir,
args.dev_key + ".pk8")
output_zip = args.output or "flash.zip"
system = update_tools.Partition.create_system(args.system_fs_type,
args.system_location)
data = update_tools.Partition.create_data(args.data_fs_type,
args.data_location)
builder = update_tools.FlashFotaBuilder(system, data)
builder.build_flash_fota(args.system_dir, public_key, private_key,
output_zip)
print "FOTA Flash ZIP generated: %s" % output_zip
def main():
parser = argparse.ArgumentParser(usage="%(prog)s [options]",
epilog="Note: java is required to be on your PATH to sign the update.zip")
system_group = parser.add_argument_group("system options")
system_group.add_argument("--system-dir", dest="system_dir",
required=True, help="path to system directory. required")
system_group.add_argument("--system-fs-type", dest="system_fs_type",
default=None, required=True, help="filesystem type for /system. required")
system_group.add_argument("--system-location", dest="system_location",
default=None, required=True, help="device location for /system. required")
data_group = parser.add_argument_group("data options")
data_group.add_argument("--data-fs-type", dest="data_fs_type",
default=None, required=True, help="filesystem type for /data. required")
data_group.add_argument("--data-location", dest="data_location",
default=None, required=True, help="device location for /data. required")
signing_group = parser.add_argument_group("signing options")
signing_group.add_argument("-d", "--dev-key", dest="dev_key",
metavar="KEYNAME", default="testkey",
help="Use the named dev key pair in build/target/product/security. " +
"Possible keys: media, platform, shared, testkey. Default: testkey")
signing_group.add_argument("-k", "--private-key", dest="private_key",
metavar="PRIVATE_KEY", default=None,
help="Private key used for signing the update.zip. Overrides --dev-key.")
signing_group.add_argument("-K", "--public-key", dest="public_key",
metavar="PUBLIC_KEY", default=None,
help="Public key used for signing the update.zip. Overrides --dev-key.")
parser.add_argument("-o", "--output", dest="output", metavar="ZIP",
help="Output to ZIP. Default: flash.zip", default=None)
update_tools.validate_env(parser)
try:
build_flash_fota(parser.parse_args())
except update_tools.UpdateException, e:
print >>sys.stderr, "Error: %s" % e
sys.exit(1)
if __name__ == "__main__":
main()