From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=bto79smp; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.67, mailfrom: pete@akeo.ie) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by groups.io with SMTP; Fri, 23 Aug 2019 05:21:06 -0700 Received: by mail-wm1-f67.google.com with SMTP id p74so8715277wme.4 for ; Fri, 23 Aug 2019 05:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NpbuaTEQzDk+j+IvSN/7k+tq7UofTsCOauxo6iB0ejk=; b=bto79smp6f+I0dDouCW6AHEG53b1ZKilRqOySK9V+Xs9jLKFig4/qGNxeuELcC5yHo 0DniA8oDfL/UFJWyxc85jo0konOWnaeEIz0ewK2aLqKzsNJ7/MIqmrzjqTHWOXO7mCjw LKHUUGbYNPel8pYhv/LpJvnfGtZsxrhxdndG8L4ufHp2ytjV5w4VIyCCWnqYfOL8flAV myn12vJx7jijw8dDXBG2xBsvPKzqj5k1/PqVJgtiEzVxakR18HCNqgpLjr7FrBNO4Djm FqOMx6P1AkpAnTXQFyzsGdrLrtGTQyOidSKwotVbFjjpG0rc71NZD5T0KkRtcdUKIPHV PhgA== 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=NpbuaTEQzDk+j+IvSN/7k+tq7UofTsCOauxo6iB0ejk=; b=MEZBBhFNqsISfJEUXZEpugKuafL7/xdnwBgSnd/pb+xpy4GnRpjDrfvTf2bns3jj7A e50Rs1gQDqiAi+GeE/WzDgEVIQCWS6uS+tCYc0EDOR8bnvHunhD6xPlI0NKHzjn6ZQb9 m1pI4s7RLDCyetGIWPOeIOauab5ZiinzbVPNzdeyul+QwVf/5ABFpH3AI8TSQ7fta+Oh oErC9xvR5nc6HaFlQyD6wLTZgobHbFR+Yr8Ua2+6pgvVPZl5wT9aRycnaEU6xCYwZ8dt SqwW9siyS3+G+aSCHztcVYJM6vc85E5J80JcRMPt8ykHSGLenRALhC+eYJBmqeYQ0dXf YItA== X-Gm-Message-State: APjAAAWKvyXJfSMG5plz3iNZDoal4z4iUtqB6raGidsiIiNlFkW4LBF7 twAjwuU7owBUzCmCCKT+rI8ulkEqP14= X-Google-Smtp-Source: APXvYqxtZYlGRN0A/f45Z9ic+nOOKLSS+hK1yYYpgdmAmKhjgLyQ0lYgtzg1zcdUZJl8bhYIrOCMXw== X-Received: by 2002:a7b:c947:: with SMTP id i7mr5079843wml.77.1566562863990; Fri, 23 Aug 2019 05:21:03 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.87.76]) by smtp.gmail.com with ESMTPSA id s19sm4634342wrb.94.2019.08.23.05.21.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 05:21:03 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org Subject: [edk2-platforms: PATCH v2 1/1] Platform/Rpi3: Add compatible property to the "usb" Device Tree node Date: Fri, 23 Aug 2019 13:20:50 +0100 Message-Id: <20190823122050.5244-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190823122050.5244-1-pete@akeo.ie> References: <20190823122050.5244-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some Linux kernels (e.g. Debian) require "bcm,bcm2835-usb" to be present in the list of compatible properties for the "usb" node, else they are unable to handle some USB devices. This patch ensures that the compatible property is added if not present. Signed-off-by: Pete Batard --- Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c | 75 ++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c index 45ffe2e394a2..eb8048930c30 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c @@ -135,6 +135,76 @@ UpdateMacAddress ( return EFI_SUCCESS; } +// +// Add "bcm2835-usb" to the USB compatible property list, if not present. +// Required because some Linux kernels can't handle USB devices otherwise. +// +STATIC +EFI_STATUS +AddUsbCompatibleProperty ( + VOID + ) +{ + CONST CHAR8 Prop[] = "brcm,bcm2708-usb"; + CONST CHAR8 NewProp[] = "brcm,bcm2835-usb"; + CONST CHAR8 *List; + CHAR8 *NewList; + INT32 ListSize; + INTN Node; + INTN Retval; + + // Locate the node that the 'usb' alias refers to + Node = fdt_path_offset (mFdtImage, "usb"); + if (Node < 0) { + DEBUG ((DEBUG_ERROR, "%a: failed to locate 'usb' alias\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + + // Get the property list. This is a list of NUL terminated strings. + List = fdt_getprop (mFdtImage, Node, "compatible", &ListSize); + if (List == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to locate properties\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + + // Check if the compatible value we plan to add is already present + if (fdt_stringlist_contains (List, ListSize, NewProp)) { + DEBUG ((DEBUG_INFO, "%a: property '%a' is already set.\n", + __FUNCTION__, NewProp)); + return EFI_SUCCESS; + } + + // Make sure the compatible device is what we expect + if (!fdt_stringlist_contains (List, ListSize, Prop)) { + DEBUG ((DEBUG_ERROR, "%a: property '%a' is missing!\n", + __FUNCTION__, Prop)); + return EFI_NOT_FOUND; + } + + // Add the new NUL terminated entry to our list + DEBUG ((DEBUG_INFO, "%a: adding '%a' to the properties\n", + __FUNCTION__, NewProp)); + + NewList = AllocatePool (ListSize + sizeof (NewProp)); + if (NewList == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to allocate memory\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES;; + } + CopyMem (NewList, List, ListSize); + CopyMem (&NewList[ListSize], NewProp, sizeof (NewProp)); + + Retval = fdt_setprop (mFdtImage, Node, "compatible", NewList, + ListSize + sizeof (NewProp)); + FreePool (NewList); + if (Retval != 0) { + DEBUG ((DEBUG_ERROR, "%a: failed to update properties (%d)\n", + __FUNCTION__, Retval)); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + STATIC EFI_STATUS CleanMemoryNodes ( @@ -486,6 +556,11 @@ FdtDxeInitialize ( Print (L"Failed to update MAC address: %r\n", Status); } + Status = AddUsbCompatibleProperty (); + if (EFI_ERROR (Status)) { + Print (L"Failed to update USB compatible properties: %r\n", Status); + } + if (Internal) { /* * A GPU-provided DTB already has the full command line. -- 2.21.0.windows.1