]>
Commit | Line | Data |
---|---|---|
27229b2a | 1 | #! /bin/bash |
83d290c5 | 2 | # SPDX-License-Identifier: GPL-2.0+ |
27229b2a LM |
3 | # |
4 | # Copyright (C) 2016, Lukasz Majewski <[email protected]> | |
5 | # | |
27229b2a LM |
6 | |
7 | # This file extracts default envs from built u-boot | |
0778e7c5 | 8 | # usage: get_default_envs.sh [build dir] > u-boot-env-default.txt |
27229b2a LM |
9 | set -ue |
10 | ||
0778e7c5 LM |
11 | : "${OBJCOPY:=${CROSS_COMPILE:-}objcopy}" |
12 | ||
963fde31 | 13 | ENV_OBJ_FILE="common.o" |
27229b2a LM |
14 | ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}" |
15 | ||
16 | echoerr() { echo "$@" 1>&2; } | |
17 | ||
0778e7c5 LM |
18 | if [ "$#" -eq 1 ]; then |
19 | path=${1} | |
20 | else | |
21 | path=$(readlink -f $0) | |
22 | path=${path%/scripts*} | |
23 | fi | |
24 | ||
25 | env_obj_file_path=$(find ${path} -path "*/env/*" -not -path "*/spl/*" \ | |
e94b93d5 | 26 | -not -path "*/tools/*" -name "${ENV_OBJ_FILE}") |
27229b2a LM |
27 | [ -z "${env_obj_file_path}" ] && \ |
28 | { echoerr "File '${ENV_OBJ_FILE}' not found!"; exit 1; } | |
29 | ||
30 | cp ${env_obj_file_path} ${ENV_OBJ_FILE_COPY} | |
31 | ||
32 | # NOTE: objcopy saves its output to file passed in | |
0778e7c5 LM |
33 | # (copy_${ENV_OBJ_FILE} in this case) |
34 | ||
963fde31 TR |
35 | ${OBJCOPY} --dump-section .rodata.default_environment=${ENV_OBJ_FILE_COPY} \ |
36 | ${env_obj_file_path} | |
27229b2a | 37 | |
7d79cba2 CN |
38 | # Replace default '\0' with '\n' , remove blank lines and sort entries |
39 | tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sed -e '/^\s*$/d' | sort --field-separator== -k1,1 --stable | |
27229b2a LM |
40 | |
41 | rm ${ENV_OBJ_FILE_COPY} | |
42 | ||
43 | exit 0 |