blob: 2fe71e76ce0b6240eedaa9c84d25590484185a01 [file] [log] [blame]
Jaewan Kim9cf731b2024-01-19 14:45:45 +09001// 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
17use clap::Parser;
18use fsfdt::FsFdt;
19use libfdt::Fdt;
20use std::fs;
21use std::path::PathBuf;
22
23const FDT_MAX_SIZE: usize = 1_000_000_usize;
24
25/// Option parser
26#[derive(Parser, Debug)]
27struct 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
35fn 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}