Commit ac3d8d97 authored by Angus Ainslie's avatar Angus Ainslie

m4_main : refactor code

* move uart functionality out to a seperate file
* add code to check RDC for the M4
* make it possible to have mailboxes in OCRAM or TCMU
parent b0411803
......@@ -7,7 +7,7 @@ CFLAGS += -g
CFLAGS += -march=armv7e-m -mthumb
AFLAGS += -march=armv7e-m -mthumb
OBJS = m4_start.o m4_main.o iomux-v3.o ddr_loader.o gpio.c
OBJS = m4_start.o m4_main.o iomux-v3.o ddr_loader.o gpio.o timer.o uart.o
all: m4.bin
......@@ -15,10 +15,10 @@ m4.bin: m4_ocram.elf
${OBJCOPY} -O binary $^ m4.bin
m4_tcm.elf: $(OBJS)
${CC} $(CXXFLAGS) -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Map,m4.map,--cref,-n
${CC} $(CXXFLAGS) -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Map,m4.map,--cref,-n
m4_ocram.elf: $(OBJS)
${CC} $(CXXFLAGS) -g -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Ttext,0x00900000,-Map,m4.map,--cref,-n
${CC} $(CXXFLAGS) -g -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Ttext,0x00900000,-Map,m4.map,--cref,-n
clean:
rm -f *.o m4.bin m4_ocram.elf m4_tcm.elf m4.map
......
/*
* Copyright (C) 2018 Purism
*
* SPDX-License-Identifier: GPL-3.0+
*/
#ifndef __M4_H__
#define __M4_H_
......
This diff is collapsed.
/*
* Copyright (c) 2016 Ryo Shimizu <ryo@nerv.org>
* Copyright (c) 2018 Purism
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* based on code found here
* https://github.com/ryo/netbsdimx7_m4loader
*/
#include "io.h"
#include "uart.h"
#define CONSOLE_PORT 1
#define DEBUG
void xputc(char c, int console)
{
#ifdef DEBUG
uint32_t console_addr;
if( console == 1 )
console_addr = CONADDR1;
else
console_addr = CONADDR2;
while ((__raw_readl((void *)console_addr + IMX_USR2) & IMX_USR2_TXDC) == 0) {
}
__raw_writel(c, (void *)console_addr + IMX_UTXD);
#endif
}
void xputs(char *s)
{
while (*s)
{
xputc(*s++, CONSOLE_PORT);
}
}
void xputhex_digit( uint8_t d )
{
char c;
if(d > 9)
c = (d - 10) + 'a';
else
c = d + '0';
xputc(c, CONSOLE_PORT);
}
void xputhex( uint32_t h )
{
char i = 28, val;
xputs("0x");
while( i > 0 ) {
val = (h>>i)&0xf;
xputhex_digit(val);
i -= 4;
}
xputhex_digit(h&0xf);
}
void xputint( int d )
{
int negative = 0, i = 0;
char str[16];
if (d == 0) {
xputc('0', CONSOLE_PORT);
return;
}
if (d < 0) {
d = d * -1;
negative = 1;
}
while (d > 0) {
str[i++] = (d % 10) + '0';
d = d / 10;
}
if (negative)
xputc('-', CONSOLE_PORT);
while (--i >= 0)
xputc(str[i], CONSOLE_PORT);
}
void setup_uart(int uart, int baud)
{
uint32_t console_addr;
uint32_t reg_val;
if( uart == 1 )
console_addr = CONADDR1;
else
console_addr = CONADDR2;
__raw_writel(0, (void *)console_addr + IMX_UCR1);
__raw_writel(0, (void *)console_addr + IMX_UCR2);
while ((__raw_readl((void *)console_addr + IMX_UCR2) & IMX_UCR2_SRST) == 0) {
// wait for reset to finish
}
__raw_writel(0x0704 | IMX_UCR3_ADNIMP, (void *)console_addr + IMX_UCR3);
__raw_writel(0x8000, (void *)console_addr + IMX_UCR4);
__raw_writel(0x2b, (void *)console_addr + IMX_UESC);
__raw_writel(0, (void *)console_addr + IMX_UTIM);
__raw_writel(0, (void *)console_addr + IMX_UTS);
reg_val = 0xf;
__raw_writel(reg_val, (void *)console_addr + IMX_UBIR);
reg_val = (IMX_UART_FREQ / (2 * baud));
__raw_writel(reg_val, (void *)console_addr + IMX_UBMR);
reg_val = IMX_UCR2_WS | IMX_UCR2_IRTS | IMX_UCR2_RXEN | IMX_UCR2_TXEN |
IMX_UCR2_SRST;
__raw_writel(reg_val, (void *)console_addr + IMX_UCR2);
__raw_writel(IMX_UCR1_UARTEN, (void *)console_addr + IMX_UCR1);
}
/*
* Copyright (c) 2016 Ryo Shimizu <ryo@nerv.org>
* Copyright (c) 2018 Purism
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* based on code found here
* https://github.com/ryo/netbsdimx7_m4loader
*/
#ifndef __UART_H__
#define __UART_H__
#include <inttypes.h>
#define CONADDR1 0x30860000 // UART1
#define CONADDR2 0x30890000 // UART2
#define CONADDR3 0x30880000 // UART3
#define IMX_UTXD 0x40 /* UART Transmitter Reg */
#define IMX_UCR1 0x80 /* UART Control Reg 1 */
#define IMX_UCR2 0x84 /* UART Control Reg 2 */
#define IMX_UCR3 0x88 /* UART Control Reg 3 */
#define IMX_UCR4 0x8c /* UART Control Reg 4 */
#define IMX_UFCR 0x90 /* UART FIFO Control Reg */
#define IMX_USR1 0x94 /* UART Status Reg 1 */
#define IMX_USR2 0x98 /* UART Status Reg 2 */
#define IMX_UTIM 0xa0 /* Escape Timer Register */
#define IMX_UESC 0x9c /* Escape Character Register */
#define IMX_UBIR 0xa4 /* UART Status Reg 2 */
#define IMX_UBMR 0xa8 /* UART Status Reg 2 */
#define IMX_UTS 0xb4 /* UART Test Register (mx31) */
#define IMX_UART_FREQ (25000000)
#define IMX_USR2_TXDC (1<<3)
#define IMX_UCR2_TXEN (1<<2)
#define IMX_UCR2_RXEN (1<<1)
#define IMX_UCR2_WS (1<<5)
#define IMX_UCR2_IRTS (1<<14)
#define IMX_UCR1_UARTEN (1)
#define IMX_UCR2_SRST (1<<0)
#define IMX_UCR3_ADNIMP (1<<7)
void xputc(char c, int console);
void xputs(char *s);
void xputhex_digit(uint8_t d);
void xputhex(uint32_t h);
void xputint(int d);
void setup_uart(int uart, int baud);
#endif /* __UART_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment