venerdì 17 aprile 2009

Early Armadillo 500 support (the last?)

Ok, after reviewing mechanism this is the patch that give early support to the Atmark Armadillo 500 dev board.
The patch apply to the latests kernel source obtained by
git pull
in the root local git repository.

0001-Initial-support-for-Atmark-Armadillo-500-developing.patch

mercoledì 15 aprile 2009

Author and name on Git configuration

From: http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

$ git config --global user.name "Alberto Panizzo"
$ git config --global user.email maramaopercheseimorto@gmail.com

Early Armadillo 500 support

Ok! Now I am ready to post the first official Early Atmark Armadillo 500 developing board support patch!

This patch add the Armadillo 500 initial support. Enabling the mxc uart console via make gconfig (by default using make armadillo500_defconfig) we can see the console output through Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0).

To see debug strings on the console you have to apply the patch "Clock ipg_clk/ipg_per_clk synchronization" due to resolve clock the synchronization issue.

Patches attached because of changes made by this blog to the code style. (Indentation, ...)

0001-Initial-support-for-Atmark-Armadillo-500-developing.patch
0002-Add-armadillo500_defconfig-file-in-the-tree.patch
0003-Clock-ipg_clk-ipg_per_clk-synchronization.patch

Clock syncronization issue!

Time spent to analyse the imx console driver to found where is the bug that produce scrambling chars on the serial debug and the problem was not there!

The problem is ipg_clk/ipg_per_clk synchronization!
ipg_per_clk clock signal has two possible clock source decided by bit 24 (PERCS) of CCMR register.
On my armadillo 500 board the clock source was set to usb_pll instead of ipg_clk resulting on not synchronized clocks signals on the UART device! producing wired characters on the output.

This patch correct the issue, for me and also for all iMX31 boards (if misconfigured)

diff --git a/arch/arm/mach-mx3/clock.c b/arch/arm/mach-mx3/clock.c
index ca46f48..f1a581d 100644
--- a/arch/arm/mach-mx3/clock.c
+++ b/arch/arm/mach-mx3/clock.c
@@ -581,6 +581,11 @@ int __init mx31_clocks_init(unsigned long fref)
MX32, but still required to be set */
MXC_CCM_CGR2);

+ /* Ensure ipg_per_clk clock is generated by ipg_clk and not by
+ usb_pll (CCMR:24 = 1) to do not turn off UART after disabling
+ usb_pll and mantain ipg_clk and ipg_per_clk syncronization */
+ __raw_writel(__raw_readl(MXC_CCM_CCMR) | (1 << 24), MXC_CCM_CCMR);
+
usb_pll_disable(&usb_pll_clk);

pr_info("Clock input source is %ld\n", clk_get_rate(&ckih_clk));

giovedì 9 aprile 2009

Very Early Support!

Ook some time working and first code work fine.
This is the first debugging patch to the kernel vanilla 2.6.29 and the result is very early debug strings from /arch/arm/boot/compressed/head.S and /arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S printed on the serial port. And an Alive message that state all is gone ok before call start_kernel().
Ehm..! no debug output is shown after start_kernel call..
Next is porting ttymcx console driver to support printk() message printing.

The patch:
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index b371fba..5d08227 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -17,6 +17,9 @@
* 100% relocatable. Any attempt to do so will result in a crash.
* Please select one of the following when turning on debugging.
*/
+
+#define DEBUG 1
+
#ifdef DEBUG

#if defined(CONFIG_DEBUG_ICEDCC)
diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S
index 991952c..5d43cfa 100644
--- a/arch/arm/kernel/head-common.S
+++ b/arch/arm/kernel/head-common.S
@@ -50,7 +50,9 @@ __mmap_switched:
1: cmp r6, r7
strcc fp, [r6],#4
bcc 1b
-
+
+ bl __alive
+
ldmia r3, {r4, r5, r6, r7, sp}
str r9, [r4] @ Save processor ID
str r1, [r5] @ Save machine type
@@ -69,6 +71,16 @@ ENDPROC(__mmap_switched)
* and hope for the best (useful if bootloader fails to pass a proper
* machine ID for example).
*/
+__alive:
+ mov r10,r0
+ adr r0, str_a
+ bl printascii
+ mov r0,r10
+ mov pc, lr
+str_a: .asciz "\n Alive!\n"
+ .align
+ENDPROC(__alive)
+
__error_p:
#ifdef CONFIG_DEBUG_LL
adr r0, str_p1
diff --git a/arch/arm/mach-mx3/Kconfig b/arch/arm/mach-mx3/Kconfig
index d623558..4ac4337 100644
--- a/arch/arm/mach-mx3/Kconfig
+++ b/arch/arm/mach-mx3/Kconfig
@@ -64,4 +64,12 @@ config MACH_QONG
Include support for Dave/DENX QongEVB-LITE platform. This includes
specific configurations for the board and its peripherals.

