1bf58cd64SPatrick Venture /*
2bf58cd64SPatrick Venture  * Copyright 2018 Google Inc.
3bf58cd64SPatrick Venture  *
4bf58cd64SPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5bf58cd64SPatrick Venture  * you may not use this file except in compliance with the License.
6bf58cd64SPatrick Venture  * You may obtain a copy of the License at
7bf58cd64SPatrick Venture  *
8bf58cd64SPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9bf58cd64SPatrick Venture  *
10bf58cd64SPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11bf58cd64SPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12bf58cd64SPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bf58cd64SPatrick Venture  * See the License for the specific language governing permissions and
14bf58cd64SPatrick Venture  * limitations under the License.
15bf58cd64SPatrick Venture  */
16bf58cd64SPatrick Venture 
17bf58cd64SPatrick Venture #include "updater.hpp"
18bf58cd64SPatrick Venture 
1900887597SPatrick Venture #include <algorithm>
20af69625fSPatrick Venture #include <memory>
21af69625fSPatrick Venture 
22a658636fSPatrick Venture int updaterMain(BlobInterface* blob, DataInterface* handler,
2300887597SPatrick Venture                 const std::string& imagePath, const std::string& signaturePath)
24bf58cd64SPatrick Venture {
25af69625fSPatrick Venture     /* TODO(venture): Add optional parameter to specify the flash type, default
26af69625fSPatrick Venture      * to legacy for now.
27af69625fSPatrick Venture      */
2800887597SPatrick Venture     std::string goalFirmware = "/flash/image";
2900887597SPatrick Venture 
30*0bf8bf0cSPatrick Venture     /* Get list of blob_ids, check for /flash/image, or /flash/tarball.
31*0bf8bf0cSPatrick Venture      * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc
32*0bf8bf0cSPatrick Venture      * will have in mind which they're sending and we need to verify it's
33*0bf8bf0cSPatrick Venture      * available and use it.
34*0bf8bf0cSPatrick Venture      */
3500887597SPatrick Venture     std::vector<std::string> blobs = blob->getBlobList();
3600887597SPatrick Venture     auto blobInst = std::find(blobs.begin(), blobs.end(), goalFirmware);
3700887597SPatrick Venture     if (blobInst == blobs.end())
3800887597SPatrick Venture     {
3900887597SPatrick Venture         std::fprintf(stderr, "firmware goal not found!\n");
4000887597SPatrick Venture         return -1; /* throw custom exception. */
4100887597SPatrick Venture     }
42af69625fSPatrick Venture 
43af69625fSPatrick Venture     /* Call stat on /flash/image (or /flash/tarball) and check if data interface
4400887597SPatrick Venture      * is supported.
4500887597SPatrick Venture      */
46*0bf8bf0cSPatrick Venture     auto stat = blob->getStat(goalFirmware);
47af69625fSPatrick Venture 
48bf58cd64SPatrick Venture     return 0;
49bf58cd64SPatrick Venture }
50