Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v1 3/9] board/intel/common: Add possibility for adding ACPI tables to the initrd
Date: Thu, 25 Aug 2016 17:04:41 +0300	[thread overview]
Message-ID: <1472133887-34746-4-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <1472133887-34746-1-git-send-email-andriy.shevchenko@linux.intel.com>

Add script which takes ASL files as input, compiles them to AML bytecode,
and prepends the whole thing to the initrd archive. They are placed in
kernel/firmware/acpi directory where the kernel is able to find and use
them.

The script requires iasl host tool that would be provided by acpica package.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 board/intel/common/README.rst                  | 19 +++++-
 board/intel/common/post-image.d/80-acpi-tables | 86 ++++++++++++++++++++++++++
 configs/intel_defconfig                        |  3 +
 3 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100755 board/intel/common/post-image.d/80-acpi-tables

diff --git a/board/intel/common/README.rst b/board/intel/common/README.rst
index e427067..f7f677e 100644
--- a/board/intel/common/README.rst
+++ b/board/intel/common/README.rst
@@ -52,6 +52,9 @@ like::
 
 in order to take advantage of these.
 
+BOARD_INTEL_ACPI_TABLES
+	list of table names to built into the ``initrd``.
+
 BOARD_INTEL_CUSTOM_CMDLINE
 	provides a custom appendix to the command line.
 
@@ -68,6 +71,20 @@ By default ``ttyS0`` is used as a default cosole for both kernel and userspace.
 The **BR2_TARGET_GENERIC_GETTY_PORT** variable could be used to alterate this
 setting.
 
+Adding custom ACPI SSDT tables
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can add additional ACPI tables to the ``initrd`` (think of device tree
+overlays) if you need to have some special devices for example. The ASL files
+should be stored in board specific directories as they vary from one board to
+another. Below we add SPI test device for Intel `Joule`_ board::
+
+	% make KERNEL_SRC=~/linux BR2_TARGET_GENERIC_GETTY_PORT=ttyS2		\
+				  BOARD_INTEL_DIR=board/intel/joule		\
+				  BOARD_INTEL_ACPI_TABLES=spidev.asl
+
+The resulting image is called ``output/images/joule-acpi-rootfs.cpio``.
+
 Supported boards
 ~~~~~~~~~~~~~~~~
 
@@ -85,7 +102,7 @@ Examples
 
 	% make KERNEL_SRC=~/linux BR2_TARGET_GENERIC_GETTY_PORT=ttyS1
 
-- Joule (Broxton), Edison (Merrifield)::
+- _`Joule` (Broxton), Edison (Merrifield)::
 
 	% make KERNEL_SRC=~/linux BR2_TARGET_GENERIC_GETTY_PORT=ttyS2
 
diff --git a/board/intel/common/post-image.d/80-acpi-tables b/board/intel/common/post-image.d/80-acpi-tables
new file mode 100755
index 0000000..c9495d8
--- /dev/null
+++ b/board/intel/common/post-image.d/80-acpi-tables
@@ -0,0 +1,86 @@
+#!/bin/sh -e
+
+#
+# Copyright (c) 2016 Intel Corp.
+#
+
+#
+# Environment:
+#
+# BOARD_INTEL_ACPI_TABLES	- ASL files to build separated by spaces
+#
+# BOARD_INTEL_DIR		- Directory holding board specific
+# 				  configuration. Should contain directory
+# 				  called "acpi" which holds the ASL tables.
+#
+# For example following variables compile two ACPI SSDTs into updated
+# initrd image called $BINARIES_DIR/joule-acpi-rootfs.cpio.
+#
+# BOARD_INTEL_DIR="board/intel/joule"
+# BOARD_INTEL_ACPI_TABLES="at25.asl spidev.asl"
+#
+
+PROG_NAME="${0##*/}"
+PROG_DIR="${0%/*}"
+
+. $PROG_DIR/../libshell-intel
+
+ACPI_DIR="$(intel_folder_lookup "acpi")"
+ACPI_TABLES="$BOARD_INTEL_ACPI_TABLES"
+
+[ -d "$ACPI_DIR" ] || exit 0
+[ -z "$ACPI_TABLES" ] && exit 0
+
+# Pick iASL.
+# First try from buildroot and if not there then try from the host.
+[ -x "$HOST_DIR/usr/bin/iasl" ] && iasl="$HOST_DIR/usr/bin/iasl" || iasl=$(which iasl)
+
+[ -x "$iasl" ] || {
+	echo "You need to to have iASL compiler available. You can either enable"
+	echo "BR2_PACKAGE_HOST_ACPICA or install it locally for your host."
+	echo "Typically the package is called acpica-tools in major distros".
+	exit 1
+}
+
+# The name of the folder is the name of a board
+board_name="${BOARD_DIR##*/}"
+[ "$board_name" = "common" ] && {
+	echo "Adding ACPI tables is always specific to a board!"
+	echo "You are not supposed to use common as board here!"
+	exit 1
+}
+
+# Always prefix with the board name to avoid mistakes if the initrd is used
+# with another board.
+updated_initrd_name="${board_name}-acpi-rootfs.cpio"
+updated_initrd="$BINARIES_DIR/$updated_initrd_name"
+initrd="$(readlink -enq "$BINARIES_DIR/initrd")"
+tmpamldir="$BINARIES_DIR/acpi-tables"
+
+# Make sure existing tables get cleared
+rm -fr $tmpamldir
+mkdir -p $tmpamldir/kernel/firmware/acpi
+
+for table in $ACPI_TABLES; do
+	[ -f "$ACPI_DIR/$table" ] || continue
+
+	$iasl -p $tmpamldir/kernel/firmware/acpi/$table "$ACPI_DIR/$table" > /dev/null 2>&1
+
+	echo "ACPI: Compiled ASL from $(realpath --relative-to=$PWD $ACPI_DIR/$table)"
+done
+
+# Exit if no tables were compiled
+[ -n "$(find $tmpamldir -type f)" ] || {
+	echo "ACPI: No tables were compiled"
+	exit 0
+}
+
+# Attach compiled tables to initrd
+(
+	cd $tmpamldir
+	find kernel | cpio -H newc -o > $updated_initrd 2>/dev/null
+	cat $initrd >> $updated_initrd
+	ln -sf "$updated_initrd_name" "$BINARIES_DIR/initrd"
+)
+
+echo "ACPI: Created initrd with updated ACPI tables in $(realpath --relative-to=$PWD $updated_initrd)"
diff --git a/configs/intel_defconfig b/configs/intel_defconfig
index 8aff9e1..24167fc 100644
--- a/configs/intel_defconfig
+++ b/configs/intel_defconfig
@@ -17,6 +17,9 @@ BR2_ROOTFS_POST_BUILD_SCRIPT="board/intel/common/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/intel/common/post-image.sh"
 BR2_ROOTFS_POST_SCRIPT_ARGS=""
 
