From patchwork Wed Feb 3 12:44:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1435301 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=B9UmsXKE; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DW1nB10SSz9sWR for ; Wed, 3 Feb 2021 23:53:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 984B8828E8; Wed, 3 Feb 2021 13:48:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="B9UmsXKE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A11282848; Wed, 3 Feb 2021 13:47:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7D75A827C3 for ; Wed, 3 Feb 2021 13:46:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-qv1-xf2b.google.com with SMTP id ew18so11551676qvb.4 for ; Wed, 03 Feb 2021 04:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MPDGg9TB3G67uKbF5bfaBK/UKNPNtk5DWR/hq201Z4c=; b=B9UmsXKEcbsjESKn0s1txWcQlr/ToGcYdxzJo2gEL3PDT9LDjVi5bHjkMxrMcfigjZ ZB6b3Rfim5fZCZ9verGeJlsIUuFzKOrP5fosmr08VR9MTGQ/+c0UcajfGQcw8Pn/0QeM kL8jrFKaclmyeTVB2ZuM2z1wRl2GGz/goG1HI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MPDGg9TB3G67uKbF5bfaBK/UKNPNtk5DWR/hq201Z4c=; b=UGcDhW1o7mfSN1h75V4nXzQxQ7s/KAmaLIVM2ZvaR5Ag9RrpyVk2JQrQwtTOjr702m OESizMJK92eSGRxf05xFLXuaK628Ds63TEcA64o4D0DKr4QeKyDSKkDOSKRkpSvjqjBR 7sVwaV75KroPyu0oD6WRdxehzrsSeyG4NhzO4UXGZAm81ApW+/tCNhwFqUG+EAcCFu4d 5DETAia8ug2zJb1yCvCrQjBhJWCbGHpI2mWd1HM6C6OE45gVwAZFukAc786da5jPM+/d f1G4qu3NVtwKTeLzpO6ovb8c56VYInq0MXpHA4INinogt5Ww6BCKRrevK/NP3MwMJZXW FxXQ== X-Gm-Message-State: AOAM530O51Tldbo1qdg2jRFNUHJ4HjDpwQp40vBxs96aN4ISEzUcSdaN 8tw+2H1UsqB9842lkLCIND/woUBrLHskHZEZ X-Google-Smtp-Source: ABdhPJwl3sPXU0XNuQQOJWiBgONkypW/MrY2EX7N81lTdlBvNpFkX+0rPj4C9f9oiuJYL47Y+20+gA== X-Received: by 2002:a05:6214:144a:: with SMTP id b10mr2645656qvy.56.1612356402229; Wed, 03 Feb 2021 04:46:42 -0800 (PST) Received: from sjg1.roam.corp.google.com ([50.225.158.38]) by smtp.gmail.com with ESMTPSA id p26sm1560903qkk.6.2021.02.03.04.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 04:46:41 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Stephen Warren , Stephen Warren , Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [PATCH v3 37/41] spl: Convert spl_fit to work with sandbox Date: Wed, 3 Feb 2021 05:44:43 -0700 Message-Id: <20210203124447.2458527-36-sjg@chromium.org> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog In-Reply-To: <20210203124447.2458527-1-sjg@chromium.org> References: <20210203124447.2458527-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean At present this casts addresses to pointers so cannot work with sandbox. Update the code to use map_sysmem() instead. As part of this change, the existing load_ptr is renamed to src_ptr since it is not a pointer to load_addr. It is confusing to use a similar name for something that is not actually related. For the alignment code, ALIGN() is used instead of open-coded alignment. Add a comment to the line that casts away a const. Use a (new) load_ptr variable to access memory at address load_addr. Signed-off-by: Simon Glass --- (no changes since v1) common/spl/spl.c | 3 ++- common/spl/spl_fit.c | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/common/spl/spl.c b/common/spl/spl.c index cdd7b05f279..8461293a517 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -167,7 +168,7 @@ __weak void spl_board_prepare_for_boot(void) __weak struct image_header *spl_get_load_buffer(ssize_t offset, size_t size) { - return (struct image_header *)(CONFIG_SYS_TEXT_BASE + offset); + return map_sysmem(CONFIG_SYS_TEXT_BASE + offset, 0); } void spl_set_header_raw_uboot(struct spl_image_info *spl_image) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index a6ad094e91a..d84e0569cf6 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -245,11 +246,11 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, size_t length; int len; ulong size; - ulong load_addr, load_ptr; + ulong load_addr; + void *load_ptr; void *src; ulong overhead; int nr_sectors; - int align_len = ARCH_DMA_MINALIGN - 1; uint8_t image_comp = -1, type = -1; const void *data; bool external_data = false; @@ -278,11 +279,13 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, } if (external_data) { + void *src_ptr; + /* External data */ if (fit_image_get_data_size(fit, node, &len)) return -ENOENT; - load_ptr = (load_addr + align_len) & ~align_len; + src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len); length = len; overhead = get_aligned_image_overhead(info, offset); @@ -290,12 +293,12 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, if (info->read(info, sector + get_aligned_image_offset(info, offset), - nr_sectors, (void *)load_ptr) != nr_sectors) + nr_sectors, src_ptr) != nr_sectors) return -EIO; - debug("External data: dst=%lx, offset=%x, size=%lx\n", - load_ptr, offset, (unsigned long)length); - src = (void *)load_ptr + overhead; + debug("External data: dst=%p, offset=%x, size=%lx\n", + src_ptr, offset, (unsigned long)length); + src = src_ptr + overhead; } else { /* Embedded data */ if (fit_image_get_data(fit, node, &data, &length)) { @@ -304,7 +307,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, } debug("Embedded data: dst=%lx, size=%lx\n", load_addr, (unsigned long)length); - src = (void *)data; + src = (void *)data; /* cast away const */ } #ifdef CONFIG_SPL_FIT_SIGNATURE @@ -320,16 +323,16 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, board_fit_image_post_process(&src, &length); #endif + load_ptr = map_sysmem(load_addr, length); if (IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) { size = length; - if (gunzip((void *)load_addr, CONFIG_SYS_BOOTM_LEN, - src, &size)) { + if (gunzip(load_ptr, CONFIG_SYS_BOOTM_LEN, src, &size)) { puts("Uncompressing error\n"); return -EIO; } length = size; } else { - memcpy((void *)load_addr, src, length); + memcpy(load_ptr, src, length); } if (image_info) { @@ -382,7 +385,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, } /* Make the load-address of the FDT available for the SPL framework */ - spl_image->fdt_addr = (void *)image_info.load_addr; + spl_image->fdt_addr = map_sysmem(image_info.load_addr, 0); #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY) if (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) { void *tmpbuffer = NULL;