0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

玄箱 初代用カーネル ARCH=powerpc のビルド

0
Last updated at Posted at 2025-06-24

Linux カーネル ビルド経験者向けです

最近では入手困難なビッグエンディアン機なので引っ張り出してみた。

実行環境

U-Boot化済み玄箱(初代)を使用
U-Boot 1.1.4 LiSt 2.1.0 (Sep 21 2006 - 00:22:56) LinkStation / KuroBox
  1. EM モードにする
  2. Version 1.02 をインストール
  3. Debian化 (U-Boot から uImage を起動)
  4. Linux カーネル 2.6.25 をビルド&インストール

で初期化からやり直し。

カーネルを 2.6.39.4 に更新

ARCH=ppcARCH=powerpc

カーネル 2.6.26 までは make ARCH=

  • ppc
  • powerpc

の両方でビルドできるようです。主な違いは

ARCH ppc powerpc
uImage生成場所 arch/ppc/boot/images arch/powerpc/boot
bootargs引数 root=/dev/hda1 root=/dev/sda1
デバイス情報
(devtree)
不要 cuImage形式か
initrdに含める

ARCH=powerpcでのビルド

ARCH=ppcでのビルドについては既に目にしていると思うので省略します。また、カーネル 2.6.27 以降ではARCH=ppcが使用できません。

cuImage.kuroboxHDのビルド

ARCH=powerpcでビルドしたuImageファイルはデバイス(devtree)情報が外部依存なので、ARCH=ppcでのビルドしたuImageを置換しても動作しません。(initrdの扱い方次第かもしれませんが)

uImage+devtreeuImageとして再構成するcuImage.BOARDが用意されています。生成されるcuImage.kuroboxHDファイルをuImageとして使用します。

kernel.org で配布されているソースコードではエラーが出るので以下のパッチを当てます。

linux-2.6.39.4-kurbox.patch
diff -urN linux-2.6.39.4.orig/arch/powerpc/boot/Makefile linux-2.6.39.4/arch/powerpc/boot/Makefile
--- linux-2.6.39.4.orig/arch/powerpc/boot/Makefile	2011-08-04 04:43:28.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/Makefile	2025-06-25 20:50:49.742831756 +0900
@@ -78,6 +78,7 @@
 		cuboot-warp.c cuboot-85xx-cpm2.c cuboot-yosemite.c simpleboot.c \
 		virtex405-head.S virtex.c redboot-83xx.c cuboot-sam440ep.c \
 		cuboot-acadia.c cuboot-amigaone.c cuboot-kilauea.c \
+		cuboot-kuroboxHD.c cuboot-kuroboxHG.c \
 		gamecube-head.S gamecube.c wii-head.S wii.c treeboot-iss4xx.c
 src-boot := $(src-wlib) $(src-plat) empty.c
 
diff -urN linux-2.6.39.4.orig/arch/powerpc/boot/cuboot-kuroboxHD.c linux-2.6.39.4/arch/powerpc/boot/cuboot-kuroboxHD.c
--- linux-2.6.39.4.orig/arch/powerpc/boot/cuboot-kuroboxHD.c	1970-01-01 09:00:00.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/cuboot-kuroboxHD.c	2025-06-23 18:41:38.897745033 +0900
@@ -0,0 +1 @@
+#include "cuboot-824x.c"
diff -urN linux-2.6.39.4.orig/arch/powerpc/boot/cuboot-kuroboxHG.c linux-2.6.39.4/arch/powerpc/boot/cuboot-kuroboxHG.c
--- linux-2.6.39.4.orig/arch/powerpc/boot/cuboot-kuroboxHG.c	1970-01-01 09:00:00.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/cuboot-kuroboxHG.c	2025-06-25 20:51:18.570832026 +0900
@@ -0,0 +1 @@
+#include "cuboot-824x.c"
--- linux-2.6.39.4.orig/arch/powerpc/boot/dts/kuroboxHD.dts	2011-08-04 04:43:28.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/dts/kuroboxHD.dts	2025-08-17 07:31:04.043431169 +0900
@@ -64,7 +64,8 @@
 			  0xfc000000 0xfc000000 0x100000	/* EUMB */
 			  0xfe000000 0xfe000000 0xc00000	/* pci i/o space */
 			  0xfec00000 0xfec00000 0x300000	/* pci cfg regs */
-			  0xfef00000 0xfef00000 0x100000>;	/* pci iack */
+			  0xfef00000 0xfef00000 0x100000	/* pci iack */
+			  0xffc00000 0xffc00000 0x400000>;	/* flash */
 
 		i2c@80003000 {
 			#address-cells = <1>;
@@ -81,25 +82,25 @@
 			};
 		};
 
