diff --git a/arch/arm/Start.S b/arch/arm/Start.S new file mode 100644 index 0000000..3891e1e --- /dev/null +++ b/arch/arm/Start.S @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + + ldr r0, =dtb + ldr r1, =kernel + b main + +.global load_kernel +load_kernel: + bx r4 diff --git a/arch/arm/linker.lds.S b/arch/arm/linker.lds.S new file mode 100644 index 0000000..f7a8574 --- /dev/null +++ b/arch/arm/linker.lds.S @@ -0,0 +1,29 @@ +ENTRY(_start); + +OUTPUT_FORMAT("elf32-littlearm") +OUTPUT_ARCH(arm) +TARGET(binary) + +INPUT(KERNEL_PATH) +INPUT(DTB_PATH) + +SECTIONS +{ + . = 0x80008000; + + .boot : { + arch/arm/Start.o + } + + .dtb ALIGN(0x1000) : { + dtb = .; + DTB_PATH + } + + .kernel ALIGN(0x1000) : { + kernel = .; + KERNEL_PATH + } + + kernel_size = SIZEOF(.kernel); +} diff --git a/board/Kconfig b/board/Kconfig index 12d526c..d5b433d 100644 --- a/board/Kconfig +++ b/board/Kconfig @@ -42,6 +42,12 @@ menu "Device Support" help Say Y if you want to include support for Samsung Galaxy S9 + config SAMSUNG_J5LTE + bool "Support for Samsung Galaxy J5 2015" + default n + depends on QC32_8916 + help + Say Y if you want to include arm32 support for Samsung Galaxy J5 2015 endmenu menu "Device Specific Addresses" @@ -54,6 +60,7 @@ menu "Device Specific Addresses" default 0x090000000 if SAMSUNG_ZEROFLTE default 0x090000000 if SAMSUNG_DREAMLTE default 0x090000000 if SAMSUNG_STARLTE + default 0x090000000 if SAMSUNG_J5LTE config FRAMEBUFFER_BASE hex "Framebuffer Base Address (for SimpleFB)" @@ -64,6 +71,7 @@ menu "Device Specific Addresses" default 0x0e2a00000 if SAMSUNG_ZEROFLTE default 0x0cc000000 if SAMSUNG_DREAMLTE default 0x0cc000000 if SAMSUNG_STARLTE + default 0x08e000000 if SAMSUNG_J5LTE config FRAMEBUFFER_WIDTH int "Framebuffer Width (for SimpleFB)" @@ -74,6 +82,7 @@ menu "Device Specific Addresses" default 1440 if SAMSUNG_ZEROFLTE default 1440 if SAMSUNG_DREAMLTE default 1440 if SAMSUNG_STARLTE + default 720 if SAMSUNG_J5LTE config FRAMEBUFFER_HEIGHT int "Framebuffer Height (for SimpleFB)" @@ -84,6 +93,7 @@ menu "Device Specific Addresses" default 2560 if SAMSUNG_ZEROFLTE default 2960 if SAMSUNG_DREAMLTE default 2960 if SAMSUNG_STARLTE + default 1280 if SAMSUNG_J5LTE config FRAMEBUFFER_STRIDE int "Framebuffer Stride (for SimpleFB)" @@ -94,5 +104,6 @@ menu "Device Specific Addresses" default 4 if SAMSUNG_ZEROFLTE default 4 if SAMSUNG_DREAMLTE default 4 if SAMSUNG_STARLTE + default 4 if SAMSUNG_J5LTE endmenu diff --git a/board/Makefile b/board/Makefile index 2657f3a..a48b05b 100644 --- a/board/Makefile +++ b/board/Makefile @@ -4,3 +4,4 @@ lib-$(CONFIG_SAMSUNG_JACKPOTLTE) += samsung/board-jackpotlte.o lib-$(CONFIG_SAMSUNG_ZEROFLTE) += samsung/board-zeroflte.o lib-$(CONFIG_SAMSUNG_DREAMLTE) += samsung/board-dreamlte.o lib-$(CONFIG_SAMSUNG_STARLTE) += samsung/board-starlte.o +lib-$(CONFIG_SAMSUNG_J5LTE) += samsung/board-j5lte.o diff --git a/board/samsung/board-j5lte.c b/board/samsung/board-j5lte.c new file mode 100644 index 0000000..a1d14f8 --- /dev/null +++ b/board/samsung/board-j5lte.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + +#include + +#define PIPE_SSPP_SRC_FORMAT 0x30 +#define PIPE_SSPP_SRC_UNPACK_PATTERN 0x34 +#define PIPE_BASE 0x1A15000 +#define PIPE_SSPP_SRC_YSTRIDE 0x24 + +#define MDP_CTL_0_BASE 0x1A02000 +#define CTL_FLUSH 0x18 + +void board_init(void) { + /* TODO: Doesn't really work :P */ + writel(0x000236FF, PIPE_BASE + PIPE_SSPP_SRC_FORMAT); + writel(0x03020001, PIPE_BASE + PIPE_SSPP_SRC_UNPACK_PATTERN); + writel(720 * 4, MDP_CTL_0_BASE + CTL_FLUSH); + writel((1 << (0)), PIPE_BASE + PIPE_SSPP_SRC_YSTRIDE); +} + +void reboot(void) { + writel(0x0, 0x004AB000); +} diff --git a/configs/j5lte_defconfig b/configs/j5lte_defconfig new file mode 100644 index 0000000..4f2c01b --- /dev/null +++ b/configs/j5lte_defconfig @@ -0,0 +1,3 @@ +CONFIG_CROSS_COMPILE="arm-none-eabi-" +CONFIG_SAMSUNG_J5LTE=y +CONFIG_QC32_8916=y diff --git a/include/main.h b/include/main.h index cb2b645..493831b 100644 --- a/include/main.h +++ b/include/main.h @@ -13,37 +13,17 @@ extern void load_kernel(void* dtb, void* x1, void* x2, void* x3, void* kernel); extern void soc_init(void); extern void board_init(void); +extern void clean_fb(volatile char *fb, int width, int height, int stride); extern void printk(char *text); -#ifndef __has_builtin - #define __has_builtin(x) 0 +extern void writel(unsigned int value, void* address); +#ifdef __aarch64__ + /* Define our own 128 bit memcpy */ + extern void memcpy(void *dest, void *src, size_t size); #endif -#if __has_builtin(__builtin_memcpy) - void memcpy(void *dest, void *src, size_t size) { - __builtin_memcpy(dest, src, size); - } -#else - #ifdef __aarch64__ - /* Define our own 128 bit memcpy */ - void memcpy(void *dest, void *src, size_t size) - { - unsigned __int128 *src2 = src; - unsigned __int128 *dest2 = dest; - - for (size_t i = 0; i < size / 16; i++) - dest2[i] = src2[i]; - } - #endif - - #ifdef __arm__ - void memcpy (char* src, char* dest, size_t len) { - for (size_t i = 0; i < len; i++) - dest[i] = src[i]; - } - #endif +#ifdef __arm__ + extern void memcpy (char* src, char* dest, size_t len); #endif - - #endif // MAIN_H_ diff --git a/include/soc/msm8916.h b/include/soc/msm8916.h new file mode 100644 index 0000000..d0bdc4e --- /dev/null +++ b/include/soc/msm8916.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + +#ifndef MSM8916_H_ /* Include guard */ +#define MSM8916_H_ + +#endif // MSM8916_H_ diff --git a/lib/debug/debug.c b/lib/debug/debug.c index 2ccc7ee..dd5fa7f 100644 --- a/lib/debug/debug.c +++ b/lib/debug/debug.c @@ -3,6 +3,16 @@ * Copyright (c) 2022, Ivaylo Ivanov */ #include +#include + +/* TODO: Import libc */ +void writel(unsigned int value, void* address) { + // Cast the address pointer to a 32-bit unsigned integer pointer + volatile unsigned int* ptr = (volatile unsigned int*)address; + + // Write the value to the memory location + *ptr = value; +} void printk(char *text) { #ifdef CONFIG_SIMPLE_FB @@ -16,3 +26,22 @@ void printk(char *text) { debug_linecount++; #endif } + + #ifdef __aarch64__ + /* Define our own 128 bit memcpy */ + void memcpy(void *dest, void *src, size_t size) + { + unsigned __int128 *src2 = src; + unsigned __int128 *dest2 = dest; + + for (size_t i = 0; i < size / 16; i++) + dest2[i] = src2[i]; + } + #endif + + #ifdef __arm__ + void memcpy (char* src, char* dest, size_t len) { + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } + #endif diff --git a/lib/simplefb/simplefb.c b/lib/simplefb/simplefb.c index 9f2ae41..0f47219 100644 --- a/lib/simplefb/simplefb.c +++ b/lib/simplefb/simplefb.c @@ -8,7 +8,7 @@ #include #include -void clean_fb(volatile char *fb, char *text, int width, int height, int stride) { +void clean_fb(volatile char *fb, int width, int height, int stride) { for (volatile char *addr = fb; addr < fb + (width * height * stride); addr += stride) *(int*) (addr) = 0x0; } diff --git a/main/main.c b/main/main.c index faa5547..f965adb 100644 --- a/main/main.c +++ b/main/main.c @@ -6,9 +6,12 @@ #include void main(void* dt, void* kernel) { - /* C entry */ - /* Initialize SoC and Board specific peripherals/quirks */ + + /* TODO: Find a better way to make this more universal (since devices like arm64 Samsung Galaxies enable FB after soc_init) */ +#ifdef CONFIG_SIMPLE_FB + clean_fb((char*)CONFIG_FRAMEBUFFER_BASE, CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_HEIGHT, CONFIG_FRAMEBUFFER_STRIDE); +#endif soc_init(); printk("soc_init() passed!"); @@ -17,6 +20,10 @@ void main(void* dt, void* kernel) { /* Copy kernel to memory and boot */ printk("Booting linux..."); - __builtin_memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size); - load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY); + + memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size); + load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY); + + /* We shouldn't get there */ + while(1) {} } diff --git a/soc/Kconfig b/soc/Kconfig index 8daf36d..dc6b48b 100644 --- a/soc/Kconfig +++ b/soc/Kconfig @@ -6,6 +6,10 @@ config EXYNOS bool default n +config QUALCOMM + bool + default n + choice prompt "SoC Support" @@ -43,5 +47,12 @@ choice select EXYNOS help Say Y if your device uses Samsung Exynos9810 SoC + + config QC32_8916 + bool "Support for QUALCOMM MSM8916" + default n + select QUALCOMM + help + Say Y if your device uses this Qualcomm SoC endchoice diff --git a/soc/Makefile b/soc/Makefile index 5cee501..9209661 100644 --- a/soc/Makefile +++ b/soc/Makefile @@ -3,3 +3,4 @@ lib-$(CONFIG_EXYNOS_7420) += exynos/exynos7420.o lib-$(CONFIG_EXYNOS_7885) += exynos/exynos7885.o lib-$(CONFIG_EXYNOS_8895) += exynos/exynos8895.o lib-$(CONFIG_EXYNOS_9810) += exynos/exynos9810.o +lib-$(CONFIG_QC32_8916) += qualcomm/msm8916.o diff --git a/soc/qualcomm/msm8916.c b/soc/qualcomm/msm8916.c new file mode 100644 index 0000000..be83e95 --- /dev/null +++ b/soc/qualcomm/msm8916.c @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + +#include + +void soc_init(void) { + +}