Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rsta2 committed Dec 12, 2018
2 parents 893c298 + fb8545f commit 01fb7b4
Show file tree
Hide file tree
Showing 47 changed files with 1,316 additions and 1,014 deletions.
3 changes: 3 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Spanish keymap (taken from Circle)
Joshua Otto
Providing support for framebuffers where pitch != width * bytes per pixel
USB MIDI device class support

Paolo Franchetti
Suggesting improvements for the HID class device support and testing
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ Another option (NDEBUG) can be defined in Rules.mk to build the release version.
Building
--------

Building is normally done on PC Linux. If building for the Raspberry Pi 1 you need a [toolchain](http://elinux.org/Rpi_Software#ARM) for the ARM1176JZF core. For Raspberry Pi 2/3 you need a toolchain with Cortex-A7/-A53 support. A toolchain, which works for all of these, can be downloaded [here](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads). USPi has been tested with the version *6-2017-q1-update* from this website. You can also build USPi on the Raspberry Pi itself on Raspbian.
> For AArch64 support go to the end of this file.
Building is normally done on PC Linux. If building for the Raspberry Pi 1 you need a [toolchain](http://elinux.org/Rpi_Software#ARM) for the ARM1176JZF core. For Raspberry Pi 2/3 you need a toolchain with Cortex-A7/-A53 support. A toolchain, which works for all of these, can be downloaded [here](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads). USPi has been tested with the version *7-2018-q2-update* from this website. You can also build USPi on the Raspberry Pi itself on Raspbian.

First edit the file *Rules.mk* and set the Raspberry Pi version (*RASPPI*, 1, 2 or 3) and the *PREFIX* of your toolchain commands. Alternatively you can create a *Config.mk* file (which is ignored by git) and set the Raspberry Pi version and the *PREFIX* variable to the prefix of your compiler like this (don't forget the dash at the end):

Expand Down
20 changes: 18 additions & 2 deletions Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ AR = $(PREFIX)ar
ifeq ($(strip $(AARCH64)),0)
ifeq ($(strip $(RASPPI)),1)
ARCH ?= -march=armv6j -mtune=arm1176jzf-s -mfloat-abi=hard
TARGET ?= kernel
else ifeq ($(strip $(RASPPI)),2)
ARCH ?= -march=armv7-a -mtune=cortex-a7 -mfloat-abi=hard
TARGET ?= kernel7
else
ARCH ?= -march=armv8-a -mtune=cortex-a53 -mfloat-abi=hard
TARGET ?= kernel8-32
endif
else
ARCH ?= -march=armv8-a -mtune=cortex-a53 -mlittle-endian -mcmodel=small -DAARCH64=1
Expand All @@ -58,10 +61,23 @@ CFLAGS += $(ARCH) -Wall -Wno-psabi -fsigned-char -fno-builtin -nostdinc -nostdli
-std=gnu99 -undef -DRASPPI=$(RASPPI) -I $(USPIHOME)/include $(OPTIMIZE) #-DNDEBUG

%.o: %.S
$(AS) $(AFLAGS) -c -o $@ $<
@echo " AS $@"
@$(AS) $(AFLAGS) -c -o $@ $<

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
@echo " CC $@"
@$(CC) $(CFLAGS) -c -o $@ $<

$(TARGET).img: $(OBJS) $(LIBS)
@echo " LD $(TARGET).elf"
@$(LD) -o $(TARGET).elf -Map $(TARGET).map -T $(USPIHOME)/env/uspienv.ld \
$(USPIHOME)/env/lib/startup.o $(OBJS) $(LIBS)
@echo " DUMP $(TARGET).lst"
@$(PREFIX)objdump -D $(TARGET).elf > $(TARGET).lst
@echo " COPY $(TARGET).img"
@$(PREFIX)objcopy $(TARGET).elf -O binary $(TARGET).img
@echo -n " WC $(TARGET).img => "
@wc -c < $(TARGET).img

clean:
rm -f *.o *.a *.elf *.lst *.img *.cir *.map *~ $(EXTRACLEAN)
7 changes: 6 additions & 1 deletion env/include/uspienv/armv6mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// armv6mmu.h
//
// USPi - An USB driver for Raspberry Pi written in C
// Copyright (C) 2014-2015 R. Stange <[email protected]>
// Copyright (C) 2014-2018 R. Stange <[email protected]>
//
// 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
Expand Down Expand Up @@ -66,6 +66,11 @@ typedef struct TARMV6MMU_LEVEL1_SECTION_DESCRIPTOR // subpages disabled
}
PACKED TARMV6MMU_LEVEL1_SECTION_DESCRIPTOR;

#define ARMV6MMUL1SECTION_NORMAL 0x0040E // outer and inner write back, no write allocate
#define ARMV6MMUL1SECTION_NORMAL_XN 0x0041E // + execute never
#define ARMV6MMUL1SECTION_DEVICE 0x10416 // shared device
#define ARMV6MMUL1SECTION_COHERENT 0x10412 // strongly ordered

#define ARMV6MMUL1SECTIONBASE(addr) (((addr) >> 20) & 0xFFF)
#define ARMV6MMUL1SECTIONPTR(base) ((void *) ((base) << 20))

Expand Down
5 changes: 2 additions & 3 deletions env/include/uspienv/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// memory.h
//
// USPi - An USB driver for Raspberry Pi written in C
// Copyright (C) 2014-2015 R. Stange <[email protected]>
// Copyright (C) 2014-2018 R. Stange <[email protected]>
//
// 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
Expand Down Expand Up @@ -32,8 +32,7 @@ typedef struct TMemorySystem
boolean m_bEnableMMU;
u32 m_nMemSize;

TPageTable *m_pPageTable0Default;
TPageTable *m_pPageTable1;
TPageTable *m_pPageTable;
}
TMemorySystem;

Expand Down
13 changes: 3 additions & 10 deletions env/include/uspienv/pagetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// pagetable.h
//
// USPi - An USB driver for Raspberry Pi written in C
// Copyright (C) 2014-2015 R. Stange <[email protected]>
// Copyright (C) 2014-2018 R. Stange <[email protected]>
//
// 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
Expand All @@ -20,7 +20,6 @@
#ifndef _uspienv_pagetable_h
#define _uspienv_pagetable_h

#include <uspienv/armv6mmu.h>
#include <uspienv/types.h>

#ifdef __cplusplus
Expand All @@ -29,17 +28,11 @@ extern "C" {

typedef struct TPageTable
{
boolean m_bTableAllocated;
TARMV6MMU_LEVEL1_SECTION_DESCRIPTOR *m_pTable;
u32 *m_pTable;
}
TPageTable;

// 4GB shared device
void PageTable (TPageTable *pThis);

// 0..nMemSize: normal,
// nMemSize..512MB: shared device (1024MB on Raspberry Pi 2)
void PageTable2 (TPageTable *pThis, u32 nMemSize);
void PageTable (TPageTable *pThis, u32 nMemSize);

void _PageTable (TPageTable *pThis);

Expand Down
4 changes: 2 additions & 2 deletions env/include/uspienv/sysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// sysconfig.h
//
// USPi - An USB driver for Raspberry Pi written in C
// Copyright (C) 2014-2016 R. Stange <[email protected]>
// Copyright (C) 2014-2018 R. Stange <[email protected]>
//
// 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
Expand Down Expand Up @@ -52,7 +52,7 @@
// system options
#if RASPPI == 1 // valid on Raspberry Pi 1 only
//#define ARM_DISABLE_MMU
#define ARM_STRICT_ALIGNMENT
//#define ARM_STRICT_ALIGNMENT
#define GPU_L2_CACHE_ENABLED
#else
#define CORES 4 // must be a power of 2
Expand Down
11 changes: 8 additions & 3 deletions env/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Makefile
#
# USPi - An USB driver for Raspberry Pi written in C
# Copyright (C) 2014-2015 R. Stange <[email protected]>
# Copyright (C) 2014-2018 R. Stange <[email protected]>
#
# 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
Expand Down Expand Up @@ -33,7 +33,12 @@ all: startup.o libuspienv.a
startup.o: startup.S

libuspienv.a: $(OBJS)
rm -f $@
$(AR) cr $@ $(OBJS)
@echo " AR $@"
@rm -f $@
@$(AR) cr $@ $(OBJS)

include $(USPIHOME)/Rules.mk

ifneq ($(strip $(AARCH64)),0)
$(error AARCH64 is not supported in lib/env/)
endif
42 changes: 13 additions & 29 deletions env/lib/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// memory.c
//
// USPi - An USB driver for Raspberry Pi written in C
// Copyright (C) 2014-2015 R. Stange <[email protected]>
// Copyright (C) 2014-2018 R. Stange <[email protected]>
//
// 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
Expand Down Expand Up @@ -31,17 +31,15 @@
| ARM_CONTROL_L1_INSTRUCTION_CACHE \
| ARM_CONTROL_BRANCH_PREDICTION \
| ARM_CONTROL_EXTENDED_PAGE_TABLE)

#define TTBCR_SPLIT 3
#else
#define MMU_MODE ( ARM_CONTROL_MMU \
| ARM_CONTROL_L1_CACHE \
| ARM_CONTROL_L1_INSTRUCTION_CACHE \
| ARM_CONTROL_BRANCH_PREDICTION)

#define TTBCR_SPLIT 2
#endif

#define TTBCR_SPLIT 0

void MemorySystemEnableMMU (TMemorySystem *pThis);

void MemorySystem (TMemorySystem *pThis, boolean bEnableMMU)
Expand All @@ -50,8 +48,7 @@ void MemorySystem (TMemorySystem *pThis, boolean bEnableMMU)

pThis->m_bEnableMMU = bEnableMMU;
pThis->m_nMemSize = 0;
pThis->m_pPageTable0Default = 0;
pThis->m_pPageTable1 = 0;
pThis->m_pPageTable = 0;

TBcmPropertyTags Tags;
BcmPropertyTags (&Tags);
Expand All @@ -69,13 +66,9 @@ void MemorySystem (TMemorySystem *pThis, boolean bEnableMMU)

if (pThis->m_bEnableMMU)
{
pThis->m_pPageTable0Default = (TPageTable *) malloc (sizeof (TPageTable));
assert (pThis->m_pPageTable0Default != 0);
PageTable2 (pThis->m_pPageTable0Default, pThis->m_nMemSize);

pThis->m_pPageTable1 = (TPageTable *) malloc (sizeof (TPageTable));
assert (pThis->m_pPageTable1 != 0);
PageTable (pThis->m_pPageTable1);
pThis->m_pPageTable = (TPageTable *) malloc (sizeof (TPageTable));
assert (pThis->m_pPageTable != 0);
PageTable (pThis->m_pPageTable, pThis->m_nMemSize);

MemorySystemEnableMMU (pThis);
}
Expand All @@ -99,13 +92,9 @@ void _MemorySystem (TMemorySystem *pThis)
asm volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0) : "memory");
}

