Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2016, Lukasz Majewski <l.majewski@majess.pl> |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0+ |
| 6 | # |
| 7 | |
| 8 | # This file extracts default envs from built u-boot |
| 9 | # usage: get_default_envs.sh > u-boot-env-default.txt |
| 10 | set -ue |
| 11 | |
| 12 | ENV_OBJ_FILE="env_common.o" |
| 13 | ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}" |
| 14 | |
| 15 | echoerr() { echo "$@" 1>&2; } |
| 16 | |
| 17 | path=$(readlink -f $0) |
| 18 | env_obj_file_path=$(find ${path%/scripts*} -not -path "*/spl/*" \ |
| 19 | -name "${ENV_OBJ_FILE}") |
| 20 | [ -z "${env_obj_file_path}" ] && \ |
| 21 | { echoerr "File '${ENV_OBJ_FILE}' not found!"; exit 1; } |
| 22 | |
| 23 | cp ${env_obj_file_path} ${ENV_OBJ_FILE_COPY} |
| 24 | |
| 25 | # NOTE: objcopy saves its output to file passed in |
| 26 | # (copy_env_common.o in this case) |
| 27 | objcopy -O binary -j ".rodata.default_environment" ${ENV_OBJ_FILE_COPY} |
| 28 | |
| 29 | # Replace default '\0' with '\n' and sort entries |
| 30 | tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sort -u |
| 31 | |
| 32 | rm ${ENV_OBJ_FILE_COPY} |
| 33 | |
| 34 | exit 0 |