Lukasz Majewski | 27229b2 | 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 |
Lukasz Majewski | 0778e7c | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 9 | # usage: get_default_envs.sh [build dir] > u-boot-env-default.txt |
Lukasz Majewski | 27229b2 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 10 | set -ue |
| 11 | |
Lukasz Majewski | 0778e7c | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 12 | : "${OBJCOPY:=${CROSS_COMPILE:-}objcopy}" |
| 13 | |
| 14 | ENV_OBJ_FILE="built-in.o" |
Lukasz Majewski | 27229b2 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 15 | ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}" |
| 16 | |
| 17 | echoerr() { echo "$@" 1>&2; } |
| 18 | |
Lukasz Majewski | 0778e7c | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 19 | if [ "$#" -eq 1 ]; then |
| 20 | path=${1} |
| 21 | else |
| 22 | path=$(readlink -f $0) |
| 23 | path=${path%/scripts*} |
| 24 | fi |
| 25 | |
| 26 | env_obj_file_path=$(find ${path} -path "*/env/*" -not -path "*/spl/*" \ |
Lukasz Majewski | 27229b2 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 27 | -name "${ENV_OBJ_FILE}") |
| 28 | [ -z "${env_obj_file_path}" ] && \ |
| 29 | { echoerr "File '${ENV_OBJ_FILE}' not found!"; exit 1; } |
| 30 | |
| 31 | cp ${env_obj_file_path} ${ENV_OBJ_FILE_COPY} |
| 32 | |
| 33 | # NOTE: objcopy saves its output to file passed in |
Lukasz Majewski | 0778e7c | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 34 | # (copy_${ENV_OBJ_FILE} in this case) |
| 35 | |
| 36 | ${OBJCOPY} -O binary -j ".rodata.default_environment" ${ENV_OBJ_FILE_COPY} |
Lukasz Majewski | 27229b2 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 37 | |
| 38 | # Replace default '\0' with '\n' and sort entries |
| 39 | tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sort -u |
| 40 | |
| 41 | rm ${ENV_OBJ_FILE_COPY} |
| 42 | |
| 43 | exit 0 |