From 19fcd263d0e7a61fdcd458a93875a537f421f5fb Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Thu, 23 Mar 2017 09:37:57 +1100
Subject: [PATCH] Add default PPC block-device layout

Add a default PPC block-device layout.  I've extracted this into
separate yaml files for ease of editing and to facilitate things like
longer comments.

This is not sufficient to get PPC images working, but it is required.

Change-Id: I09e5d1ed92260bdb632333f5203dd7e70d512dc8
---
 .../elements/vm/block-device-default.yaml     | 12 ++++++++
 .../elements/vm/block-device-ppc.yaml         | 30 +++++++++++++++++++
 .../elements/vm/environment.d/10-partitioning | 21 +++++++------
 3 files changed, 52 insertions(+), 11 deletions(-)
 create mode 100644 diskimage_builder/elements/vm/block-device-default.yaml
 create mode 100644 diskimage_builder/elements/vm/block-device-ppc.yaml

diff --git a/diskimage_builder/elements/vm/block-device-default.yaml b/diskimage_builder/elements/vm/block-device-default.yaml
new file mode 100644
index 000000000..85b41a3b7
--- /dev/null
+++ b/diskimage_builder/elements/vm/block-device-default.yaml
@@ -0,0 +1,12 @@
+# Default single partition loopback
+
+- local_loop:
+    name: image0
+
+- partitioning:
+   base: image0
+   label: mbr
+   partitions:
+     - name: root
+       flags: [ boot, primary ]
+       size: 100%
diff --git a/diskimage_builder/elements/vm/block-device-ppc.yaml b/diskimage_builder/elements/vm/block-device-ppc.yaml
new file mode 100644
index 000000000..2b3a78ddf
--- /dev/null
+++ b/diskimage_builder/elements/vm/block-device-ppc.yaml
@@ -0,0 +1,30 @@
+# Default block device setup for PPC
+# ----------------------------------
+#
+# Details (extracted from [1])
+#
+# Power Firmware (OFW) scans chosen (nvram value boot-device) device,
+# for either PReP* partition or vfat.
+#
+# PReP is raw and small (8M max) partition which caries only stage1
+# binary.
+#  msdos partition table:
+#   - PReP partition have 0x41 type (must be active)
+#   - PReP partition must have boot flag set
+#
+# [1] https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/W51a7ffcf4dfd_4b40_9d82_446ebc23c550/page/PowerLinux%20Boot%20howto
+
+- local_loop:
+    name: image0
+
+- partitioning:
+    base: image0
+    label: mbr
+    partitions:
+      - name: boot
+        flags: [ boot, primary ]
+        type: '0x41'
+        size: 8MiB
+      - name: root
+        flags: [ primary ]
+        size: 100%
diff --git a/diskimage_builder/elements/vm/environment.d/10-partitioning b/diskimage_builder/elements/vm/environment.d/10-partitioning
index 186ea6a1d..7aeea5a3d 100644
--- a/diskimage_builder/elements/vm/environment.d/10-partitioning
+++ b/diskimage_builder/elements/vm/environment.d/10-partitioning
@@ -1,15 +1,14 @@
-export DIB_BLOCK_DEVICE_DEFAULT_CONFIG="
-- local_loop:
-    name: image0
+_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-- partitioning:
-   base: image0
-   label: mbr
-   partitions:
-     - name: root
-       flags: [ boot, primary ]
-       size: 100%
-"
+if [[ "$ARCH" =~ "ppc" ]] ; then
+    DIB_BLOCK_DEVICE_DEFAULT_CONFIG="$(cat $_DIR/../block-device-ppc.yaml)"
+else
+    DIB_BLOCK_DEVICE_DEFAULT_CONFIG="$(cat $_DIR/../block-device-default.yaml)"
+fi
 
 DIB_BLOCK_DEVICE_CONFIG=${DIB_BLOCK_DEVICE_CONFIG:-${DIB_BLOCK_DEVICE_DEFAULT_CONFIG}}
 export DIB_BLOCK_DEVICE_CONFIG
+
+# Local variables:
+# mode: sh
+# End: