1 // Copyright 2024 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 
15 //! CLI for converting file system to FDT
16 
17 use clap::Parser;
18 use fsfdt::FsFdt;
19 use libfdt::Fdt;
20 use std::fs;
21 use std::path::PathBuf;
22 
23 const FDT_MAX_SIZE: usize = 1_000_000_usize;
24 
25 /// Option parser
26 #[derive(Parser, Debug)]
27 struct Opt {
28     /// File system path (directory path) to parse from
29     fs_path: PathBuf,
30 
31     /// FDT file path for writing
32     fdt_file_path: PathBuf,
33 }
34 
main()35 fn main() {
36     let opt = Opt::parse();
37 
38     let mut data = vec![0_u8; FDT_MAX_SIZE];
39     let fdt = Fdt::from_fs(&opt.fs_path, &mut data).unwrap();
40     fdt.pack().unwrap();
41     fs::write(&opt.fdt_file_path, fdt.as_slice()).unwrap();
42 }
43