[OpenWrt-Devel,1/2] gemini: Add copy-kernel utility package
diff mbox series

Message ID 20190717172332.8286-1-linus.walleij@linaro.org
State Accepted
Delegated to: Hauke Mehrtens
Headers show
Series
  • [OpenWrt-Devel,1/2] gemini: Add copy-kernel utility package
Related show

Commit Message

Linus Walleij July 17, 2019, 5:23 p.m. UTC
This package just contains a small Gemini-only assembler
bootstrap loop to copy the kernel from the two fragments
(previously zImage at 0x01600000 and initramdisk at 0x00800000)
into one big zImage of up to 8 MB at 0x00400000.

It will be built on demand from the Gemini image Makefile.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../linux/gemini/image/copy-kernel/.gitignore |  1 +
 .../linux/gemini/image/copy-kernel/Makefile   | 32 +++++++++++++
 .../gemini/image/copy-kernel/copy-kernel.S    | 45 +++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 target/linux/gemini/image/copy-kernel/.gitignore
 create mode 100644 target/linux/gemini/image/copy-kernel/Makefile
 create mode 100644 target/linux/gemini/image/copy-kernel/copy-kernel.S

Comments

Linus Walleij Aug. 9, 2019, 4:57 p.m. UTC | #1
On Wed, Jul 17, 2019 at 7:23 PM Linus Walleij <linus.walleij@linaro.org> wrote:

> This package just contains a small Gemini-only assembler
> bootstrap loop to copy the kernel from the two fragments
> (previously zImage at 0x01600000 and initramdisk at 0x00800000)
> into one big zImage of up to 8 MB at 0x00400000.
>
> It will be built on demand from the Gemini image Makefile.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Any comments on these two patches?

I have tested on both ITian Square One and the SL93512r
reference design, and I am pretty confident that the
Raidsonic 4220B "IcyBox" will also work with this approach,
but of course it is even nicer if someone tests it.

I do not flash my devices from the composite firmware
image actually: I use the RedBoot menu to flash
each of the files: "kernel", "ramdisk" and "application"
from the constituents. I think the composite firmware
image only works from the web-based upgrade utility,
the RedBoot "upgrade firmware" option is super dangerous
and will erase the whole flash and overwrite it with
whatever you send in.

I just extract the firmware files:
tar xvf openwrt-gemini-storlink_sl93512r-squashfs-factory.bin
then I flash
hddapp.tgz
rd.gz
zImage

From the different menu choices over TFTP.

Yours,
Linus Walleij

Patch
diff mbox series

diff --git a/target/linux/gemini/image/copy-kernel/.gitignore b/target/linux/gemini/image/copy-kernel/.gitignore
new file mode 100644
index 000000000000..e5939dfd9c2d
--- /dev/null
+++ b/target/linux/gemini/image/copy-kernel/.gitignore
@@ -0,0 +1 @@ 
+copy-kernel.bin
diff --git a/target/linux/gemini/image/copy-kernel/Makefile b/target/linux/gemini/image/copy-kernel/Makefile
new file mode 100644
index 000000000000..155c35968c68
--- /dev/null
+++ b/target/linux/gemini/image/copy-kernel/Makefile
@@ -0,0 +1,32 @@ 
+#
+# Makefile for Gemin kernel copy stub
+#
+# Copyright (C) 2019 Linus Walleij <linus.walleij@linaro.org>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+
+AS		:= $(CROSS_COMPILE)as
+OBJCOPY		:= $(CROSS_COMPILE)objcopy
+
+BIN_FLAGS	:= -O binary -S
+
+all: copy-kernel.bin
+
+# Don't build dependencies, this may die if $(CC) isn't gcc
+dep:
+
+install:
+
+%.o : %.S
+	$(AS) $(ASFLAGS) -k -o $@ $<
+
+%.bin: %.o
+	$(OBJCOPY) $(BIN_FLAGS) $< $@
+
+mrproper: clean
+
+clean:
+	rm -f copy-kernel.bin copy-kernel.o
diff --git a/target/linux/gemini/image/copy-kernel/copy-kernel.S b/target/linux/gemini/image/copy-kernel/copy-kernel.S
new file mode 100644
index 000000000000..a287e40defb6
--- /dev/null
+++ b/target/linux/gemini/image/copy-kernel/copy-kernel.S
@@ -0,0 +1,45 @@ 
+	// Arm assembly to copy the Gemini kernel on Storlink reference
+	// designs and derived devices with the same flash layout and
+	// boot loader.
+	//
+	// This will execute at 0x01600000
+	//
+	// Copies the kernel from two fragments (originally zImage
+	// and initramdisk) to 0x00400000 making space for a kernel
+	// image of up to 8 MB except for these 512 bytes used for
+	// this bootstrap.
+	//
+	// 0x01600200 .. 0x017fffff -> 0x00400000 .. 0x005ffdff
+	// 0x00800000 .. 0x00dfffff -> 0x005ffe00 .. 0x00bffdff
+
+	// Memory used for this bootstrap
+	.equ BOOT_HEADROOM,	0x200
+
+	.global _start // Stand-alone assembly code
+_start:
+	mov r1, #0x01600000
+	mov r2, #0x00400000
+	mov r3, #0x00200000
+	add r1, r1, #BOOT_HEADROOM
+	sub r3, r3, #BOOT_HEADROOM
+copyloop1:
+	ldr r0, [r1]
+	str r0, [r2]
+	add r1, r1, #4
+	add r2, r2, #4
+	sub r3, r3, #4
+	cmp r3, #0
+	bne copyloop1
+	mov r1, #0x00800000
+	mov r3, #0x00600000
+copyloop2:
+	ldr r0, [r1]
+	str r0, [r2]
+	add r1, r1, #4
+	add r2, r2, #4
+	sub r3, r3, #4
+	cmp r3, #0
+	bne copyloop2
+	mov r0, #0x00400000
+	// Let's go
+	mov pc, r0