-		serial0: serial@80004500 {
+		serial0: serial@80004600 {
 			cell-index = <0>;
 			device_type = "serial";
 			compatible = "ns16550";
-			reg = <0x80004500 0x8>;
+			reg = <0x80004600 0x8>;
 			clock-frequency = <97553800>;
-			current-speed = <9600>;
-			interrupts = <9 0>;
+			current-speed = <57600>;
+			interrupts = <10 0>;
 			interrupt-parent = <&mpic>;
 		};
 
-		serial1: serial@80004600 {
+		serial1: serial@80004500 {
 			cell-index = <1>;
 			device_type = "serial";
 			compatible = "ns16550";
-			reg = <0x80004600 0x8>;
+			reg = <0x80004500 0x8>;
 			clock-frequency = <97553800>;
-			current-speed = <57600>;
-			interrupts = <10 0>;
+			current-speed = <9600>;
+			interrupts = <9 0>;
 			interrupt-parent = <&mpic>;
 		};
 
@@ -143,5 +144,48 @@
 				0x7000 0x0 0x0 0x4 &mpic 0x3 0x1
 			>;
 		};
+
+		flash@ffc00000 {
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0xffc00000 0x400000>;
+
+			compatible = "cfi-flash";
+			bank-width = <1>;
+			erase-size = <0x10000>;
+
+			settings@380000 {
+				label = "settings";
+				reg = <0x380000 0x80000>;
+				read-only;
+			};
+			firmware@0 {
+				label = "firmware";
+				reg = <0x0 0x300000>;
+				read-only;
+			};
+			boot@300000 {
+				label = "boot";
+				reg = <0x300000 0x70000>;
+				read-only;
+			};
+			mode@370000 {
+				label = "mode";
+				reg = <0x370000 0x10000>;
+			};
+			full@0 {
+				label = "full";
+				reg = <0x0 0x400000>;
+				read-only;
+			};
+			ubootenv@360000 {
+				label = "ubootenv";
+				reg = <0x360000 0x10000>;
+			};
+		};
+	};
+
+	chosen {
+		linux,stdout-path = "/soc10x/serial@80004600";
 	};
 };
--- linux-2.6.39.4.orig/arch/powerpc/boot/dts/kuroboxHG.dts	2011-08-04 04:43:28.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/dts/kuroboxHG.dts	2025-08-17 07:32:43.978541537 +0900
@@ -64,7 +64,8 @@
 			  0xfc000000 0xfc000000 0x100000	/* EUMB */
 			  0xfe000000 0xfe000000 0xc00000	/* pci i/o space */
 			  0xfec00000 0xfec00000 0x300000	/* pci cfg regs */
-			  0xfef00000 0xfef00000 0x100000>;	/* pci iack */
+			  0xfef00000 0xfef00000 0x100000	/* pci iack */
+			  0xffc00000 0xffc00000 0x400000>;	/* flash */
 
 		i2c@80003000 {
 			#address-cells = <1>;
@@ -81,25 +82,25 @@
 			};
 		};
 
-		serial0: serial@80004500 {
+		serial0: serial@80004600 {
 			cell-index = <0>;
 			device_type = "serial";
 			compatible = "ns16550";
-			reg = <0x80004500 0x8>;
+			reg = <0x80004600 0x8>;
 			clock-frequency = <130041000>;
-			current-speed = <9600>;
-			interrupts = <9 0>;
+			current-speed = <57600>;
+			interrupts = <10 0>;
 			interrupt-parent = <&mpic>;
 		};
 
-		serial1: serial@80004600 {
+		serial1: serial@80004500 {
 			cell-index = <1>;
 			device_type = "serial";
 			compatible = "ns16550";
-			reg = <0x80004600 0x8>;
+			reg = <0x80004500 0x8>;
 			clock-frequency = <130041000>;
-			current-speed = <57600>;
-			interrupts = <10 0>;
+			current-speed = <9600>;
+			interrupts = <9 0>;
 			interrupt-parent = <&mpic>;
 		};
 
@@ -143,5 +144,48 @@
 				0x7000 0x0 0x0 0x4 &mpic 0x3 0x1
 			>;
 		};
+
+		flash@ffc00000 {
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0xffc00000 0x400000>;
+
+			compatible = "cfi-flash";
+			bank-width = <1>;
+			erase-size = <0x10000>;
+
+			settings@380000 {
+				label = "settings";
+				reg = <0x380000 0x80000>;
+				read-only;
+			};
+			firmware@0 {
+				label = "firmware";
+				reg = <0x0 0x300000>;
+				read-only;
+			};
+			boot@300000 {
+				label = "boot";
+				reg = <0x300000 0x70000>;
+				read-only;
+			};
+			mode@370000 {
+				label = "mode";
+				reg = <0x370000 0x10000>;
+			};
+			full@0 {
+				label = "full";
+				reg = <0x0 0x400000>;
+				read-only;
+			};
+			ubootenv@360000 {
+				label = "ubootenv";
+				reg = <0x360000 0x10000>;
+			};
+		};
+	};
+
+	chosen {
+		linux,stdout-path = "/soc10x/serial@80004600";
 	};
 };

