[U-Boot] [PATCH 2/2] P4080/PBL: add tool to support pbl image build.
Shaohui Xie
b21989 at freescale.com
Wed Mar 16 03:11:03 CET 2011
The tool can build u-boot image which can be used by PBL,
run "make P4080DS_RAMBOOT_PBL" can make all works done,
the default output image is u-boot.pbl, for more details
please refer to doc/README.pblimage.
Signed-off-by: Shaohui Xie <b21989 at freescale.com>
---
Makefile | 5 +
board/freescale/corenet_ds/config.mk | 26 +++
board/freescale/corenet_ds/pblimage.cfg | 59 ++++++
common/image.c | 1 +
doc/README.pblimage | 83 ++++++++
include/image.h | 1 +
tools/Makefile | 2 +
tools/mkimage.c | 5 +
tools/mkimage.h | 2 +
tools/pblimage.c | 329 +++++++++++++++++++++++++++++++
tools/pblimage.h | 36 ++++
11 files changed, 549 insertions(+), 0 deletions(-)
create mode 100644 board/freescale/corenet_ds/config.mk
create mode 100644 board/freescale/corenet_ds/pblimage.cfg
create mode 100644 doc/README.pblimage
create mode 100644 tools/pblimage.c
create mode 100644 tools/pblimage.h
diff --git a/Makefile b/Makefile
index dc2e3d8..ca6078e 100644
--- a/Makefile
+++ b/Makefile
@@ -361,6 +361,10 @@ $(obj)u-boot.kwb: $(obj)u-boot.bin
$(obj)tools/mkimage -n $(CONFIG_SYS_KWD_CONFIG) -T kwbimage \
-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) -d $< $@
+$(obj)u-boot.pbl: $(obj)u-boot.bin
+ $(obj)tools/mkimage -n $(PBL_CONFIG) -T pblimage \
+ -d $< $@
+
$(obj)u-boot.sha1: $(obj)u-boot.bin
$(obj)tools/ubsha1 $(obj)u-boot.bin
@@ -1156,6 +1160,7 @@ clobber: clean
$(obj)cscope.* $(obj)*.*~
@rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
@rm -f $(obj)u-boot.kwb
+ @rm -f $(obj)u-boot.pbl
@rm -f $(obj)u-boot.imx
@rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes}
@rm -f $(obj)arch/powerpc/cpu/mpc824x/bedbug_603e.c
diff --git a/board/freescale/corenet_ds/config.mk b/board/freescale/corenet_ds/config.mk
new file mode 100644
index 0000000..c94938f
--- /dev/null
+++ b/board/freescale/corenet_ds/config.mk
@@ -0,0 +1,26 @@
+#
+# Copyright 2011 Freescale Semiconductor, Inc.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+ifeq ($(CONFIG_RAMBOOT_PBL), y)
+PBL_CONFIG = $(SRCTREE)/board/$(BOARDDIR)/pblimage.cfg
+ALL += $(obj)u-boot.pbl
+endif
diff --git a/board/freescale/corenet_ds/pblimage.cfg b/board/freescale/corenet_ds/pblimage.cfg
new file mode 100644
index 0000000..96c55ee
--- /dev/null
+++ b/board/freescale/corenet_ds/pblimage.cfg
@@ -0,0 +1,59 @@
+#
+# Copyright 2011 Freescale Semiconductor, Inc.
+# Written-by: Shaohui Xie<b21989 at freescale.com>
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+#
+# Refer docs/README.pblimage for more details about how-to configure
+# and create PBL boot image
+#
+
+#PBL preamble and RCW header
+aa55aa55 010e0100
+#64 bytes RCW data
+4c580000 00000000 18185218 0000cccc
+40464000 3c3c2000 58000000 61000000
+00000000 00000000 00000000 008b6000
+00000000 00000000 00000000 00000000
+
+#PBI commands
+#Initialize CPC1
+09010000 00200400
+09138000 00000000
+091380c0 00000100
+09010100 00000000
+09010104 fff0000b
+09010f00 08000000
+09010000 80000000
+#Configure LAW for CPC1
+09000d00 00000000
+09000d04 fff00000
+09000d08 81000013
+09000010 00000000
+09000014 ff000000
+09000018 81000000
+#Initialize eSPI controller
+09110000 80000403
+09110020 2d170008
+09110024 00100008
+09110028 00100008
+0911002c 00100008
+#Flush PBL data
+09138000 00000000
+091380c0 00000000
diff --git a/common/image.c b/common/image.c
index f63a2ff..76e493d 100644
--- a/common/image.c
+++ b/common/image.c
@@ -141,6 +141,7 @@ static const table_entry_t uimage_type[] = {
{ IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
{ IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
{ IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
+ { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
{ -1, "", "", },
};
diff --git a/doc/README.pblimage b/doc/README.pblimage
new file mode 100644
index 0000000..e7ebea0
--- /dev/null
+++ b/doc/README.pblimage
@@ -0,0 +1,83 @@
+------------------------------------------------------------------
+Freescale PBL(pre-boot loader) Boot Image generation using mkimage
+------------------------------------------------------------------
+
+This document describes the U-Boot feature as it
+is implemented for the Freescale P4080.
+
+The P4080 SoC's can boot directly from eSPI FLASH.
+
+for more details refer section 5 Pre-boot loader specifications.
+
+Building PBL boot image and boot steps
+--------------------------------------
+
+1. To build the PBL boot image for P4080DS:
+ make P4080DS_RAMBOOT_PBL
+ The default image is u-boot.pbl.
+
+2. Command below provided a way to re-build the PBL boot image if the
+configuration file needes to be modified while the u-boot.bin does not
+need to be re-build.
+
+Command syntax:
+--------------
+./tools/mkimage -n <board specific configuration file> \
+ -T pblimage -d <input_raw_binary> <output_pblboot_file>
+
+for ex.
+./tools/mkimage -n ./board/freescale/corenet_ds/pblimage.cfg \
+ -T pblimage -d u-boot.bin u-boot.pbl
+
+
+3. pblimage support available with mkimage utility will generate Freescale PBL
+boot image that can be flashed on the board eSPI flash. After flashed the
+image u-boot.pbl, Change SW1[2] = off, then power on, board will boot from
+eSPI flash.
+
+Board specific configuration file specifications:
+------------------------------------------------
+1. This file must present in the $(BOARDDIR) and the name should be
+ pblimage.cfg (since this is used in Makefile)
+2. This file can have empty lines and lines starting with "#" as first
+ character to put comments
+
+Typical example of pblimage.cfg file:
+-----------------------------------
+
+#PBL preamble and RCW header
+aa55aa55 010e0100
+#64 bytes RCW data
+4c580000 00000000 18185218 0000cccc
+40464000 3c3c2000 58000000 61000000
+00000000 00000000 00000000 008b6000
+00000000 00000000 00000000 00000000
+
+#PBI commands
+#Initialize CPC1
+09010000 00200400
+09138000 00000000
+091380c0 00000100
+09010100 00000000
+09010104 fff0000b
+09010f00 08000000
+09010000 80000000
+#Configure LAW for CPC1
+09000d00 00000000
+09000d04 fff00000
+09000d08 81000013
+09000010 00000000
+09000014 ff000000
+09000018 81000000
+#Initialize eSPI controller
+09110000 80000403
+09110020 2d170008
+09110024 00100008
+09110028 00100008
+0911002c 00100008
+#Flush PBL data
+09138000 00000000
+091380c0 00000000
+
+------------------------------------------------
+Author: Shaohui Xie<b21989 at freescale.com>
diff --git a/include/image.h b/include/image.h
index 005e0d2..56b849e 100644
--- a/include/image.h
+++ b/include/image.h
@@ -157,6 +157,7 @@
#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
#define IH_TYPE_KWBIMAGE 9 /* Kirkwood Boot Image */
#define IH_TYPE_IMXIMAGE 10 /* Freescale IMXBoot Image */
+#define IH_TYPE_PBLIMAGE 11 /* Freescale PBLBoot Image */
/*
* Compression Types
diff --git a/tools/Makefile b/tools/Makefile
index 623f908..c068bc0 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -83,6 +83,7 @@ OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
OBJ_FILES-$(CONFIG_INCA_IP) += inca-swap-bytes.o
NOPED_OBJ_FILES-y += kwbimage.o
+NOPED_OBJ_FILES-y += pblimage.o
NOPED_OBJ_FILES-y += imximage.o
NOPED_OBJ_FILES-y += mkimage.o
OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
@@ -181,6 +182,7 @@ $(obj)mkimage$(SFX): $(obj)crc32.o \
$(obj)image.o \
$(obj)imximage.o \
$(obj)kwbimage.o \
+ $(obj)pblimage.o \
$(obj)md5.o \
$(obj)mkimage.o \
$(obj)os_support.o \
diff --git a/tools/mkimage.c b/tools/mkimage.c
index f5859d7..a3e793a 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -149,6 +149,8 @@ main (int argc, char **argv)
int retval = 0;
struct image_type_params *tparams = NULL;
+ /* Init Freescale PBL Boot image generation/list support */
+ init_pbl_image_type();
/* Init Kirkwood Boot image generation/list support */
init_kwb_image_type ();
/* Init Freescale imx Boot image generation/list support */
@@ -421,6 +423,9 @@ NXTARG: ;
break;
}
}
+ } else if (params.type == IH_TYPE_PBLIMAGE) {
+ /* the copy_file need to be re-write for PBL. */
+ pbl_load_uboot(ifd, ¶ms);
} else {
copy_file (ifd, params.datafile, 0);
}
diff --git a/tools/mkimage.h b/tools/mkimage.h
index 9033a7d..597dcaf 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -139,6 +139,8 @@ void mkimage_register (struct image_type_params *tparams);
*
* Supported image types init functions
*/
+void pbl_load_uboot(int, struct mkimage_params *);
+void init_pbl_image_type(void);
void init_kwb_image_type (void);
void init_imx_image_type (void);
void init_default_image_type (void);
diff --git a/tools/pblimage.c b/tools/pblimage.c
new file mode 100644
index 0000000..d0c29a6
--- /dev/null
+++ b/tools/pblimage.c
@@ -0,0 +1,329 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#define _GNU_SOURCE
+
+#include "mkimage.h"
+#include <image.h>
+#include "pblimage.h"
+
+/*
+ * PBL can load 64 bytes each time in MAX, so the u-boot need to be splited into
+ * pieces of 64 bytes, PBL needs a command for each piece, the command looks
+ * like 81xxxxxx, the "xxxxxx" is offset, it starts from F80000 in our case.
+ */
+static unsigned int uboot_label = 0x81F80000;
+/*
+ * need to store all bytes in memory for calculating crc32, then write the
+ * bytes to image file for PBL boot.
+ */
+static unsigned char mem_buf[600000];
+static unsigned char *pmem_buf = mem_buf;
+static int mem_byte_cnt;
+static char *fname = "Unknown";
+static int lineno = -1;
+static struct pbl_header pblimage_header;
+
+static union
+{
+ char c[4];
+ unsigned char l;
+} endian_test = { {'l', '?', '?', 'b'} };
+
+#define ENDIANNESS ((char)endian_test.l)
+
+static void generate_pbl_cmd(void)
+{
+ unsigned int val = uboot_label;
+ uboot_label += 0x40;
+ int i;
+
+ for (i = 3; i >= 0; i--) {
+ *pmem_buf++ = (val >> (i * 8)) & 0xff;
+ mem_byte_cnt++;
+ }
+}
+
+static void pbl_fget(size_t size, FILE *stream)
+{
+ unsigned char c;
+ while (size) {
+ c = (unsigned char)fgetc(stream);
+ *pmem_buf++ = c;
+ mem_byte_cnt++;
+ size--;
+ }
+}
+
+/* load splited u-boot with PBI command 81xxxxxx. */
+static void load_uboot(FILE *fp_uboot)
+{
+ while (uboot_label < 0x82000000) {
+ generate_pbl_cmd();
+ pbl_fget(64, fp_uboot);
+ }
+}
+
+static void check_get_hexval(char *token)
+{
+ uint32_t hexval;
+ int i;
+
+ if (!sscanf(token, "%x", &hexval)) {
+ printf("Error:%s[%d] - Invalid hex data(%s)\n", fname,
+ lineno, token);
+ exit(EXIT_FAILURE);
+ }
+ for (i = 3; i >= 0; i--) {
+ *pmem_buf++ = (hexval >> (i * 8)) & 0xff;
+ mem_byte_cnt++;
+ }
+}
+
+static void pbl_parser(char *name)
+{
+ FILE *fd = NULL;
+ char *line = NULL;
+ char *token, *saveptr1, *saveptr2;
+ size_t len = 0;
+
+ fname = name;
+ fd = fopen(name, "r");
+ if (fd == NULL) {
+ printf("Error:%s - Can't open\n", fname);
+ exit(EXIT_FAILURE);
+ }
+
+ while ((getline(&line, &len, fd)) > 0) {
+ lineno++;
+ token = strtok_r(line, "\r\n", &saveptr1);
+ /* drop all lines with zero tokens (= empty lines) */
+ if (token == NULL)
+ continue;
+ for (line = token;; line = NULL) {
+ token = strtok_r(line, " \t", &saveptr2);
+ if (token == NULL)
+ break;
+ /* Drop all text starting with '#' as comments */
+ if (token[0] == '#')
+ break;
+ check_get_hexval(token);
+ }
+ }
+ if (line)
+ free(line);
+ fclose(fd);
+}
+
+static uint32_t crc_table[256];
+
+static void make_crc_table(void)
+{
+ uint32_t mask;
+ int i, j;
+ uint32_t poly; /* polynomial exclusive-or pattern */
+
+ /*
+ * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
+ * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
+ */
+ poly = 0x04c11db7;
+
+ for (i = 0; i < 256; i++) {
+ mask = i << 24;
+ for (j = 0; j < 8; j++) {
+ if (mask & 0x80000000)
+ mask = (mask << 1) ^ poly;
+ else
+ mask <<= 1;
+ }
+ crc_table[i] = mask;
+ }
+}
+
+unsigned long pbl_crc32(unsigned long crc, const char *buf, unsigned int len)
+{
+ unsigned int crc32_val = 0xffffffff;
+ unsigned int xor = 0x0;
+ int i;
+
+ make_crc_table();
+
+ for (i = 0; i < len; i++)
+ crc32_val = (crc32_val << 8) ^
+ crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
+
+ crc32_val = crc32_val ^ xor;
+ if (crc32_val < 0) {
+ crc32_val += 0xffffffff;
+ crc32_val += 1;
+ }
+ return crc32_val;
+}
+
+static unsigned int reverse_byte(unsigned int val)
+{
+ unsigned int temp;
+ unsigned char *p1;
+ int j;
+
+ temp = val;
+ p1 = (unsigned char *)&temp;
+ for (j = 3; j >= 0; j--)
+ *p1++ = (val >> (j * 8)) & 0xff;
+ return temp;
+}
+
+/* write end command and crc command to memory. */
+static void add_end_cmd(void)
+{
+ unsigned int pbl_end_cmd[4] = {0x09138000, 0x00000000,
+ 0x091380c0, 0x00000000};
+ unsigned int crc32_pbl;
+ int i;
+ unsigned char *p = (unsigned char *)&pbl_end_cmd;
+
+ if (ENDIANNESS == 'l') {
+ for (i = 0; i < 4; i++)
+ pbl_end_cmd[i] = reverse_byte(pbl_end_cmd[i]);
+ }
+
+ for (i = 0; i < 16; i++) {
+ *pmem_buf++ = *p++;
+ mem_byte_cnt++;
+ }
+
+ /* Add PBI CRC command. */
+ *pmem_buf++ = 0x08;
+ *pmem_buf++ = 0x13;
+ *pmem_buf++ = 0x80;
+ *pmem_buf++ = 0x40;
+ mem_byte_cnt += 4;
+
+ /* calculated CRC32 and write it to memory. */
+ crc32_pbl = pbl_crc32(0, (const char *)mem_buf, mem_byte_cnt);
+ *pmem_buf++ = (crc32_pbl >> 24) & 0xff;
+ *pmem_buf++ = (crc32_pbl >> 16) & 0xff;
+ *pmem_buf++ = (crc32_pbl >> 8) & 0xff;
+ *pmem_buf++ = (crc32_pbl) & 0xff;
+ mem_byte_cnt += 4;
+
+ if (((mem_byte_cnt) % 16) != 0) {
+ for (i = 0; i < 8; i++) {
+ *pmem_buf++ = 0x0;
+ mem_byte_cnt++;
+ }
+ }
+ if ((mem_byte_cnt % 16 != 0)) {
+ printf("Error: Bad size of image file\n");
+ exit(EXIT_FAILURE);
+ }
+
+}
+
+void pbl_load_uboot(int ifd, struct mkimage_params *params)
+{
+ FILE *fp_uboot;
+ int size;
+
+ /* parse the pblimage.cfg file. */
+ pbl_parser(params->imagename);
+
+ fp_uboot = fopen(params->datafile, "r");
+ if (fp_uboot == NULL) {
+ printf("Error: %s open failed\n", params->datafile);
+ exit(EXIT_FAILURE);
+ }
+
+ load_uboot(fp_uboot);
+ add_end_cmd();
+ fclose(fp_uboot);
+ lseek(ifd, 0, SEEK_SET);
+
+ size = mem_byte_cnt;
+ if (write(ifd, (const void *)&mem_buf, size) != size) {
+ fprintf(stderr, "Write error on %s: %s\n",
+ params->imagefile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+}
+
+static int pblimage_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_PBLIMAGE)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static int pblimage_verify_header(unsigned char *ptr, int image_size,
+ struct mkimage_params *params)
+{
+
+ struct pbl_header *pbl_hdr = (struct pbl_header *) ptr;
+
+ /* Only a few checks can be done: search for magic numbers */
+ if (ENDIANNESS == 'l') {
+ if (pbl_hdr->preamble != reverse_byte(RCW_PREAMBLE))
+ return -FDT_ERR_BADSTRUCTURE;
+
+ if (pbl_hdr->rcwheader != reverse_byte(RCW_HEADER))
+ return -FDT_ERR_BADSTRUCTURE;
+ } else {
+ if (pbl_hdr->preamble != RCW_PREAMBLE)
+ return -FDT_ERR_BADSTRUCTURE;
+
+ if (pbl_hdr->rcwheader != RCW_HEADER)
+ return -FDT_ERR_BADSTRUCTURE;
+ }
+
+ return 0;
+}
+
+static void pblimage_print_header(const void *ptr)
+{
+ printf("Image Type: Freescale pbl Boot Image\n");
+}
+
+static void pblimage_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct mkimage_params *params)
+{
+ /*nothing need to do, pbl_load_uboot takes care of whole file. */
+}
+
+/*
+ * pblimage parameters
+ */
+static struct image_type_params pblimage_params = {
+ .name = "Freescale PBL Boot Image support",
+ .header_size = sizeof(struct pbl_header),
+ .hdr = (void *)&pblimage_header,
+ .check_image_type = pblimage_check_image_types,
+ .verify_header = pblimage_verify_header,
+ .print_header = pblimage_print_header,
+ .set_header = pblimage_set_header,
+};
+
+void init_pbl_image_type(void)
+{
+ mem_byte_cnt = 0;
+ mkimage_register(&pblimage_params);
+}
diff --git a/tools/pblimage.h b/tools/pblimage.h
new file mode 100644
index 0000000..887d4c9
--- /dev/null
+++ b/tools/pblimage.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _PBLIMAGE_H_
+#define _PBLIMAGE_H_
+
+#define RCW_BYTES 64
+#define RCW_PREAMBLE 0xaa55aa55
+#define RCW_HEADER 0x010e0100
+
+struct pbl_header {
+ uint32_t preamble;
+ uint32_t rcwheader;
+ uint8_t rcw_data[RCW_BYTES];
+};
+
+#endif /* _PBLIMAGE_H_ */
--
1.6.4
More information about the U-Boot
mailing list