cpu/x86/mtrr: Replace CONFIG_CPU_ADDR_BITS with cpu_phys_address_size()
[coreboot.git] / util / scripts / dts-to-fmd.sh
blobb468b35bcd7f0f76e423f36ec2c41b40a9b5f3c8
1 #!/usr/bin/env bash
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)
16 # $1 dts file name
17 # result on stdout
18 set -e
20 if [ $# -lt 1 ]; then
21 echo "usage: $0 dts-file"
22 exit 1
25 DTS=$1
26 DTB=`mktemp`
28 # $1 node
29 # $2 start variable name
30 # $3 size variable name
31 get_reg() {
32 local t=`fdtget -t x $DTB $1 reg 2>/dev/null`
33 if [ -n "$t" ]; then
34 export $2=0x`echo $t|cut -d' ' -f1`
35 export $3=0x`echo $t|cut -d' ' -f2`
36 else
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} {"
45 PREFIX="\t"
46 REGION_START=-1
47 REGION_SIZE=0
48 CONTAINER_END=$(( ${ROM_SIZE} ))
49 CONTAINER_END_STACK=${CONTAINER_END}
50 CONTAINER_OFFSET=0
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-`
62 printf "\n${PREFIX}}"
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`
67 done
69 # determine if we're inside a new container region now
70 if [ $(( ${OLD_REGION_START} + ${OLD_REGION_SIZE} )) -gt $(( ${REGION_START} )) ]; then
71 PREFIX="\t${PREFIX}"
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}"
76 printf " {"
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
87 IS_CBFS="(CBFS)"
88 else
89 IS_CBFS=""
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
97 IS_CBFS="(CBFS)"
100 # also mark RW_LEGACY (seabios et al) as CBFS
101 if [ "${REGION_NAME}" = "RW_LEGACY" ]; then
102 IS_CBFS="(CBFS)"
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}"
118 done
120 while [ -n "${PREFIX}" ]; do
121 PREFIX=`printf "${PREFIX}" | cut -c2-`
122 printf "\n${PREFIX}}"
123 done
124 printf "\n"
126 rm -f $DTB