3 # Copyright 2015 Google Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 # converts a depthcharge fmap.dts into an fmaptool compatible .fmd format
14 # requires fdt utilities (dtc, fdtget)
21 echo "usage: $0 dts-file"
29 # $2 start variable name
30 # $3 size variable name
32 local t
=`fdtget -t x $DTB $1 reg 2>/dev/null`
34 export $2=0x
`echo $t|cut -d' ' -f1`
35 export $3=0x
`echo $t|cut -d' ' -f2`
37 export $3=0x
`fdtget -t x $DTB $1 size`
41 dtc
-O dtb
-o $DTB $DTS
42 get_reg
/flash ROM_START ROM_SIZE
43 printf "FLASH@${ROM_START} ${ROM_SIZE} {"
48 CONTAINER_END
=$
(( ${ROM_SIZE} ))
49 CONTAINER_END_STACK
=${CONTAINER_END}
51 CONTAINER_OFFSET_STACK
=0
53 FMAP_REGIONS
=`fdtget -l $DTB /flash`
54 for region
in $FMAP_REGIONS; do
55 OLD_REGION_START
=$REGION_START
56 OLD_REGION_SIZE
=$REGION_SIZE
57 get_reg
/flash
/$region REGION_START REGION_SIZE
59 # determine if we're past an existing container
60 while [ $
(( ${REGION_START} )) -ge ${CONTAINER_END} ]; do
61 PREFIX
=`printf "${PREFIX}" | cut -c2-`
63 CONTAINER_END_STACK
=`printf "${CONTAINER_END_STACK}" | cut -d' ' -f2-`
64 CONTAINER_OFFSET_STACK
=`printf "${CONTAINER_OFFSET_STACK}" | cut -d' ' -f2-`
65 CONTAINER_END
=`printf ${CONTAINER_END_STACK} | cut -d' ' -f1`
66 CONTAINER_OFFSET
=`printf ${CONTAINER_OFFSET_STACK} | cut -d' ' -f1`
69 # determine if we're inside a new container region now
70 if [ $
(( ${OLD_REGION_START} + ${OLD_REGION_SIZE} )) -gt $(( ${REGION_START} )) ]; then
72 CONTAINER_END
=$
(( ${OLD_REGION_START} + ${OLD_REGION_SIZE} ))
73 CONTAINER_OFFSET
=$
(( ${OLD_REGION_START} ))
74 CONTAINER_END_STACK
="${CONTAINER_END} ${CONTAINER_END_STACK}"
75 CONTAINER_OFFSET_STACK
="${CONTAINER_OFFSET} ${CONTAINER_OFFSET_STACK}"
79 LOCAL_REGION_START
=$
(( ${REGION_START} - ${CONTAINER_OFFSET} ))
80 LOCAL_REGION_START
=`printf "0x%x" ${LOCAL_REGION_START}`
82 REGION_NAME
=`fdtget $DTB /flash/$region label | tr '[a-z]-' '[A-Z]_'`
83 REGION_TYPE
=`fdtget $DTB /flash/$region type 2>/dev/null | cut -d'/' -f1`
85 # a CBFS region? if so, mark as such
86 if [ "${REGION_TYPE}" = "blob cbfs" ]; then
92 # special handling: rename BOOT_STUB to COREBOOT, mark them as CBFS
93 if [ "${REGION_NAME}" = "BOOT_STUB" ]; then
94 REGION_NAME
="COREBOOT"
96 if [ "${REGION_NAME}" = "COREBOOT" ]; then
100 # also mark RW_LEGACY (seabios et al) as CBFS
101 if [ "${REGION_NAME}" = "RW_LEGACY" ]; then
105 # special handling: COREBOOT region at 0, inject a 128K bootblock
106 # The size may need changes to accommodate the chipsets,
107 # but should work for now.
108 if [ "${REGION_NAME}" = "COREBOOT" -a \
109 $
(( ${REGION_START} )) -eq 0 ]; then
110 printf "\n${PREFIX}BOOTBLOCK@0 128K"
111 LOCAL_REGION_START
=$
(( ${LOCAL_REGION_START} + 128*1024 ))
112 LOCAL_REGION_START
=`printf 0x%x ${LOCAL_REGION_START}`
113 REGION_SIZE
=$
(( ${REGION_SIZE} - 128*1024 ))
114 REGION_SIZE
=`printf 0x%x ${REGION_SIZE}`
117 printf "\n${PREFIX}${REGION_NAME}${IS_CBFS}@${LOCAL_REGION_START} ${REGION_SIZE}"
120 while [ -n "${PREFIX}" ]; do
121 PREFIX
=`printf "${PREFIX}" | cut -c2-`
122 printf "\n${PREFIX}}"