-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakedtb
More file actions
executable file
·93 lines (81 loc) · 2.01 KB
/
Copy pathmakedtb
File metadata and controls
executable file
·93 lines (81 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Fixed output directory
OUTPUT_DIR="output"
# Function to create the output directory if it doesn't exist
create_output_directory() {
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi
}
# Display help menu
display_help() {
echo "Usage: $0 --input input_filename.dts --output output_format(dtb, dts, or dtbo)"
echo "Options:"
echo " -i, --input Input DTS file"
echo " -o, --output Output format (dtb, dts, or dtbo)"
echo " -h, --help Display this help menu"
exit 1
}
# Initialize variables
INPUT_FILE=""
OUTPUT_FORMAT="dtb"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-i | --input )
INPUT_FILE=$2
shift 2
;;
-o | --output )
OUTPUT_FORMAT=$2
shift 2
;;
-h | --help )
display_help
;;
* )
display_help
;;
esac
done
# Check if input file and output format are provided
if [ -z "$INPUT_FILE" ] || [ -z "$OUTPUT_FORMAT" ]; then
echo "Error: Please provide both input file and output format."
display_help
fi
# Check if output format is valid
case $OUTPUT_FORMAT in
dtb | dtbo | dts )
;;
* )
echo "Error: Invalid output format. Please specify 'dtb', 'dts', or 'dtbo'."
display_help
;;
esac
# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: Input file '$INPUT_FILE' not found."
exit 1
fi
# Create or clear the output directory
create_output_directory
# Determine output file name based on output format
case $OUTPUT_FORMAT in
dtb )
OUTPUT_EXTENSION=".dtb"
;;
dtbo )
OUTPUT_EXTENSION=".dtbo"
;;
dts )
OUTPUT_EXTENSION=".dts"
;;
esac
# Remove extension from input file name
OUTPUT_FILE="${INPUT_FILE%.dts}$OUTPUT_EXTENSION"
# Preprocess DTS file with arm-none-eabi-cpp and pipe the output to dtc to generate DTB or DTBO file
if [ "$OUTPUT_FORMAT" = "dts" ]; then
arm-none-eabi-cpp -nostdinc -I include -undef -x assembler-with-cpp "$INPUT_FILE" "$OUTPUT_DIR/$OUTPUT_FILE"
else
arm-none-eabi-cpp -nostdinc -I include -undef -x assembler-with-cpp "$INPUT_FILE" | dtc -O dtb -o "$OUTPUT_DIR/$OUTPUT_FILE" -@
fi