+config MACH_ARMADILLO500
+ bool "Support Atmark Armadillo-500 Development Base Board"
+ select ARCH_MX31
+ default n
+ help
+ Include support for Atmark Armadillo-500 platform. This includes
+ specific configurations for the board and its peripherals.
+
endif
diff --git a/arch/arm/mach-mx3/Makefile b/arch/arm/mach-mx3/Makefile
index 272c8a9..4659598 100644
--- a/arch/arm/mach-mx3/Makefile
+++ b/arch/arm/mach-mx3/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_MACH_MX31_3DS) += mx31pdk.o
obj-$(CONFIG_MACH_MX31MOBOARD) += mx31moboard.o mx31moboard-devboard.o \
mx31moboard-marxbot.o
obj-$(CONFIG_MACH_QONG) += qong.o
+obj-$(CONFIG_MACH_ARMADILLO500) += armadillo5x0.o
diff --git a/arch/arm/mach-mx3/armadillo5x0.c b/arch/arm/mach-mx3/armadillo5x0.c
new file mode 100644
index 0000000..ae4e35e
--- /dev/null
+++ b/arch/arm/mach-mx3/armadillo5x0.c
@@ -0,0 +1,117 @@
+/*
+ * armadillo500.c
+ *
+ * Copyright 2009 Alberto Panizzo
+ * updates in http://alberdroid.blogspot.com/
+ *
+ * Based on Atmark Techno, Inc. armadillo 500 BSP 2008 All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include
+#include
+#include
+
+/* Define Machine specific Memory regions */
+#include
+/* All machine types definitions */
+#include
+/* Machine descriptor definition */
+#include
+/* Time keepeing definitions */
+#include
+/* Memory mapping functions */
+#include
+/* Define map_desc */
+#include
+
+/* Platform functions */
+#include
+#include
+
+
+
+static void __init armadillo5x0_init(void)
+{
+}
+
+/*!
+ * This structure defines static mappings for the i.MX31ADS board.
+ */
+static struct map_desc armadillo5x0_io_desc[] __initdata = {
+ /*{//Internal RAM
+ .virtual = MX31_IRAM_BASE_ADDR_VIRT,
+ .pfn = __phys_to_pfn(IRAM_BASE_ADDR),
+ .length = IRAM_SIZE,
+ .type = MT_NONSHARED_DEVICE},
+ },*//* {//ROM PATCH
+ .virtual = ROMP_BASE_ADDR_VIRT,
+ .pfn = __phys_to_pfn(ROMP_BASE_ADDR),
+ .length = ROMP_SIZE,
+ .type = MT_DEVICE_NONSHARED
+ },*/ {//Shared Perpheral Bus Arbiter
+ .virtual = SPBA0_BASE_ADDR_VIRT,
+ .pfn = __phys_to_pfn(SPBA0_BASE_ADDR),
+ .length = SPBA0_SIZE,
+ .type = MT_DEVICE_NONSHARED
+ }, {//NOR Flash memory (32 M)
+ .virtual = CS0_BASE_ADDR_VIRT,
+ .pfn = __phys_to_pfn(CS0_BASE_ADDR),
+ .length = CS0_SIZE,
+ .type = MT_DEVICE
+ }, {//Extended Bus Region
+ .virtual = CS4_BASE_ADDR_VIRT,
+ .pfn = __phys_to_pfn(CS4_BASE_ADDR),
+ .length = CS4_SIZE,
+ .type = MT_DEVICE
+ },
+};
+
+/*!
+ * Set up static virtual mappings.
+ */
+static void __init armadillo5x0_map_io(void)
+{
+ /*
+ * Maps:
+ * - NAND, SDRAM, WEIM, M3IF, EMI controllers
+ * - AVIC (Vectored Interrupt controller)
+ * - AIPS1 and AIPS2
+ **/
+ mxc_map_io();
+ iotable_init(armadillo5x0_io_desc, ARRAY_SIZE(armadillo5x0_io_desc));
+}
+
+static void __init armadillo5x0_timer_init(void)
+{
+ mx31_clocks_init(26000000);
+}
+
+static struct sys_timer armadillo5x0_timer = {
+ .init = armadillo5x0_timer_init,
+};
+
+MACHINE_START(ARMADILLO5X0, "Armadillo-500")
+ /* Maintainer: Atmark Techno, Inc. */
+ .phys_io = AIPS1_BASE_ADDR,
+ .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+ .boot_params = PHYS_OFFSET + 0x00000100,
+ //.map_io = armadillo5x0_map_io,
+ //.init_irq = mxc_init_irq,
+ //.timer = &armadillo5x0_timer,
+ //.init_machine = armadillo5x0_init,
+MACHINE_END
diff --git a/arch/arm/plat-mxc/include/mach/board-armadillo5x0.h b/arch/arm/plat-mxc/include/mach/board-armadillo5x0.h
new file mode 100644
index 0000000..b16897b
--- /dev/null
+++ b/arch/arm/plat-mxc/include/mach/board-armadillo5x0.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005-2007 Alberto Panizzo .
+ * All Rights Reserved.
+ */
+
+/*
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_MXC_BOARD_ARMADILLO5X0_H__
+#define __ASM_ARCH_MXC_BOARD_ARMADILLO5X0_H__
+
+#include
+
+/*
+ * Other memory mapping regions
+ */
+
+#define CS0_BASE_ADDR_VIRT 0xE0000000
+#define CS0_SIZE SZ_128M
+
+/* mandatory for CONFIG_LL_DEBUG */
+
+#define MXC_LL_UART_PADDR UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR AIPS1_IO_ADDRESS(UART1_BASE_ADDR)
+
+#endif
diff --git a/arch/arm/plat-mxc/include/mach/debug-macro.S b/arch/arm/plat-mxc/include/mach/debug-macro.S
index 4f77314..d3440ab 100644
--- a/arch/arm/plat-mxc/include/mach/debug-macro.S
+++ b/arch/arm/plat-mxc/include/mach/debug-macro.S
@@ -34,6 +34,9 @@
#ifdef CONFIG_MACH_QONG
#include
#endif
+#ifdef CONFIG_MACH_ARMADILLO500
+#include
+#endif
.macro addruart,rx
mrc p15, 0, \rx, c1, c0
tst \rx, #1 @ MMU enabled?

