2 # SPDX-License-Identifier: GPL-2.0-only
4 # converts a depthcharge fmap.dts into an fmaptool compatible .fmd format
5 # requires fdt utilities (dtc, fdtget)
12 echo "usage: $0 dts-file"
20 # $2 start variable name
21 # $3 size variable name
23 local t
=`fdtget -t x $DTB $1 reg 2>/dev/null`
25 export $2=0x
`echo $t|cut -d' ' -f1`
26 export $3=0x
`echo $t|cut -d' ' -f2`
28 export $3=0x
`fdtget -t x $DTB $1 size`
32 dtc
-O dtb
-o $DTB $DTS
33 get_reg
/flash ROM_START ROM_SIZE
34 printf "FLASH@${ROM_START} ${ROM_SIZE} {"
39 CONTAINER_END
=$
(( ${ROM_SIZE} ))
40 CONTAINER_END_STACK
=${CONTAINER_END}
42 CONTAINER_OFFSET_STACK
=0
44 FMAP_REGIONS
=`fdtget -l $DTB /flash`
45 for region
in $FMAP_REGIONS; do
46 OLD_REGION_START
=$REGION_START
47 OLD_REGION_SIZE
=$REGION_SIZE
48 get_reg
/flash
/$region REGION_START REGION_SIZE
50 # determine if we're past an existing container
51 while [ $
(( ${REGION_START} )) -ge ${CONTAINER_END} ]; do
52 PREFIX
=`printf "${PREFIX}" | cut -c2-`
54 CONTAINER_END_STACK
=`printf "${CONTAINER_END_STACK}" | cut -d' ' -f2-`
55 CONTAINER_OFFSET_STACK
=`printf "${CONTAINER_OFFSET_STACK}" | cut -d' ' -f2-`
56 CONTAINER_END
=`printf ${CONTAINER_END_STACK} | cut -d' ' -f1`
57 CONTAINER_OFFSET
=`printf ${CONTAINER_OFFSET_STACK} | cut -d' ' -f1`
60 # determine if we're inside a new container region now
61 if [ $
(( ${OLD_REGION_START} + ${OLD_REGION_SIZE} )) -gt $(( ${REGION_START} )) ]; then
63 CONTAINER_END
=$
(( ${OLD_REGION_START} + ${OLD_REGION_SIZE} ))
64 CONTAINER_OFFSET
=$
(( ${OLD_REGION_START} ))
65 CONTAINER_END_STACK
="${CONTAINER_END} ${CONTAINER_END_STACK}"
66 CONTAINER_OFFSET_STACK
="${CONTAINER_OFFSET} ${CONTAINER_OFFSET_STACK}"
70 LOCAL_REGION_START
=$
(( ${REGION_START} - ${CONTAINER_OFFSET} ))
71 LOCAL_REGION_START
=`printf "0x%x" ${LOCAL_REGION_START}`
73 REGION_NAME
=`fdtget $DTB /flash/$region label | tr '[a-z]-' '[A-Z]_'`
74 REGION_TYPE
=`fdtget $DTB /flash/$region type 2>/dev/null | cut -d'/' -f1`
76 # a CBFS region? if so, mark as such
77 if [ "${REGION_TYPE}" = "blob cbfs" ]; then
83 # special handling: rename BOOT_STUB to COREBOOT, mark them as CBFS
84 if [ "${REGION_NAME}" = "BOOT_STUB" ]; then
85 REGION_NAME
="COREBOOT"
87 if [ "${REGION_NAME}" = "COREBOOT" ]; then
91 # also mark RW_LEGACY (seabios et al) as CBFS
92 if [ "${REGION_NAME}" = "RW_LEGACY" ]; then
96 # special handling: COREBOOT region at 0, inject a 128K bootblock
97 # The size may need changes to accommodate the chipsets,
98 # but should work for now.
99 if [ "${REGION_NAME}" = "COREBOOT" -a \
100 $
(( ${REGION_START} )) -eq 0 ]; then
101 printf "\n${PREFIX}BOOTBLOCK@0 128K"
102 LOCAL_REGION_START
=$
(( ${LOCAL_REGION_START} + 128*1024 ))
103 LOCAL_REGION_START
=`printf 0x%x ${LOCAL_REGION_START}`
104 REGION_SIZE
=$
(( ${REGION_SIZE} - 128*1024 ))
105 REGION_SIZE
=`printf 0x%x ${REGION_SIZE}`
108 printf "\n${PREFIX}${REGION_NAME}${IS_CBFS}@${LOCAL_REGION_START} ${REGION_SIZE}"
111 while [ -n "${PREFIX}" ]; do
112 PREFIX
=`printf "${PREFIX}" | cut -c2-`
113 printf "\n${PREFIX}}"