Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 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 "updater.hpp" |
| 18 | |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 19 | #include "bt.hpp" |
| 20 | #include "interface.hpp" |
| 21 | #include "lpc.hpp" |
| 22 | |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 23 | #include <algorithm> |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 24 | #include <memory> |
| 25 | |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 26 | int updaterMain(BlobInterface* blob, const std::string& interface, |
| 27 | const std::string& imagePath, const std::string& signaturePath) |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 28 | { |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 29 | std::unique_ptr<DataInterface> handler; |
| 30 | |
| 31 | /* Input has already been validated in this case. */ |
| 32 | if (interface == "ipmibt") |
| 33 | { |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 34 | handler = std::make_unique<BtDataHandler>(blob); |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 35 | } |
| 36 | else if (interface == "ipmilpc") |
| 37 | { |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 38 | handler = std::make_unique<LpcDataHandler>(blob); |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | if (!handler) |
| 42 | { |
| 43 | /* TODO(venture): use a custom exception. */ |
| 44 | std::fprintf(stderr, "Interface %s is unavailable\n", |
| 45 | interface.c_str()); |
| 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | /* TODO(venture): Add optional parameter to specify the flash type, default |
| 50 | * to legacy for now. |
| 51 | */ |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 52 | std::string goalFirmware = "/flash/image"; |
| 53 | |
| 54 | std::vector<std::string> blobs = blob->getBlobList(); |
| 55 | |
| 56 | auto blobInst = std::find(blobs.begin(), blobs.end(), goalFirmware); |
| 57 | if (blobInst == blobs.end()) |
| 58 | { |
| 59 | std::fprintf(stderr, "firmware goal not found!\n"); |
| 60 | return -1; /* throw custom exception. */ |
| 61 | } |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 62 | |
| 63 | /* Get list of blob_ids, check for /flash/image, or /flash/tarball. |
| 64 | * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc |
| 65 | * will have in mind which they're sending and we need to verify it's |
| 66 | * available and use it. |
| 67 | */ |
| 68 | |
| 69 | /* Call stat on /flash/image (or /flash/tarball) and check if data interface |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame^] | 70 | * is supported. |
| 71 | */ |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 72 | |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 73 | return 0; |
| 74 | } |