From patchwork Tue Nov 21 12:00:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 839984 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="qKp+puZ/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yh4954fj6z9ryT for ; Tue, 21 Nov 2017 23:07:53 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5B3E3C21EE7; Tue, 21 Nov 2017 12:03:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 875BDC21FC8; Tue, 21 Nov 2017 12:01:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 329FAC21EF3; Tue, 21 Nov 2017 12:01:18 +0000 (UTC) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by lists.denx.de (Postfix) with ESMTPS id 6F26AC21F63 for ; Tue, 21 Nov 2017 12:01:14 +0000 (UTC) Received: by mail-wr0-f196.google.com with SMTP id 11so7724117wrb.6 for ; Tue, 21 Nov 2017 04:01:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=eZpB+71jYvRje+mGqJDqDHc0Dxlbr9EAF1O2Lm1xjzg=; b=qKp+puZ/zE1dzlE/nhEtB5K3a2EYijn9xdYEcW8ypu7LxHTr5vx6khjj7g2F8e+nrn Sab+r2w1Yc7kM0D7Q5UyyjZKfKPeos67t5lirpT7RJQXlcsCjl1nbjdsz3uz112IkUq6 4tkxo1rXj48MaaAMu9I4QrkRw7CmVCeBa/Og570euzQnD8px42FB8nfXDSV3RWo+84mP rNSn0Y/vvQpM8B1Q/jWapAwrR+0yu0wgYUbvXBtNytIa55/WWI/jIafow84eexNIETac cMYbndUFNDTKE8NHhO3MjTFkfa2CfXqCgP3sQfnZdAfa7LwPanYiJnJUHroOZeda82PB 9RVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=eZpB+71jYvRje+mGqJDqDHc0Dxlbr9EAF1O2Lm1xjzg=; b=scJ4hwgfcCOBdqLeB/drBgEUegHQ+AJxK0fjiKged+R26RQPQkUva26h+EByZP9Wt3 dY09qij3KGUbOO2F5RUFqcLFl1ExPw/Kh1uMw/BIZ1bN9XRWIKHy28+Z6H2agN/fwALX 7eMd2mExia54T8XlkBsBg7gu+Mu7ctIK7DALiHps+TClgmheE3fLJ3RHynTyQaGnFog3 J4rzeRAM1/gFbs3ygakILKPgDcycmYPj/Me3xA13tSq6aPW3iu6zk5Bi6BGHVeTJgwL/ IwJrhaQL6Hlg9zWAeMGLOvzuG+ccVc9Dzt5sdTadTF2S456+cVnEEJATvnLXKNYXxznR svaA== X-Gm-Message-State: AJaThX55eCXtTErlS02e2K79zanCKZ1gmfXkukzBOXJN9nFzMayUHZ7C jStZswS8GYHuudd0xNCjF9et26NJ X-Google-Smtp-Source: AGs4zMbT+zpkw/NxdDFE0GdUQkwzJHC07/Vy9mao/+wGAZrZ8Hi29V1xG5HhAOn0shSnH+GL3xP/jw== X-Received: by 10.223.202.1 with SMTP id o1mr15006298wrh.233.1511265673810; Tue, 21 Nov 2017 04:01:13 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id m189sm542725wmb.38.2017.11.21.04.01.12 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 21 Nov 2017 04:01:13 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de Date: Tue, 21 Nov 2017 13:00:57 +0100 Message-Id: <33a58795d066f0fdbc826d418935e0f0ea90f479.1511265659.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Cc: Stefan Agner , Maxime Ripard Subject: [U-Boot] [PATCH v2 04/11] tools: mkimage: Extend mkimage to also include pmufw X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The patch is adding external pmufw "Platform Management Unit firmware" to boot.bin image. Boot.bin is a Xilinx format which bootrom is capable to read and boot the system. pmufw is copied to the header data section follows by u-boot-spl.bin. pmufw is consumed by PMU unit (Microblaze) and SPL runs on a53-0. This is generated command line when PMUFW_INIT_FILE is setup. ./tools/mkimage -T zynqmpimage -R ./"" -n ./"board/xilinx/zynqmp/pmufw.bin" -d spl/u-boot-spl.bin spl/boot.bin Signed-off-by: Michal Simek Reviewed-by: Simon Glass --- Changes in v2: - Change commit message - reported by sjg - Extend help in Kconfig - reported by sjg arch/arm/cpu/armv8/zynqmp/Kconfig | 8 ++++ scripts/Makefile.spl | 3 +- tools/zynqmpimage.c | 99 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/arch/arm/cpu/armv8/zynqmp/Kconfig b/arch/arm/cpu/armv8/zynqmp/Kconfig index 4dc8b1caf79e..7a415830752c 100644 --- a/arch/arm/cpu/armv8/zynqmp/Kconfig +++ b/arch/arm/cpu/armv8/zynqmp/Kconfig @@ -57,6 +57,14 @@ config BOOT_INIT_FILE Add register writes to boot.bin format (max 256 pairs). Expect a table of register-value pairs, e.g. "0x12345678 0x4321" +config PMUFW_INIT_FILE + string "PMU firmware" + depends on SPL + default "" + help + Include external PMUFW (Platform Management Unit FirmWare) to + a Xilinx bootable image (boot.bin). + config ZYNQMP_USB bool "Configure ZynqMP USB" diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index ca044767a02c..b5e7019ea36a 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -167,7 +167,8 @@ ifdef CONFIG_ARCH_ZYNQ MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) endif ifdef CONFIG_ARCH_ZYNQMP -MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) +MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) \ + -n $(srctree)/$(CONFIG_PMUFW_INIT_FILE) endif spl/boot.bin: $(obj)/u-boot-spl.bin FORCE diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c index 0c9a3daddd6a..74bd5f5ccc3f 100644 --- a/tools/zynqmpimage.c +++ b/tools/zynqmpimage.c @@ -99,6 +99,8 @@ struct zynqmp_header { }; static struct zynqmp_header zynqmpimage_header; +static void *dynamic_header; +static FILE *fpmu; static uint32_t zynqmpimage_checksum(struct zynqmp_header *ptr) { @@ -181,6 +183,13 @@ static void zynqmpimage_print_header(const void *ptr) printf("Image Size : %lu bytes (%lu bytes packed)\n", (unsigned long)le32_to_cpu(zynqhdr->image_size), (unsigned long)le32_to_cpu(zynqhdr->image_stored_size)); + + if (zynqhdr->pfw_image_length) + printf("PMUFW Size : %lu bytes (%lu bytes packed)\n", + (unsigned long)le32_to_cpu(zynqhdr->pfw_image_length), + (unsigned long)le32_to_cpu( + zynqhdr->total_pfw_image_length)); + printf("Image Load : 0x%08x\n", le32_to_cpu(zynqhdr->image_load)); printf("Checksum : 0x%08x\n", le32_to_cpu(zynqhdr->checksum)); @@ -203,6 +212,8 @@ static void zynqmpimage_print_header(const void *ptr) le32_to_cpu(zynqhdr->register_init[i].address), le32_to_cpu(zynqhdr->register_init[i].data)); } + + free(dynamic_header); } static int zynqmpimage_check_params(struct image_tool_params *params) @@ -234,6 +245,44 @@ static int zynqmpimage_check_image_types(uint8_t type) return EXIT_FAILURE; } +static int fsize(FILE *fp) +{ + int size; + int origin = ftell(fp); + + fseek(fp, 0L, SEEK_END); + size = ftell(fp); + + /* going back */ + fseek(fp, origin, SEEK_SET); + + return size; +} + +static void zynqmpimage_pmufw(struct zynqmp_header *zynqhdr, + const char *filename) +{ + uint32_t size; + + /* Setup PMU fw size */ + zynqhdr->pfw_image_length = fsize(fpmu); + zynqhdr->total_pfw_image_length = zynqhdr->pfw_image_length; + + zynqhdr->image_size -= zynqhdr->pfw_image_length; + zynqhdr->image_stored_size -= zynqhdr->total_pfw_image_length; + + /* Read the whole PMUFW to the header */ + size = fread(&zynqhdr->__reserved4[66], 1, + zynqhdr->pfw_image_length, fpmu); + if (size != zynqhdr->pfw_image_length) { + fprintf(stderr, "Cannot read PMUFW file: %s\n", filename); + fclose(fpmu); + exit(1); + } + + fclose(fpmu); +} + static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr, const char *filename) { @@ -288,6 +337,10 @@ static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (params->eflag) zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep); + /* PMUFW */ + if (fpmu) + zynqmpimage_pmufw(zynqhdr, params->imagename); + /* User can pass in text file with init list */ if (strlen(params->imagename2)) zynqmpimage_parse_initparams(zynqhdr, params->imagename2); @@ -295,6 +348,50 @@ static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, zynqhdr->checksum = zynqmpimage_checksum(zynqhdr); } +static int zynqmpimage_vrec_header(struct image_tool_params *params, + struct image_type_params *tparams) +{ + struct stat path_stat; + char *filename = params->imagename; + int err; + + /* Handle static case without PMUFW */ + tparams->header_size = sizeof(struct zynqmp_header); + tparams->hdr = (void *)&zynqmpimage_header; + + /* PMUFW name is passed via params->imagename */ + if (strlen(filename) == 0) + return EXIT_SUCCESS; + + fpmu = fopen(filename, "r"); + if (!fpmu) { + fprintf(stderr, "Cannot open PMUFW file: %s\n", filename); + return EXIT_FAILURE; + } + + err = fstat(fileno(fpmu), &path_stat); + if (err) { + fclose(fpmu); + fpmu = NULL; + return EXIT_FAILURE; + } + + if (!S_ISREG(path_stat.st_mode)) { + fclose(fpmu); + fpmu = NULL; + return EXIT_FAILURE; + } + + /* Increase header size by PMUFW file size */ + tparams->header_size += fsize(fpmu); + + /* Allocate buffer with space for PMUFW */ + dynamic_header = calloc(1, tparams->header_size); + tparams->hdr = dynamic_header; + + return EXIT_SUCCESS; +} + U_BOOT_IMAGE_TYPE( zynqmpimage, "Xilinx ZynqMP Boot Image support", @@ -307,5 +404,5 @@ U_BOOT_IMAGE_TYPE( NULL, zynqmpimage_check_image_types, NULL, - NULL + zynqmpimage_vrec_header );