boot_control_android.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (C) 2015 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_BOOT_CONTROL_ANDROID_H_
  17. #define UPDATE_ENGINE_BOOT_CONTROL_ANDROID_H_
  18. #include <map>
  19. #include <memory>
  20. #include <string>
  21. #include <android/hardware/boot/1.0/IBootControl.h>
  22. #include <base/files/file_util.h>
  23. #include <liblp/builder.h>
  24. #include "update_engine/common/boot_control.h"
  25. #include "update_engine/dynamic_partition_control_interface.h"
  26. namespace chromeos_update_engine {
  27. // The Android implementation of the BootControlInterface. This implementation
  28. // uses the libhardware's boot_control HAL to access the bootloader.
  29. class BootControlAndroid : public BootControlInterface {
  30. public:
  31. BootControlAndroid() = default;
  32. ~BootControlAndroid() = default;
  33. // Load boot_control HAL implementation using libhardware and
  34. // initializes it. Returns false if an error occurred.
  35. bool Init();
  36. // BootControlInterface overrides.
  37. unsigned int GetNumSlots() const override;
  38. BootControlInterface::Slot GetCurrentSlot() const override;
  39. bool GetPartitionDevice(const std::string& partition_name,
  40. BootControlInterface::Slot slot,
  41. std::string* device) const override;
  42. bool IsSlotBootable(BootControlInterface::Slot slot) const override;
  43. bool MarkSlotUnbootable(BootControlInterface::Slot slot) override;
  44. bool SetActiveBootSlot(BootControlInterface::Slot slot) override;
  45. bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override;
  46. bool InitPartitionMetadata(Slot slot,
  47. const PartitionMetadata& partition_metadata,
  48. bool update_metadata) override;
  49. void Cleanup() override;
  50. private:
  51. ::android::sp<::android::hardware::boot::V1_0::IBootControl> module_;
  52. std::unique_ptr<DynamicPartitionControlInterface> dynamic_control_;
  53. friend class BootControlAndroidTest;
  54. // Wrapper method of IBootControl::getSuffix().
  55. bool GetSuffix(Slot slot, std::string* out) const;
  56. enum class DynamicPartitionDeviceStatus {
  57. SUCCESS,
  58. ERROR,
  59. TRY_STATIC,
  60. };
  61. DynamicPartitionDeviceStatus GetDynamicPartitionDevice(
  62. const base::FilePath& device_dir,
  63. const std::string& partition_name_suffix,
  64. Slot slot,
  65. std::string* device) const;
  66. // Return true if |partition_name_suffix| is a block device of
  67. // super partition metadata slot |slot|.
  68. bool IsSuperBlockDevice(const base::FilePath& device_dir,
  69. Slot slot,
  70. const std::string& partition_name_suffix) const;
  71. // Whether the target partitions should be loaded as dynamic partitions. Set
  72. // by InitPartitionMetadata() per each update.
  73. bool is_target_dynamic_{false};
  74. DISALLOW_COPY_AND_ASSIGN(BootControlAndroid);
  75. };
  76. } // namespace chromeos_update_engine
  77. #endif // UPDATE_ENGINE_BOOT_CONTROL_ANDROID_H_