_PageTable (pThis->m_pPageTable1);
free (pThis->m_pPageTable1);
pThis->m_pPageTable1 = 0;

_PageTable (pThis->m_pPageTable0Default);
free (pThis->m_pPageTable0Default);
pThis->m_pPageTable0Default = 0;
_PageTable (pThis->m_pPageTable);
free (pThis->m_pPageTable);
pThis->m_pPageTable = 0;
}

u32 MemorySystemGetMemSize (TMemorySystem *pThis)
Expand Down Expand Up @@ -138,16 +127,11 @@ void MemorySystemEnableMMU (TMemorySystem *pThis)
asm volatile ("mcr p15, 0, %0, c2, c0, 2" : : "r" (TTBCR_SPLIT));

// set TTBR0
assert (pThis->m_pPageTable0Default != 0);
asm volatile ("mcr p15, 0, %0, c2, c0, 0" : : "r" (PageTableGetBaseAddress (pThis->m_pPageTable0Default)));
assert (pThis->m_pPageTable != 0);
asm volatile ("mcr p15, 0, %0, c2, c0, 0" : : "r" (PageTableGetBaseAddress (pThis->m_pPageTable)));

// set TTBR1
assert (pThis->m_pPageTable1 != 0);
asm volatile ("mcr p15, 0, %0, c2, c0, 1" : : "r" (PageTableGetBaseAddress (pThis->m_pPageTable1)));

// set Domain Access Control register (Domain 0 and 1 to client)
asm volatile ("mcr p15, 0, %0, c3, c0, 0" : : "r" ( DOMAIN_CLIENT << 0
| DOMAIN_CLIENT << 2));
asm volatile ("mcr p15, 0, %0, c3, c0, 0" : : "r" (DOMAIN_CLIENT << 0));

InvalidateDataCache ();
FlushPrefetchBuffer ();
Expand Down
Loading

0 comments on commit 01fb7b4

Please sign in to comment.