blob: 7ebc042b4007d6707a55e56481ba0f38fe2680f6 [file] [log] [blame]
David Anderson41241232018-06-13 16:50:11 -07001/*
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
David Anderson0640c672018-07-12 13:10:57 -070022#include <liblp/liblp.h>
David Anderson41241232018-06-13 16:50:11 -070023
24using namespace android;
25using namespace android::fs_mgr;
26
27/* Prints program usage to |where|. */
28static 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
38int 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
David Anderson71e763a2018-08-16 09:56:27 -070049 if (!FlashPartitionTable(argv[1], *pt.get())) {
David Anderson41241232018-06-13 16:50:11 -070050 printf("Failed to flash partition table.\n");
51 return EX_SOFTWARE;
52 }
53 printf("Successfully flashed partition table.\n");
54 return EX_OK;
55}