Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1F2DC6FD19 for ; Thu, 16 Mar 2023 04:09:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5450385DFC; Thu, 16 Mar 2023 05:09:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ji9I3/n5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5551385AA2; Wed, 15 Mar 2023 22:25:20 +0100 (CET) Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 4423F85AA2 for ; Wed, 15 Mar 2023 22:25:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ghidoliemanuele@gmail.com Received: by mail-wm1-x32a.google.com with SMTP id g18so1761090wmk.0 for ; Wed, 15 Mar 2023 14:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678915515; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=a1Uhp3jkrMtJE5ujCCnApPMO8oaktc1lbBDW7sxRyPY=; b=ji9I3/n5Zyd3SBplZ2K9VK/crnIioJXxSCONpEBD6bJSTqEsCQ0MXJPNmZ8TFl4ki9 nOoH5Er28QArJXREh06Pi1CHfSU4TPLVYvOO3AorJ5ukenZcmouCyfwycomoP8j3SzG3 Yz971Z6tCkSesW8dSDlEIuCH3e+hI7jRJG+V9QJrj/3NouJVBQzi4FrQ/YQgn+oFbUB9 g99A30iBu5pG7m4jvL6+x/zvlH4jmxjNpBvGVHTe2ftVnAne4jUxt5/NE79JQwqFj646 +GeWTWhgwx8IUbcO3phdMGOSEyFYSwb1uttVLboJ9Sbiu1B7MnSsb7Pb6DOrdO1eFkgw +4ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678915515; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a1Uhp3jkrMtJE5ujCCnApPMO8oaktc1lbBDW7sxRyPY=; b=Fwme3ukM5q6a9H0glYh5dLu69QBSblG3XMX9Aoki2gW/Vyjkcod5NCr4wx9+LFbl77 ZL+UQOU4DdOD/HtzOtnDaaQmcl+6juHhV34IM56ZNPZgDWKdAaQ1PpQYH/Tn85TgD+jG iZICYRX47Vtwoc4Qk+US+ADGOB/YF6Oubai1s9JMCXtI79sx7h7WzTjLIlhaEPJN7jmh 8TlPbmX6QbNmKZZmHImRzquPao1NcogmNGtM02F8wzSZSSqqLFkRwrSYrr28xaUg+kgm d00h+QW05Lt+qYyAlOkX/KEse2sisdn+BKXVChQKrkTq8fb9GX8YGO7qCvXrtwBDY5KX 2KPA== X-Gm-Message-State: AO0yUKVvrTuWvrBnnxeb2j/DfwJLgWS8ErgGXFJIlUifUUck+qEWH80h +rzvETidB98QOWMSr+n6gUc= X-Google-Smtp-Source: AK7set8eIEHQqxu+bh/dGnbBBdwtSQ+MBHD3HcILbUOC+Ixd4N6jbyLERAE79zK/qZ4xfOS/axNSUg== X-Received: by 2002:a05:600c:190c:b0:3e1:fc61:e0e5 with SMTP id j12-20020a05600c190c00b003e1fc61e0e5mr18704311wmq.33.1678915515396; Wed, 15 Mar 2023 14:25:15 -0700 (PDT) Received: from [192.168.79.191] ([151.48.46.123]) by smtp.gmail.com with ESMTPSA id bg7-20020a05600c3c8700b003eb2e33f327sm8626873wmb.2.2023.03.15.14.25.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Mar 2023 14:25:15 -0700 (PDT) Message-ID: <88485229-ceeb-831f-7901-c8f8ab9102e1@gmail.com> Date: Wed, 15 Mar 2023 22:25:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: i.MX8MP SPL failures due to memory corruption/overflow? To: Frieder Schrempf , Michael Nazzareno Trimarchi Cc: "u-boot@lists.denx.de" , Fabio Estevam , "Peng Fan (OSS)" , Marcel Ziswiler , Teresa Remmet , Tim Harvey , Marek Vasut References: <14d7d9f9-c71b-7825-33ce-e9d84fa4ef27@kontron.de> Content-Language: en-US From: Emanuele Ghidoli In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 16 Mar 2023 05:08:59 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean On 15/03/2023 16:24, Frieder Schrempf wrote: > On 15.03.23 15:42, Frieder Schrempf wrote: >> On 15.03.23 15:17, Michael Nazzareno Trimarchi wrote: >>> Hi >>> >>> On Wed, Mar 15, 2023 at 3:13 PM Frieder Schrempf >>> wrote: >>>> >>>> Hi, >>>> >>>> I'm trying to bring up a new board based on the i.MX8MP and I have an >>>> issue I'm hoping someone can help solving. >>>> >>>> I'm seeing failures in the early SPL code, usually in the DDR >>>> initialization. Often they look like: >>>> >>>> U-Boot SPL 2023.04-rc3 (Mar 07 2023 - 14:32:34 +0000) >>>> Training FAILED >>>> Failed to initialize DDR RAM! >>>> ### ERROR ### Please RESET the board ### >>>> >>>> But sometimes ddr_init() doesn't even return an error and only the >>>> get_ram_size() afterwards which tries to allocate the memory fails. >>>> >>> >>> In my experience you don't have space inside the cpu internal memory. It means >>> that you overlap some stack with the code. Change the printf means >>> move a bit. So you have >>> problem but depends what you are going to destroy >> >> Thanks for your reply. That's exactly what I'm thinking, too. >> >>> >>>> The strange thing is that the issues appear or disappear >>>> deterministically on the binary level. This means I sometimes get a >>>> U-Boot binary which runs just fine in 100% of cases. Then I change for >>>> example one of the following: >>>> >>>> * Adding a single printf() somewhere in the boards spl.c >>>> * Using the same binary but booting from SD card instead of USB loader >>>> * Using the same source but switching from the OS cross compiler to the >>>> one from Yocto/OE >>>> >>>> And afterwards I get 100% failure rate with an error as described above. >>>> >>>> My suspicion is that there is some memory corruption/conflict. My SPL is >>>> quite large and I wonder if it exceeds some limit. >>>> >>>> SPL is loaded to 0x920000 and CONFIG_SPL_STACK is set to 0x960000, which >>>> leaves 256 KiB in between for the SPL. But all i.MX8MP boards seem to >>>> set CONFIG_SPL_MAX_SIZE=0x26000 (152 KiB) for some reason. My >>>> u-boot-spl-ddr.bin currently has around 193 KiB but I don't get any >>>> warning about exceeding the SPL_MAX_SIZE. >>>> >>>> My questions: >>>> >>>> * Why is CONFIG_SPL_MAX_SIZE set to 152 KiB? >> >> I guess the remainder between the SPL code and the SPL stack is for the >> DDR firmware. Which explains why I get failures with SPL exceeding 152 >> KiB size. > > Still, it doesn't really make sense to me at the moment as the > u-boot-spl-ddr.bin already contains the DDR firmware it should be fine > to exceed the 152 KiB size. My u-boot-spl.bin (without DDR firmware) is > only 135 KiB. > > Sorry for spamming you by thinking out loud... ;) > >> >> Now I also understand the reason why the power init code was implemented >> using legacy non-DM drivers in other i.MX8MP boards. I probably also >> need to do this to save some space. >> >>>> * Why is there no warning in my case? >> >> Still, I fail to see why there isn't any error or where the size check >> is even implemented. >> >>>> * Any other ideas or pointers? >>>> >>>> Thanks for your help! >>>> >>>> Best regards >>>> Frieder > Hello, I fall in a similar problem. Some hints: - commit 5004901efb3b ("board_init: Do not reserve MALLOC_F area on stack if non-zero MALLOC_F_ADDR") - but you should already have it - Reduce (set to something different from default value) SPL_SYS_MALLOC_F_LEN. Normally that area is not used a lot. Stack start before heap area and, if I remember well, start address of heap area depend upon this config. And... its default value is equal to SYS_MALLOC_F_LEN, that normally is high. Suggestions from Rasmus are precious. I adopt a rather similar approch to find that stack / gd (global data) was overlapping DDR firmware / cfg. Best regards, Emanuele Ghidoli