1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <sysexits.h>
19
20 #include <string>
21
22 #include <liblp/liblp.h>
23
24 using namespace android;
25 using namespace android::fs_mgr;
26
27 /* Prints program usage to |where|. */
usage(int,char * argv[])28 static int usage(int /* argc */, char* argv[]) {
29 fprintf(stderr,
30 "%s - command-line tool for dumping Android Logical Partition images.\n"
31 "\n"
32 "Usage:\n"
33 " %s [block-device] [img-file]\n",
34 argv[0], argv[0]);
35 return EX_USAGE;
36 }
37
main(int argc,char * argv[])38 int main(int argc, char* argv[]) {
39 if (argc != 3) {
40 return usage(argc, argv);
41 }
42
43 std::unique_ptr<LpMetadata> pt = ReadFromImageFile(argv[2]);
44 if (!pt) {
45 printf("Failed to read image file.\n");
46 return EX_NOINPUT;
47 }
48
49 if (!FlashPartitionTable(argv[1], *pt.get())) {
50 printf("Failed to flash partition table.\n");
51 return EX_SOFTWARE;
52 }
53 printf("Successfully flashed partition table.\n");
54 return EX_OK;
55 }
56