blob: 287265331281469f45f3dca3f0c407482c4cd968 [file] [log] [blame]
Lukasz Majewski27229b22016-09-17 06:57:39 +02001#! /bin/bash
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski27229b22016-09-17 06:57:39 +02003#
4# Copyright (C) 2016, Lukasz Majewski <l.majewski@majess.pl>
5#
Lukasz Majewski27229b22016-09-17 06:57:39 +02006
7# This file extracts default envs from built u-boot
Lukasz Majewski0778e7c2018-02-14 11:39:48 +01008# usage: get_default_envs.sh [build dir] > u-boot-env-default.txt
Lukasz Majewski27229b22016-09-17 06:57:39 +02009set -ue
10
Lukasz Majewski0778e7c2018-02-14 11:39:48 +010011: "${OBJCOPY:=${CROSS_COMPILE:-}objcopy}"
12
13ENV_OBJ_FILE="built-in.o"
Lukasz Majewski27229b22016-09-17 06:57:39 +020014ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}"
15
16echoerr() { echo "$@" 1>&2; }
17
Lukasz Majewski0778e7c2018-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/*" \
Lukasz Majewski27229b22016-09-17 06:57:39 +020026 -name "${ENV_OBJ_FILE}")
27[ -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 Majewski0778e7c2018-02-14 11:39:48 +010033# (copy_${ENV_OBJ_FILE} in this case)
34
35${OBJCOPY} -O binary -j ".rodata.default_environment" ${ENV_OBJ_FILE_COPY}
Lukasz Majewski27229b22016-09-17 06:57:39 +020036
37# Replace default '\0' with '\n' and sort entries
38tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sort -u
39
40rm ${ENV_OBJ_FILE_COPY}
41
42exit 0