+# Host tools
+BR2_PACKAGE_HOST_ACPICA=y
+
 # Busybox utilities (target)
 BR2_PACKAGE_BUSYBOX_WATCHDOG=y
 
-- 
2.8.1

  parent reply	other threads:[~2016-08-25 14:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 14:04 [Buildroot] [PATCH v1 0/9] board: introduce common infrastructure for Intel SoCs Andy Shevchenko
2016-08-25 14:04 ` [Buildroot] [PATCH v1 1/9] package/acpica: Add host configuration to the tool Andy Shevchenko
2016-08-25 21:44   ` Thomas Petazzoni
2016-08-26 10:50   ` Erico Nunes
2016-08-25 14:04 ` [Buildroot] [PATCH v1 2/9] board/intel/common: Add common files for x86 boards Andy Shevchenko
2016-08-25 21:37   ` Thomas Petazzoni
2016-08-26 16:42   ` Arnout Vandecappelle
2016-08-25 14:04 ` Andy Shevchenko [this message]
2016-08-25 21:43   ` [Buildroot] [PATCH v1 3/9] board/intel/common: Add possibility for adding ACPI tables to the initrd Thomas Petazzoni
2016-08-26  6:13   ` Arnout Vandecappelle
2016-08-26  8:39     ` Thomas Petazzoni
     [not found]     ` <20160826090454.GK1812@lahna.fi.intel.com>
2016-08-26  9:30       ` Thomas Petazzoni
     [not found]         ` <20160826093901.GO1812@lahna.fi.intel.com>
2016-08-26 13:28           ` Thomas Petazzoni
2016-08-26 16:30           ` Arnout Vandecappelle
     [not found]             ` <20160829065522.GV1812@lahna.fi.intel.com>
2016-08-29  7:45               ` Arnout Vandecappelle
     [not found]                 ` <20160829075810.GA1709@lahna.fi.intel.com>
2016-08-29  9:08                   ` Arnout Vandecappelle
2016-08-25 14:04 ` [Buildroot] [PATCH v1 4/9] board / intel: Add SPI peripherals for Minnowboard MAX Andy Shevchenko
2016-08-25 21:47   ` Thomas Petazzoni
     [not found]     ` <20160826090917.GL1812@lahna.fi.intel.com>
2016-08-26  9:26       ` Thomas Petazzoni
2016-08-25 14:04 ` [Buildroot] [PATCH v1 5/9] board / intel: Add SPI peripherals for Joule Andy Shevchenko
2016-08-25 14:04 ` [Buildroot] [PATCH v1 6/9] board / intel: Add Aosong AM2315 sensor for Intel Joule Andy Shevchenko
2016-08-25 14:04 ` [Buildroot] [PATCH v1 7/9] board / intel: Add GPIO LEDs " Andy Shevchenko
2016-08-25 14:04 ` [Buildroot] [PATCH v1 8/9] board / intel: Add GPIO LEDs for Intel Minnowboard Andy Shevchenko
2016-08-25 14:04 ` [Buildroot] [PATCH v1 9/9] board / intel: Add GPIO buttons " Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472133887-34746-4-git-send-email-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox