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 19 #include <algorithm> 20 #include <memory> 21 22 int updaterMain(BlobInterface* blob, DataInterface* handler, 23 const std::string& imagePath, const std::string& signaturePath) 24 { 25 /* TODO(venture): Add optional parameter to specify the flash type, default 26 * to legacy for now. 27 */ 28 std::string goalFirmware = "/flash/image"; 29 30 /* Get list of blob_ids, check for /flash/image, or /flash/tarball. 31 * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc 32 * will have in mind which they're sending and we need to verify it's 33 * available and use it. 34 */ 35 std::vector<std::string> blobs = blob->getBlobList(); 36 auto blobInst = std::find(blobs.begin(), blobs.end(), goalFirmware); 37 if (blobInst == blobs.end()) 38 { 39 std::fprintf(stderr, "firmware goal not found!\n"); 40 return -1; /* throw custom exception. */ 41 } 42 43 /* Call stat on /flash/image (or /flash/tarball) and check if data interface 44 * is supported. 45 */ 46 auto stat = blob->getStat(goalFirmware); 47 if ((stat.blob_state & handler->supportedType()) == 0) 48 { 49 std::fprintf(stderr, "data interface selected not supported.\n"); 50 return -1; /* throw custom exception. */ 51 } 52 53 return 0; 54 } 55