Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 1 | /* |
Patrick Venture | 514f648 | 2018-08-07 14:27:58 -0700 | [diff] [blame^] | 2 | * Copyright 2018 Google Inc. |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 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 "flash-ipmi.hpp" |
| 18 | |
Patrick Venture | 8ec019f | 2018-08-07 11:22:33 -0700 | [diff] [blame] | 19 | #include <cstdio> |
| 20 | #include <phosphor-logging/log.hpp> |
| 21 | |
| 22 | using namespace phosphor::logging; |
| 23 | |
| 24 | namespace |
| 25 | { |
| 26 | |
| 27 | /** |
| 28 | * Close a file pointer and set to null. |
| 29 | * |
| 30 | * @param[in] fd a pointer to your file handle. |
| 31 | */ |
| 32 | void closeFile(std::FILE** fd) |
| 33 | { |
| 34 | if (!fd) |
| 35 | { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | if (*fd) |
| 40 | { |
| 41 | std::fclose(*fd); |
| 42 | (*fd) = nullptr; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void FlashUpdate::closeEverything() |
| 48 | { |
| 49 | closeFile(&flashFd); |
| 50 | } |
| 51 | |
| 52 | FlashUpdate::~FlashUpdate() |
| 53 | { |
| 54 | /* Close without deleting. This object can only be destroyed if the ipmi |
| 55 | * daemon unloads it, by closing down. In this event, we want the verified |
| 56 | * file to live on. |
| 57 | */ |
| 58 | closeEverything(); |
| 59 | } |
| 60 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 61 | void FlashUpdate::abortEverything() |
| 62 | { |
Patrick Venture | 8ec019f | 2018-08-07 11:22:33 -0700 | [diff] [blame] | 63 | closeEverything(); |
| 64 | |
| 65 | /* TODO: And now delete everything */ |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 66 | return; |
| 67 | } |
| 68 | |
| 69 | bool FlashUpdate::openEverything() |
| 70 | { |
Patrick Venture | 8ec019f | 2018-08-07 11:22:33 -0700 | [diff] [blame] | 71 | flashFd = std::fopen(tmpPath.c_str(), "w"); |
| 72 | if (flashFd == nullptr) |
| 73 | { |
| 74 | log<level::INFO>("Unable to open staging path", |
| 75 | entry("PATH=%s", tmpPath.c_str())); |
| 76 | return false; |
| 77 | } |
| 78 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 79 | return true; |
| 80 | } |
| 81 | |
| 82 | /* Prepare to receive a BMC image and then a signature. */ |
Patrick Venture | 8ec019f | 2018-08-07 11:22:33 -0700 | [diff] [blame] | 83 | bool FlashUpdate::start(uint32_t length) |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 84 | { |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 85 | /* Close out and delete everything. */ |
| 86 | abortEverything(); |
| 87 | |
Patrick Venture | 8ec019f | 2018-08-07 11:22:33 -0700 | [diff] [blame] | 88 | /* TODO: Validate request->length */ |
| 89 | flashLength = length; |
| 90 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame] | 91 | /* Start over! */ |
| 92 | return openEverything(); |
| 93 | } |
Patrick Venture | 79e131f | 2018-08-01 13:34:35 -0700 | [diff] [blame] | 94 | |
| 95 | bool FlashUpdate::flashData(uint32_t offset, const std::vector<uint8_t>& bytes) |
| 96 | { |
| 97 | /* TODO: implement. */ |
| 98 | return false; |
| 99 | } |
Patrick Venture | 2c1205d | 2018-08-03 10:23:14 -0700 | [diff] [blame] | 100 | |
| 101 | bool FlashUpdate::flashFinish() |
| 102 | { |
| 103 | /* TODO: implement. */ |
| 104 | return false; |
| 105 | } |
Patrick Venture | 8d9f732 | 2018-08-03 10:39:13 -0700 | [diff] [blame] | 106 | |
| 107 | bool FlashUpdate::startHash(uint32_t length) |
| 108 | { |
| 109 | /* TODO: implement. */ |
| 110 | return false; |
| 111 | } |
Patrick Venture | cfe6687 | 2018-08-03 13:32:33 -0700 | [diff] [blame] | 112 | |
| 113 | bool FlashUpdate::hashData(uint32_t offset, const std::vector<uint8_t>& bytes) |
| 114 | { |
| 115 | /* TODO: implement. */ |
| 116 | return false; |
| 117 | } |
Patrick Venture | fbc7d19 | 2018-08-03 13:54:21 -0700 | [diff] [blame] | 118 | |
| 119 | bool FlashUpdate::hashFinish() |
| 120 | { |
| 121 | /* TODO: implement. */ |
| 122 | return false; |
| 123 | } |
Patrick Venture | 1cb87d2 | 2018-08-03 18:22:09 -0700 | [diff] [blame] | 124 | |
| 125 | bool FlashUpdate::startDataVerification() |
| 126 | { |
| 127 | /* TODO: implement. */ |
| 128 | return false; |
| 129 | } |
Patrick Venture | 5c251ca | 2018-08-03 18:31:01 -0700 | [diff] [blame] | 130 | |
| 131 | bool FlashUpdate::abortUpdate() |
| 132 | { |
| 133 | /* TODO: implement. */ |
| 134 | return false; |
| 135 | } |