blob: 432a134ee5a0c12a4e4964133658f2b416786f5e [file] [log] [blame]
Jooyung Han74573482021-06-08 17:10:21 +09001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jooyung Han14e5a8e2021-07-06 20:48:38 +090015//! Payload metadata from /dev/block/by-name/payload-metadata
Jooyung Han74573482021-06-08 17:10:21 +090016
Jooyung Hane706c9f2021-07-29 17:21:20 +090017use crate::ioutil;
18
Jooyung Han14e5a8e2021-07-06 20:48:38 +090019use anyhow::Result;
Jooyung Han74573482021-06-08 17:10:21 +090020use log::info;
Jooyung Hanf1e00862021-06-25 12:02:33 +090021use microdroid_metadata::{read_metadata, Metadata};
Jooyung Hane706c9f2021-07-29 17:21:20 +090022use std::time::Duration;
Jooyung Han74573482021-06-08 17:10:21 +090023
Jooyung Hane706c9f2021-07-29 17:21:20 +090024const WAIT_TIMEOUT: Duration = Duration::from_secs(10);
Jooyung Han14e5a8e2021-07-06 20:48:38 +090025const PAYLOAD_METADATA_PATH: &str = "/dev/block/by-name/payload-metadata";
Jooyung Han74573482021-06-08 17:10:21 +090026
Jooyung Han14e5a8e2021-07-06 20:48:38 +090027/// loads payload metadata from /dev/block/by-name/paylaod-metadata
28pub fn load() -> Result<Metadata> {
Jooyung Han74573482021-06-08 17:10:21 +090029 info!("loading payload metadata...");
Jooyung Hane706c9f2021-07-29 17:21:20 +090030 let file = ioutil::wait_for_file(PAYLOAD_METADATA_PATH, WAIT_TIMEOUT)?;
31 read_metadata(file)
Jooyung Han74573482021-06-08 17:10:21 +090032}