boot_img_filesystem.h 2.6 KB

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