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 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_BOOT_IMG_FILESYSTEM_H_ 18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_BOOT_IMG_FILESYSTEM_H_ 19 20 #include "update_engine/payload_generator/filesystem_interface.h" 21 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 namespace chromeos_update_engine { 27 28 class BootImgFilesystem : public FilesystemInterface { 29 public: 30 // Creates an BootImgFilesystem from an Android boot.img file. 31 static std::unique_ptr<BootImgFilesystem> CreateFromFile( 32 const std::string& filename); 33 ~BootImgFilesystem() override = default; 34 35 // FilesystemInterface overrides. 36 size_t GetBlockSize() const override; 37 size_t GetBlockCount() const override; 38 39 // GetFiles will return one FilesystemInterface::File for kernel and one for 40 // ramdisk. 41 bool GetFiles(std::vector<File>* files) const override; 42 43 bool LoadSettings(brillo::KeyValueStore* store) const override; 44 45 private: 46 friend class BootImgFilesystemTest; 47 48 BootImgFilesystem() = default; 49 50 File GetFile(const std::string& name, uint64_t offset, uint64_t size) const; 51 52 // The boot.img file path. 53 std::string filename_; 54 55 // https://android.googlesource.com/platform/system/core/+/master/mkbootimg/include/bootimg/bootimg.h 56 #define BOOT_MAGIC "ANDROID!" 57 #define BOOT_MAGIC_SIZE 8 58 struct boot_img_hdr { 59 // Must be BOOT_MAGIC. 60 uint8_t magic[BOOT_MAGIC_SIZE]; 61 uint32_t kernel_size; /* size in bytes */ 62 uint32_t kernel_addr; /* physical load addr */ 63 uint32_t ramdisk_size; /* size in bytes */ 64 uint32_t ramdisk_addr; /* physical load addr */ 65 uint32_t second_size; /* size in bytes */ 66 uint32_t second_addr; /* physical load addr */ 67 uint32_t tags_addr; /* physical addr for kernel tags */ 68 uint32_t page_size; /* flash page size we assume */ 69 } __attribute__((packed)); 70 // The boot image header. 71 boot_img_hdr hdr_; 72 73 DISALLOW_COPY_AND_ASSIGN(BootImgFilesystem); 74 }; 75 76 } // namespace chromeos_update_engine 77 78 #endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_BOOT_IMG_FILESYSTEM_H_ 79