kuroboxHD.dts へのパッチは

  • ttyS0 : コンソール
  • ttyS1 : AVR
  • mtdblockN : /dev/flN に対応
  • mtdblock5 : U-Boot 変数

となっています。

wrapperの変更

ブート時のカーネル ロード アドレスの取り回しが

ARCH=ppcの場合

  1. U-Boot がuImageを U-Boot 変数ldaddrに読み込む
  2. uImage内のzImage00000へ展開
  3. 00000へジャンプしてカーネル開始

ARCH=powerpcの場合

  1. U-Boot がuImage(cuImage)を U-Boot 変数ldaddrに読み込む
  2. cuImage内のuImagecuImage内にあるアドレスへ展開
  3. uImage内のzImage00000へ展開
  4. 00000へジャンプしてカーネル開始

となるので、両方で動作するには、U-Boot の変数をldaddr=1000000に設定して、cuImage展開アドレスを以下のパッチで指定します。

arch/powerpc/boot/wrapper.patch
diff -ur linux-2.6.39.4.orig/arch/powerpc/boot/wrapper linux-2.6.39.4/arch/powerpc/boot/wrapper
--- linux-2.6.39.4.orig/arch/powerpc/boot/wrapper	2011-08-04 04:43:28.000000000 +0900
+++ linux-2.6.39.4/arch/powerpc/boot/wrapper	2025-06-25 21:01:45.350824957 +0900
@@ -197,6 +197,9 @@
     *-amigaone)
         link_address='0x800000'
         ;;
+    *-kuroboxHD|*-kuroboxHG)
+        link_address='0x800000'
+	;;
     esac
     ;;
 ps3)

ビルド

コマンドライン引数にはcuImage.kuroboxHDが必要です。

cuImage.kuroboxHDのビルド
$ make cuImage.kuroboxHD modules    # クロスコンパイルでは必要に応じて引数追加

玄箱でビルドすると数時間かかります。手元の環境でクロスコンパイルすると数分(体感50倍以上)で終わります。

実行

手元の環境ではルートディレクトリに/uImage-testを置いてテスト用として起動するように U-Boot を設定しています。

実行結果(wrapperパッチなし)
Loading 0:1:uImage-test

1927824 bytes read
## Booting image at 01000000 ...
   Image Name:   Linux-2.6.39.4-kurobox-1
   Image Type:   PowerPC Linux Kernel Image (gzip compressed)
   Data Size:    1927760 Bytes =  1.8 MB
   Load Address: 00400000
   Entry Point:  00400550
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
Memory <- <0x0 0x4000000> (64MB)
CPU clock-frequency <- 0xbb80000 (197MHz)
CPU timebase-frequency <- 0x1770000 (25MHz)
CPU bus-frequency <- 0x5dc0000 (98MHz)

zImage starting: loaded at 0x00400000 (sp: 0x03e6f600)
Allocating 0x4b8e94 bytes for kernel ...
gunzipping (0x00000000 <- 0x0040c000:0x007bdac8)...done 0x3a1360 bytes

Linux/PowerPC load: root=/dev/sda1
Finalizing device tree... flat tree at 0x7ca300
Using Buffalo Linkstation machine description
Linux version 2.6.39.4-kurobox-1 (ikiuo@debian7x) (gcc version 4.7.2 (GCC) ) #10 Wed Jun 25 15:58:28 JST 2025
bootconsole [udbg0] enabled
Adding PCI host bridge /soc10x/pci@fec00000
PCI host bridge /soc10x/pci@fec00000 (primary) ranges:

デバイス ファイル

udev/dev以下にファイルが欲しいときの対応方法

/dev/AVR00

/etc/udev/rules.d/00-avr.rules
KERNEL=="ttyS1",SYMLINK+="AVR00",MODE="0660"

/dev/rtc

/etc/udev/rules.d/00-rtc.rules
KERNEL=="rtc0",SYMLINK+="rtc",MODE="0660"

/dev/fl?

以下のファイルを作る

/etc/udev/rules.d/00-flash.rules
SUBSYSTEM=="mtd",RUN+="/sbin/modprobe mtdblock"
KERNEL=="mtdblock0",SYMLINK+="fl0",MODE="0660"
KERNEL=="mtdblock1",SYMLINK+="fl1",MODE="0660"
KERNEL=="mtdblock2",SYMLINK+="fl2",MODE="0660"
KERNEL=="mtdblock3",SYMLINK+="fl3",MODE="0660"
KERNEL=="mtdblock4",SYMLINK+="fl4",MODE="0660"
KERNEL=="mtdblock5",SYMLINK+="ubootenv",MODE="0660"

.dtsのパッチではmtdblock3,mtdblock5以外は書き込み禁止にしてあります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?