Commit 32669476 authored by Pankaj Gupta's avatar Pankaj Gupta
Browse files

nxp-tool: for creating pbl file from bl2


NXP tool to create pbl from bl2 binary:
- RCW is prepended to BL2.bin
- If TRUSTED_BOARD_BOOT=1, pre-append the CSF header
	to be understood by NXP boot-rom.
Signed-off-by: default avatarPankaj Gupta <pankaj.gupta@nxp.com>
Change-Id: Iddc7336a045222e2073ddad86358ebc4440b8bcf
No related merge requests found
Showing with 1418 additions and 0 deletions
+1418 -0
#
# Copyright 2018-2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
MAKE_HELPERS_DIRECTORY := ../../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk
PROJECT_1 := create_pbl${BIN_EXT}
OBJECTS_1 := create_pbl.o
PROJECT_2 := byte_swap${BIN_EXT}
OBJECTS_2 := byte_swap.o
V ?= 0
override CPPFLAGS += -D_GNU_SOURCE -D_XOPEN_SOURCE=700
CFLAGS := -Wall -Werror -pedantic -std=c99
ifeq (${DEBUG},1)
CFLAGS += -g -O0 -DDEBUG
else
CFLAGS += -O2
endif
LDLIBS :=
ifeq (${V},0)
Q := @
else
Q :=
endif
INCLUDE_PATHS :=
HOSTCC ?= gcc
CC = gcc
.PHONY: all clean distclean
all: create_pbl byte_swap
${PROJECT_1}: ${OBJECTS_1} Makefile
@echo " LD $@"
${Q}${HOSTCC} ${OBJECTS_1} -o $@ ${LDLIBS}
@${ECHO_BLANK_LINE}
@echo "Built $@ successfully"
@${ECHO_BLANK_LINE}
${PROJECT_2}: ${OBJECTS_2} Makefile
@echo " LD $@"
${Q}${HOSTCC} ${OBJECTS_2} -o $@ ${LDLIBS}
@${ECHO_BLANK_LINE}
@echo "Built $@ successfully"
@${ECHO_BLANK_LINE}
%.o: %.c %.h Makefile
@echo " CC $<"
${Q}${HOSTCC} -c ${CPPFLAGS} ${CFLAGS} ${INCLUDE_PATHS} $< -o $@
clean:
$(call SHELL_DELETE_ALL, ${PROJECT_1} ${OBJECTS_1})
$(call SHELL_DELETE_ALL, ${PROJECT_2} ${OBJECTS_2})
Description:
------------
Tool 'create_pbl' is a standalone tool to create the PBL images.
where,
On the basis of Chassis,
RCW image is placed first followed by the,
PBI commands to copy the,
Input BL2 image stored on the,
Specified boot source (QSPI or SD or NOR) to the,
Specified destination address.
Usage in standalone way:
-----------------------
./create_pbl [options] (mentioned below):
-r <RCW file-name> - name of RCW binary file.
-i <BL2 Bin file-name> - file to be added to rcw file.
-c <SoC Number> - SoC numeric identifier, may be one of
1012,1023,1026.1028,
1043,1046,1088,2080,
2088,2160
-b <boot source id> - Boot source id string, may be one of
"qspi", "nor", "nand", "sd", "emmc"
-d <Address> - Destination address where BL2
image is to be copied
-o <output filename> - Name of PBL image generated
as an output of the tool.
-e <Address> - [Optional] Entry Point Address
of the BL2.bin
-f <Address> - BL2 image offset
on Boot Source for block copy.
command for chassis >=3.)
(Must for Ch3, Ignored for Ch2)
-h Help.
-s Secure boot.
-s secure boot
-c SoC Number (see description above)
-b Boot source.
-r RCW binary file.
-i Input file that is to be added to rcw file.
-o Name of output file
-f Source Offset (Block Copy)
-d Destination address to which file has to be copied
-h Help.
Example:
./create_pbl -r <RCW file> -i <bl2.bin> -c <chassis_no> -b <boot_source = sd/qspi/nor> -d <Destination_Addr> -o <pbl_image_name>
Usage at compilation time:
--------------------------------
make <compilation command......> pbl RCW=<Path_to_RCW_File>/<rcw_file_name.bin>
Example: QSPI Boot For LS1046ARDB-
make PLAT=ls1046rdb all fip BOOT_MODE=qspi SPD=opteed BL32=tee.bin BL33=u-boot-ls1046.bin pbl RCW=/home/pankaj/flexbuild/packages/firmware/dash-rcw/ls1046ardb/RR_FFSSPPPN_1133_5506/rcw_1600_qspiboot.bin
Example: QSPI Boot For LX2160ARDB-
make PLAT=lx2160ardb all fip BOOT_MODE=flexspi_nor SPD=opteed BL32=tee_lx2.bin BL33=u-boot_lx2160.bin pbl RCW=plat/nxp/soc-lx2160/lx2160ardb/rcw_1900_600_1600_19_5_2.bin
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#define NUM_MEM_BLOCK 1
#define FOUR_BYTE_ALIGN 4
#define EIGHT_BYTE_ALIGN 8
#define SIZE_TWO_PBL_CMD 24
#define SUCCESS 0
#define FAILURE -1
#define BYTE_SWAP_32(word) ((((word) & 0xff000000) >> 24)| \
(((word) & 0x00ff0000) >> 8) | \
(((word) & 0x0000ff00) << 8) | \
(((word) & 0x000000ff) << 24))
/*
* Returns:
* SUCCESS, on successful byte swapping.
* FAILURE, on failure.
*/
int do_byteswap(FILE *fp)
{
int bytes = 0;
uint32_t upper_byte;
uint32_t lower_byte;
uint32_t pad = 0U;
/* Carries number of Padding bytes to be appended to
* make file size 8 byte aligned.
*/
int append_bytes;
int ret = FAILURE;
fseek(fp, 0L, SEEK_END);
bytes = ftell(fp);
append_bytes = EIGHT_BYTE_ALIGN - (bytes % EIGHT_BYTE_ALIGN);
if (append_bytes != 0) {
if (fwrite(&pad, append_bytes, NUM_MEM_BLOCK, fp)
!= NUM_MEM_BLOCK) {
printf("%s: Error in appending padding bytes.\n",
__func__);
goto byteswap_err;
}
bytes += append_bytes;
}
rewind(fp);
while (bytes > 0) {
if ((fread(&upper_byte, sizeof(upper_byte), NUM_MEM_BLOCK, fp)
!= NUM_MEM_BLOCK) && (feof(fp) == 0)) {
printf("%s: Error reading upper bytes.\n", __func__);
goto byteswap_err;
}
if ((fread(&lower_byte, sizeof(lower_byte), NUM_MEM_BLOCK, fp)
!= NUM_MEM_BLOCK) && (feof(fp) == 0)) {
printf("%s: Error reading lower bytes.\n", __func__);
goto byteswap_err;
}
fseek(fp, -8L, SEEK_CUR);
upper_byte = BYTE_SWAP_32(upper_byte);
lower_byte = BYTE_SWAP_32(lower_byte);
if (fwrite(&lower_byte, sizeof(lower_byte), NUM_MEM_BLOCK, fp)
!= NUM_MEM_BLOCK) {
printf("%s: Error writing lower bytes.\n", __func__);
goto byteswap_err;
}
if (fwrite(&upper_byte, sizeof(upper_byte), NUM_MEM_BLOCK, fp)
!= NUM_MEM_BLOCK) {
printf("%s: Error writing upper bytes.\n", __func__);
goto byteswap_err;
}
bytes -= EIGHT_BYTE_ALIGN;
}
ret = SUCCESS;
byteswap_err:
return ret;
}
int main(int argc, char **argv)
{
FILE *fp = NULL;
int ret = 0;
if (argc > 2) {
printf("Usage format is byteswap <filename>");
return -1;
}
fp = fopen(argv[1], "rb+");
if (fp == NULL) {
printf("%s: Error opening the input file: %s\n",
__func__, argv[1]);
return -1;
}
ret = do_byteswap(fp);
fclose(fp);
return ret;
}
This diff is collapsed.
#
# Copyright 2018-2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
CREATE_PBL ?= ${CREATE_PBL_TOOL_PATH}/create_pbl${BIN_EXT}
BYTE_SWAP ?= ${CREATE_PBL_PLAT_TOOL_PATH}/byte_swap${BIN_EXT}
HOST_GCC := gcc
#SWAP is required for Chassis 2 platforms - LS102, ls1043 and ls1046 for QSPI
ifeq (${SOC},ls1046a)
SOC_NUM := 1046a
SWAP = 1
CH = 2
else ifeq (${SOC},ls1043a)
SOC_NUM := 1043a
SWAP = 1
CH = 2
else ifeq (${SOC},ls1012a)
SOC_NUM := 1012a
SWAP = 1
CH = 2
else ifeq (${SOC},ls1088a)
SOC_NUM := 1088a
CH = 3
else ifeq (${SOC},ls2088a)
SOC_NUM := 2088a
CH = 3
else ifeq (${SOC},lx2160a)
SOC_NUM := 2160a
CH = 3
else ifeq (${SOC},ls1028a)
SOC_NUM := 1028a
CH = 3
else
$(error "Check SOC Not defined in create_pbl.mk.")
endif
ifeq (${CH},2)
include ${CREATE_PBL_TOOL_PATH}/pbl_ch2.mk
endif #CH2
ifeq (${CH},3)
include ${CREATE_PBL_TOOL_PATH}/pbl_ch3.mk
endif #CH3
#
# Copyright 2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
CREATE_PBL ?= ${CREATE_PBL_TOOL_PATH}/create_pbl${BIN_EXT}
BYTE_SWAP ?= ${CREATE_PBL_TOOL_PATH}/byte_swap${BIN_EXT}
HOST_GCC := gcc
.PHONY: pbl
pbl: ${BUILD_PLAT}/bl2.bin
ifeq ($(SECURE_BOOT),yes)
pbl: ${BUILD_PLAT}/bl2.bin
ifeq ($(RCW),"")
${Q}echo "Platform ${PLAT} requires rcw file. Please set RCW to point to the right RCW file for boot mode ${BOOT_MODE}"
else
# Generate header for bl2.bin
$(Q)$(CST_DIR)/create_hdr_isbc --in ${BUILD_PLAT}/bl2.bin --out ${BUILD_PLAT}/hdr_bl2 ${BL2_INPUT_FILE}
# Compile create_pbl tool
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${CREATE_PBL_TOOL_PATH};\
# Add bl2.bin to RCW
${CREATE_PBL} -r ${RCW} -i ${BUILD_PLAT}/bl2.bin -b ${BOOT_MODE} -c ${SOC_NUM} -d ${BL2_BASE} -e ${BL2_BASE}\
-o ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl ;\
# Add header to RCW
${CREATE_PBL} -r ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl -i ${BUILD_PLAT}/hdr_bl2 -b ${BOOT_MODE} -c ${SOC_NUM} \
-d ${BL2_HDR_LOC} -e ${BL2_HDR_LOC} -o ${BUILD_PLAT}/bl2_${BOOT_MODE}_sec.pbl -s;\
rm ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl
# Swapping of RCW is required for QSPi Chassis 2 devices
ifeq (${BOOT_MODE}, qspi)
ifeq ($(SWAP),1)
${Q}echo "Byteswapping RCW for QSPI"
${BYTE_SWAP} ${BUILD_PLAT}/bl2_${BOOT_MODE}_sec.pbl;
endif # SWAP
endif # BOOT_MODE
cd ${CREATE_PBL_TOOL_PATH}; ${MAKE} clean ; cd -;
endif
else # NON SECURE_BOOT
ifeq ($(RCW),"")
${Q}echo "Platform ${PLAT} requires rcw file. Please set RCW to point to the right RCW file for boot mode ${BOOT_MODE}"
else
# -a option appends the image for Chassis 3 devices in case of non secure boot
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${CREATE_PBL_TOOL_PATH};
${CREATE_PBL} -r ${RCW} -i ${BUILD_PLAT}/bl2.bin -b ${BOOT_MODE} -c ${SOC_NUM} -d ${BL2_BASE} -e ${BL2_BASE} \
-o ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl ;
# Swapping of RCW is required for QSPi Chassis 2 devices
ifeq (${BOOT_MODE}, qspi)
ifeq ($(SWAP),1)
${Q}echo "Byteswapping RCW for QSPI"
${BYTE_SWAP} ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl;
endif # SWAP
endif # BOOT_MODE
cd ${CREATE_PBL_TOOL_PATH}; ${MAKE} clean ; cd -;
endif
endif # SECURE_BOOT
#
# Copyright 2018-2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
SHELL=/bin/bash
CREATE_PBL ?= ${CREATE_PBL_TOOL_PATH}/create_pbl${BIN_EXT}
BYTE_SWAP ?= ${CREATE_PBL_TOOL_PATH}/byte_swap${BIN_EXT}
HOST_GCC := gcc
BL2_SRC_OFFSET ?= 0x9000
BL2_HDR_SRC_OFFSET ?= 0x5000
bl2_hdr_loc=$(shell echo $$(( $(BL2_HDR_SRC_OFFSET) / 1024 )))
bl2_loc=$(shell echo $$(( $(BL2_SRC_OFFSET) / 1024 )))
.PHONY: pbl
pbl: ${BUILD_PLAT}/bl2.bin
ifeq ($(SECURE_BOOT),yes)
pbl: ${BUILD_PLAT}/bl2.bin
ifeq ($(RCW),"")
${Q}echo "Platform ${PLAT} requires rcw file. Please set RCW to point to the right RCW file for boot mode ${BOOT_MODE}"
else
# Generate header for bl2.bin
$(Q)$(CST_DIR)/create_hdr_isbc --in ${BUILD_PLAT}/bl2.bin --out ${BUILD_PLAT}/hdr_bl2 ${BL2_INPUT_FILE}
# Compile create_pbl tool
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${CREATE_PBL_TOOL_PATH};\
# Add Block Copy command for bl2.bin to RCW
${CREATE_PBL} -r ${RCW} -i ${BUILD_PLAT}/bl2.bin -b ${BOOT_MODE} -c ${SOC_NUM} -d ${BL2_BASE} -e ${BL2_BASE}\
-o ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl -f ${BL2_SRC_OFFSET};\
# Add Block Copy command and Load CSF header command to RCW
${CREATE_PBL} -r ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl -i ${BUILD_PLAT}/hdr_bl2 -b ${BOOT_MODE} -c ${SOC_NUM} \
-d ${BL2_HDR_LOC} -e ${BL2_HDR_LOC} -s -f ${BL2_HDR_SRC_OFFSET} \
-o ${BUILD_PLAT}/rcw_sec.pbl
# Sign and add "Load Security Header command to PBI commands
$(Q)$(CST_DIR)/create_hdr_pbi --out ${BUILD_PLAT}/bl2_${BOOT_MODE}_sec.pbl --in ${BUILD_PLAT}/rcw_sec.pbl ${PBI_INPUT_FILE}
# Append the bl2_hdr to the RCW image
@echo "${bl2_hdr_loc}"
dd if=${BUILD_PLAT}/hdr_bl2 of=${BUILD_PLAT}/bl2_${BOOT_MODE}_sec.pbl bs=1K seek=${bl2_hdr_loc}
# Append the bl2.bin to the RCW image
@echo "${bl2_loc}"
dd if=${BUILD_PLAT}/bl2.bin of=${BUILD_PLAT}/bl2_${BOOT_MODE}_sec.pbl bs=1K seek=${bl2_loc}
rm ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl
cd ${CREATE_PBL_TOOL_PATH}; ${MAKE} clean ; cd -;
endif
else #SECURE_BOOT
ifeq ($(RCW),"")
${Q}echo "Platform ${PLAT} requires rcw file. Please set RCW to point to the right RCW file for boot mode ${BOOT_MODE}"
else
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${CREATE_PBL_TOOL_PATH};
# Add Block Copy command and populate boot loc ptrfor bl2.bin to RCW
${CREATE_PBL} -r ${RCW} -i ${BUILD_PLAT}/bl2.bin -b ${BOOT_MODE} -c ${SOC_NUM} -d ${BL2_BASE} -e ${BL2_BASE} \
-o ${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl -f ${BL2_SRC_OFFSET};
# Append the bl2.bin to the RCW image
@echo "bl2_loc is ${bl2_offset}"
dd if=${BUILD_PLAT}/bl2.bin of=${BUILD_PLAT}/bl2_${BOOT_MODE}.pbl bs=1K seek=${bl2_loc}
cd ${CREATE_PBL_TOOL_PATH}; ${MAKE} clean ; cd -;
endif
endif # SECURE_BOOT
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment