blob: 5068a99cbd60f687916054baeeee48366c0947db [file] [log] [blame]
Patrick Georgi5d7ab392015-12-12 00:23:15 +01001#!/bin/bash
Patrick Georgi40032832016-10-24 11:58:07 +02002#
3# Copyright 2015 Google Inc.
4#
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.
8#
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.
Patrick Georgi5d7ab392015-12-12 00:23:15 +010013# converts a depthcharge fmap.dts into an fmaptool compatible .fmd format
14# requires fdt utilities (dtc, fdtget)
15#
16# $1 dts file name
17# result on stdout
18set -e
19
20if [ $# -lt 1 ]; then
21 echo "usage: $0 dts-file"
22 exit 1
23fi
24
25DTS=$1
26DTB=`mktemp`
27
28# $1 node
29# $2 start variable name
30# $3 size variable name
31get_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`
38 fi
39}
40
41dtc -O dtb -o $DTB $DTS
42get_reg /flash ROM_START ROM_SIZE
43printf "FLASH@${ROM_START} ${ROM_SIZE} {"
44
45PREFIX="\t"
46REGION_START=-1
47REGION_SIZE=0
48CONTAINER_END=$(( ${ROM_SIZE} ))
49CONTAINER_END_STACK=${CONTAINER_END}
50CONTAINER_OFFSET=0
51CONTAINER_OFFSET_STACK=0
52
53FMAP_REGIONS=`fdtget -l $DTB /flash`
54for 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
58
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
68
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 " {"
77 fi
78
79 LOCAL_REGION_START=$(( ${REGION_START} - ${CONTAINER_OFFSET} ))
80 LOCAL_REGION_START=`printf "0x%x" ${LOCAL_REGION_START}`
81
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`
84
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=""
90 fi
91
92 # special handling: rename BOOT_STUB to COREBOOT, mark them as CBFS
93 if [ "${REGION_NAME}" = "BOOT_STUB" ]; then
94 REGION_NAME="COREBOOT"
95 fi
96 if [ "${REGION_NAME}" = "COREBOOT" ]; then
97 IS_CBFS="(CBFS)"
98 fi
99
Patrick Georgi1000a552016-03-31 15:59:41 +0200100 # also mark RW_LEGACY (seabios et al) as CBFS
101 if [ "${REGION_NAME}" = "RW_LEGACY" ]; then
102 IS_CBFS="(CBFS)"
103 fi
104
Patrick Georgi5d7ab392015-12-12 00:23:15 +0100105 # special handling: COREBOOT region at 0, inject a 128K bootblock
106 # The size may need changes to accomodate 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}`
115 fi
116
117 printf "\n${PREFIX}${REGION_NAME}${IS_CBFS}@${LOCAL_REGION_START} ${REGION_SIZE}"
118done
119
120while [ -n "${PREFIX}" ]; do
121 PREFIX=`printf "${PREFIX}" | cut -c2-`
122 printf "\n${PREFIX}}"
123done
124printf "\n"
125
126rm -f $DTB