| David Anderson | 4124123 | 2018-06-13 16:50:11 -0700 | [diff] [blame] | 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/reader.h> |
| 23 | #include <liblp/writer.h> |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace android::fs_mgr; |
| 27 | |
| 28 | /* Prints program usage to |where|. */ |
| 29 | static int usage(int /* argc */, char* argv[]) { |
| 30 | fprintf(stderr, |
| 31 | "%s - command-line tool for dumping Android Logical Partition images.\n" |
| 32 | "\n" |
| 33 | "Usage:\n" |
| 34 | " %s [block-device] [img-file]\n", |
| 35 | argv[0], argv[0]); |
| 36 | return EX_USAGE; |
| 37 | } |
| 38 | |
| 39 | int main(int argc, char* argv[]) { |
| 40 | if (argc != 3) { |
| 41 | return usage(argc, argv); |
| 42 | } |
| 43 | |
| 44 | std::unique_ptr<LpMetadata> pt = ReadFromImageFile(argv[2]); |
| 45 | if (!pt) { |
| 46 | printf("Failed to read image file.\n"); |
| 47 | return EX_NOINPUT; |
| 48 | } |
| 49 | |
| 50 | if (!WritePartitionTable(argv[1], *pt.get(), SyncMode::Flash, 0)) { |
| 51 | printf("Failed to flash partition table.\n"); |
| 52 | return EX_SOFTWARE; |
| 53 | } |
| 54 | printf("Successfully flashed partition table.\n"); |
| 55 | return EX_OK; |
| 56 | } |