Compiling:
apply the patch...
$ export ARCH=arm
$ export CROSS_COMPILE=/media/dati/android/cupcake/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
$ make allnoconfig
$ make gconfig
->System Type>ARMSystemType>Freescale MXC/iMX based=y
->Freescale MXC Implementation > Support Atmark Armadillo-500 Development Board=y
$ make
-> download to the board and boot!

venerdì 3 aprile 2009

iMX Linux Boot Process description online

Within my links on right side now there is the pdf document that describe the entire Linux boot process adapted for arm i.MX31: after the bootloader work through the execution of /sbin/init!

Taste it! Bye!

giovedì 2 aprile 2009

Very deep focus on ARM Boot process

Here Peter Pearse make a very deep and up-to-date focus analysis of SMP ARM Boot process:
http://www.linux-arm.org/LinuxBootLoader/SMPBoot
Thanks a lot to him :)

With little adjusting Voilà! the single core ARM Boot process!
The context where I have to work and without I will not understand nothing :p

Kernel XIP

What is XIP?? Only for memo.. eXecute In Place.
Ref: http://elinux.org/Kernel_XIP

What Run First

Form Arm-Linux Mailing list, posted by Russell King
http://lists.arm.linux.org.uk/lurker/message/20011005.154003.5d698445.html

What runs first depends on what type of kernel you start running.

Compressed kernel (aka zImage):
  1. the startup code in arch/arm/boot/compressed/head.S (start label)
    (and maybe some other architecture specific code in other head-*.S files in that directory).
  2. Decompressor proper (via decompress_kernel) in arch/arm/boot/compressed/misc.c which gunzips the kernel.
  3. We then relocate the kernel if required, and call it.
Uncompressed kernel (aka Image):
This is where we join the uncompressed kernel startup.
  1. arch/arm/kernel/head-armv.S (Edit head.S and head-*.S ) describes this, and includes such things as:
    page table initialization and processor cache initialization
    (via support stuff in arch/arm/mm/proc-*.S).
  2. We then proceed to start_kernel in init/main.c, and everything follows from that point on.
  3. The only other thing to note is that the various drivers are initialized via a table built by the linker from the __initcall() and module_init() statements scattered throughout the kernel source. The code which calls them can be found in init/main.c: do_initcalls().

mercoledì 1 aprile 2009

All begin by main.c

All the time I spent since now was for looking to understand the real order in booting/init procedure (not counting time spent for diffs over different kernel source and bsp's)

Here I found an effective utile documentation: http://www.linux-arm.org/LinuxKernel/LinuxNewPlatformPort

In Kernel Boot section we can find that the function init/main.c:start_kernel() starts the kernel over all architecture, and give the real order of the initialization sequence.

Sorry it it was obvious I am a sort of Davide that fight with Golia in this work :)

Anyway every tutorial/docs I've found is related to old kernel version..

C Preprocessor and Macro, symbol ##

It is easy to see in kernel sources within macros the symbol ## but what it mean??
It is used to Concatenate "token" of text source: when the macro is expanded first the preprocessor substitute the variables name with their values and then concatenate tokens divided by ##
#define init_func(prefix_name, arg) prefix_name##_init(arg)
so calling:
init_func(armadillo, null)
expands in:
armadillo_init(null)
fox!

Reference: http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html#Concatenation

Fermo per un pò.. ma riprendo!

Dopo gli eventi della settimana scorsa ho ripreso il lavoro..
Ora mi stò concentrando sulla creazione del supporto ad armadillo 500 per la versione corrente del kernel: 2.6.29 Questo perché:
  1. Atmark con la loro bsp si sono strafregati dello sviluppo mailine del kernel..
  2. -> La bsp risultate è difficile da portare su kernel recenti.
  3. Se devo fare lo sforzo di rivedere l'intera bsp, cosa mi trattiene da farlo fatto bene in modo che possa convivere con tutte le altre??
  4. Per Android è già presente la versione del kernel 2.6.29..! skeggie! :)