3 # Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
5 # Sanity check for mkimage and dumpimage tools
7 # SPDX-License-Identifier: GPL-2.0+
11 # make O=sandbox sandbox_config
13 # ./test/image/test-imagetools.sh
16 SRCDIR=${BASEDIR}/boot
17 IMAGE_NAME="v1.0-test"
19 IMAGE_FIT_ITS=linux.its
20 IMAGE_FIT_ITB=linux.itb
24 DATAFILES="${DATAFILE0} ${DATAFILE1} ${DATAFILE2}"
26 MKIMAGE=${BASEDIR}/tools/mkimage
27 DUMPIMAGE=${BASEDIR}/tools/dumpimage
28 MKIMAGE_LIST=mkimage.list
29 DUMPIMAGE_LIST=dumpimage.list
31 # Remove all the files we created
36 for file in ${DATAFILES}; do
37 rm -f ${file} ${SRCDIR}/${file}
40 rm -f ${DUMPIMAGE_LIST}
46 # Check that two files are the same
49 if ! diff -u $1 $2; then
56 # Create some test files
62 for file in ${DATAFILES}; do
63 head -c $RANDOM /dev/urandom >${SRCDIR}/${file}
67 # Run a command, echoing it first
76 # Run a command, redirecting output
90 # Write files into an multi-file image
93 local files="${SRCDIR}/${DATAFILE0}:${SRCDIR}/${DATAFILE1}"
94 files+=":${SRCDIR}/${DATAFILE2}"
96 echo -e "\nBuilding multi-file image..."
97 do_cmd ${MKIMAGE} -A x86 -O linux -T multi -n \"${IMAGE_NAME}\" \
98 -d ${files} ${IMAGE_MULTI}
102 # Extract files from an multi-file image
103 extract_multi_image()
105 echo -e "\nExtracting multi-file image contents..."
106 do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 0 ${DATAFILE0}
107 do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 1 ${DATAFILE1}
108 do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2}
109 do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2} -o ${TEST_OUT}
113 # Write files into a FIT image
119 description = \"FIT image\"; \
120 #address-cells = <1>; \
124 description = \"kernel\"; \
125 data = /incbin/(\"${DATAFILE0}\"); \
127 arch = \"sandbox\"; \
129 compression = \"gzip\"; \
134 description = \"filesystem\"; \
135 data = /incbin/(\"${DATAFILE1}\"); \
136 type = \"ramdisk\"; \
137 arch = \"sandbox\"; \
139 compression = \"none\"; \
144 description = \"device tree\"; \
145 data = /incbin/(\"${DATAFILE2}\"); \
146 type = \"flat_dt\"; \
147 arch = \"sandbox\"; \
148 compression = \"none\"; \
152 default = \"conf@1\"; \
154 kernel = \"kernel@1\"; \
161 echo -e "\nBuilding FIT image..."
162 do_cmd ${MKIMAGE} -f ${IMAGE_FIT_ITS} ${IMAGE_FIT_ITB}
166 # Extract files from a FIT image
169 echo -e "\nExtracting FIT image contents..."
170 do_cmd ${DUMPIMAGE} -T flat_dt -i ${IMAGE_FIT_ITB} -p 0 ${DATAFILE0}
171 do_cmd ${DUMPIMAGE} -T flat_dt -i ${IMAGE_FIT_ITB} -p 1 ${DATAFILE1}
172 do_cmd ${DUMPIMAGE} -T flat_dt -i ${IMAGE_FIT_ITB} -p 2 ${DATAFILE2}
173 do_cmd ${DUMPIMAGE} -T flat_dt -i ${IMAGE_FIT_ITB} -p 2 ${DATAFILE2} -o ${TEST_OUT}
177 # List the contents of a file
184 echo -e "\nListing image contents..."
185 do_cmd_redir ${MKIMAGE_LIST} ${MKIMAGE} -l ${image}
186 do_cmd_redir ${DUMPIMAGE_LIST} ${DUMPIMAGE} -l ${image}
196 # Compress and extract multi-file images, compare the result
199 for file in ${DATAFILES}; do
200 assert_equal ${file} ${SRCDIR}/${file}
202 assert_equal ${TEST_OUT} ${DATAFILE2}
204 # List contents of multi-file image and compares output from tools
205 list_image ${IMAGE_MULTI}
206 assert_equal ${DUMPIMAGE_LIST} ${MKIMAGE_LIST}
208 # Compress and extract FIT images, compare the result
211 for file in ${DATAFILES}; do
212 assert_equal ${file} ${SRCDIR}/${file}
214 assert_equal ${TEST_OUT} ${DATAFILE2}
216 # List contents of FIT image and compares output from tools
217 list_image ${IMAGE_FIT_ITB}
218 assert_equal ${DUMPIMAGE_LIST} ${MKIMAGE_LIST}
220 # Remove files created