From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC181C11F64 for ; Thu, 1 Jul 2021 03:30:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B515F610E5 for ; Thu, 1 Jul 2021 03:30:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B515F610E5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A61DB83187; Thu, 1 Jul 2021 05:30:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=panix.com header.i=@panix.com header.b="fNxV4VHT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3730282C0A; Thu, 1 Jul 2021 01:19:36 +0200 (CEST) Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2D3C782ABE for ; Thu, 1 Jul 2021 01:19:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=zackw@panix.com Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by mailbackend.panix.com (Postfix) with ESMTPSA id 4GFckC0w7Xz4H2l for ; Wed, 30 Jun 2021 19:19:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=panix.com; s=panix; t=1625095171; bh=Z07ZCJKjw/2cNgXO1qXGn7/0GJ6o+OSEnh16sl3nNJQ=; h=From:Date:Subject:To; b=fNxV4VHT5GPZPFmTO51Ir/BffkpNJaw+2bK5RYqYpzH0mYyRRZpqcJG5oqnogLFos taxjnNudzRxWQCL3c3GjZji3hfz0lUL/msG+PaS36L+6rBloXX7xzlUlLSzkT8eA5Y mx9zfzftVYVYmbCBOt+9GvPmSPWPheMKQ1MrvTVE= Received: by mail-yb1-f171.google.com with SMTP id m9so7762047ybp.8 for ; Wed, 30 Jun 2021 16:19:31 -0700 (PDT) X-Gm-Message-State: AOAM531RxNUzCn+S9/8l8WoE3zoZlyrYpBrF1jyb0/dUVtVK5KkPCRmE XWKKm7rV9yycJU/l4o5b0+V+BFykSrTgtgA5GSY= X-Google-Smtp-Source: ABdhPJwHl1NhdNtFzUuWX03/BtKj1uG4KCi2DR5SpOaWMK9n88Cy9K6IpsjGrps9VASdpGW/j7MX5epTLg4MIEGy0Dg= X-Received: by 2002:a5b:34a:: with SMTP id q10mr49846446ybp.224.1625095170709; Wed, 30 Jun 2021 16:19:30 -0700 (PDT) MIME-Version: 1.0 From: Zack Weinberg Date: Wed, 30 Jun 2021 19:19:19 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Suggestion: When flash is uninitialized, *silently* fall back to default environment To: u-boot@lists.denx.de Content-Type: text/plain; charset="UTF-8" X-Mailman-Approved-At: Thu, 01 Jul 2021 05:30:05 +0200 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.103.2 at phobos.denx.de X-Virus-Status: Clean Consider a boot ROM that looks for u-boot in several places (SPI flash, eMMC flash, etc) and loads the first one it finds, and then u-boot repeats the same search to find its own configuration. If there is _nothing_ on the SPI flash and u-boot and all its configuration is on the eMMC, this will work fine _except_ that you'll get a scary-looking message from env_set_default *** Warning: bad CRC, using default environment because uninitialized flash memory reads as all-ones (FF FF FF FF ...) and the crc32 of ENV_SIZE bytes of 0xFF will typically not be 0xFFFF. I'd like to suggest that env_import() should, when the CRC fails, scan the environment block, and if it's uniformly 0xFF or uniformly 0x00, then it should call env_set_default(0,0) instead of env_set_default("bad CRC", 0). If I'm reading the code right, the only effect of this will be to suppress the warning message. Thanks for your consideration, zw ps. Can we be sure that the crc32 of ENV_SIZE bytes of 0xFF will _never_ be 0xFFFF and the crc32 of ENV_SIZE bytes of 0x00 will _never_ be 0x0000? If not, it might be wise to do the scans for blank flash/disk sectors _first_, rather than relying on the CRC to detect them.