Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 1 | #! /bin/bash |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 3 | # |
| 4 | # Copyright (C) 2016, Lukasz Majewski <l.majewski@majess.pl> |
| 5 | # |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 6 | |
| 7 | # This file extracts default envs from built u-boot |
Lukasz Majewski | a02e933 | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 8 | # usage: get_default_envs.sh [build dir] > u-boot-env-default.txt |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 9 | set -ue |
| 10 | |
Lukasz Majewski | a02e933 | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 11 | : "${OBJCOPY:=${CROSS_COMPILE:-}objcopy}" |
| 12 | |
Tom Rini | a5a5206 | 2021-06-21 16:14:18 -0400 | [diff] [blame] | 13 | ENV_OBJ_FILE="common.o" |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 14 | ENV_OBJ_FILE_COPY="copy_${ENV_OBJ_FILE}" |
| 15 | |
| 16 | echoerr() { echo "$@" 1>&2; } |
| 17 | |
Lukasz Majewski | a02e933 | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 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/*" \ |
Seung-Woo Kim | a13e31a | 2018-06-04 13:25:04 +0900 | [diff] [blame] | 26 | -not -path "*/tools/*" -name "${ENV_OBJ_FILE}") |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 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 |
Lukasz Majewski | a02e933 | 2018-02-14 11:39:48 +0100 | [diff] [blame] | 33 | # (copy_${ENV_OBJ_FILE} in this case) |
| 34 | |
Tom Rini | a5a5206 | 2021-06-21 16:14:18 -0400 | [diff] [blame] | 35 | ${OBJCOPY} --dump-section .rodata.default_environment=${ENV_OBJ_FILE_COPY} \ |
| 36 | ${env_obj_file_path} |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 37 | |
| 38 | # Replace default '\0' with '\n' and sort entries |
Rasmus Villemoes | 294ba04 | 2020-01-06 12:01:17 +0000 | [diff] [blame] | 39 | tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sort --field-separator== -k1,1 --stable |
Lukasz Majewski | babaaa6 | 2016-09-17 06:57:39 +0200 | [diff] [blame] | 40 | |
| 41 | rm ${ENV_OBJ_FILE_COPY} |
| 42 | |
| 43 | exit 0 |