blob: fedf7206fe12a89d027a99487223f32c8ed4df1b [file] [log] [blame]
Lukasz Majewskibabaaa62016-09-17 06:57:39 +02001#! /bin/bash
Tom Rini10e47792018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskibabaaa62016-09-17 06:57:39 +02003#
4# Copyright (C) 2016, Lukasz Majewski <l.majewski@majess.pl>
5#
Lukasz Majewskibabaaa62016-09-17 06:57:39 +02006
7# This file extracts default envs from built u-boot
Lukasz Majewskia02e9332018-02-14 11:39:48 +01008# usage: get_default_envs.sh [build dir] > u-boot-env-default.txt
Lukasz Majewskibabaaa62016-09-17 06:57:39 +02009set -ue
10
Lukasz Majewskia02e9332018-02-14 11:39:48 +010011: "${OBJCOPY:=${CROSS_COMPILE:-}objcopy}"
12
Tom Rinia5a52062021-06-21 16:14:18 -040013ENV_OBJ_FILE="common.o"
Lukasz Majewskibabaaa62016-09-17 06:57:39 +020014ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}"
15
16echoerr() { echo "$@" 1>&2; }
17
Lukasz Majewskia02e9332018-02-14 11:39:48 +010018if [ "$#" -eq 1 ]; then
19 path=${1}
20else
21 path=$(readlink -f $0)
22 path=${path%/scripts*}
23fi
24
25env_obj_file_path=$(find ${path} -path "*/env/*" -not -path "*/spl/*" \
Seung-Woo Kima13e31a2018-06-04 13:25:04 +090026 -not -path "*/tools/*" -name "${ENV_OBJ_FILE}")
Lukasz Majewskibabaaa62016-09-17 06:57:39 +020027[ -z "${env_obj_file_path}" ] && \
28 { echoerr "File '${ENV_OBJ_FILE}' not found!"; exit 1; }
29
30cp ${env_obj_file_path} ${ENV_OBJ_FILE_COPY}
31
32# NOTE: objcopy saves its output to file passed in
Lukasz Majewskia02e9332018-02-14 11:39:48 +010033# (copy_${ENV_OBJ_FILE} in this case)
34
Tom Rinia5a52062021-06-21 16:14:18 -040035${OBJCOPY} --dump-section .rodata.default_environment=${ENV_OBJ_FILE_COPY} \
36 ${env_obj_file_path}
Lukasz Majewskibabaaa62016-09-17 06:57:39 +020037
Christoph Niedermaier58990872022-02-23 10:33:36 +010038# Replace default '\0' with '\n' , remove blank lines and sort entries
39tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sed -e '/^\s*$/d' | sort --field-separator== -k1,1 --stable
Lukasz Majewskibabaaa62016-09-17 06:57:39 +020040
41rm ${ENV_OBJ_FILE_COPY}
42
43exit 0