Last active
October 8, 2022 11:04
-
-
Save lupyuen/ee3adf76e76881609845d0ab0f768a95 to your computer and use it in GitHub Desktop.
Experimenting with PinePhone p-boot Display Code on Apache NuttX RTOS. See https://lupyuen.github.io/articles/dsi#render-display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// p-boot Display Code from https://megous.com/git/p-boot/ | |
// With minor modifications: https://github.com/lupyuen/pinephone-nuttx/releases/download/pboot/p-boot.zip | |
// As called by: https://github.com/lupyuen/incubator-nuttx-apps/blob/de/examples/hello/hello_main.c | |
// Runs OK on Apache NuttX RTOS on PinePhone with the following fixes... | |
// From p-boot/build/build.ninja | |
#define DUMP_DSI_INIT 1 | |
#define DSI_FULL_INIT 1 | |
#define DE2_RESIZE 1 | |
#define __KERNEL__ | |
#define __UBOOT__ | |
#define __ARM__ | |
#define __LINUX_ARM_ARCH__ 8 | |
#define CONFIG_ARM64 | |
#define CONFIG_MACH_SUN50I | |
#define CONFIG_SUNXI_GEN_SUN6I | |
#define CONFIG_SPL_BUILD | |
#define CONFIG_CONS_INDEX 1 | |
#define CONFIG_SUNXI_DE2 | |
#define CONFIG_SUNXI_A64_TIMER_ERRATUM | |
#define CONFIG_SYS_HZ 1000 | |
#define CONFIG_SUNXI_DRAM_DW | |
#define CONFIG_SUNXI_DRAM_LPDDR3_STOCK | |
#define CONFIG_SUNXI_DRAM_LPDDR3 | |
#define CONFIG_DRAM_CLK 552 | |
#define CONFIG_DRAM_ZQ 3881949 | |
#define CONFIG_NR_DRAM_BANKS 1 | |
#define CONFIG_SUNXI_DRAM_DW_32BIT | |
#define CONFIG_SUNXI_DRAM_MAX_SIZE 0xC0000000 | |
#define CONFIG_DRAM_ODT_EN | |
#define CONFIG_SYS_CLK_FREQ 816000000 | |
#define CONFIG_SYS_SDRAM_BASE 0x40000000 | |
#define CONFIG_SUNXI_SRAM_ADDRESS 0x10000 | |
#define CONFIG_SYS_CACHE_SHIFT_6 | |
#define CONFIG_SYS_CACHELINE_SIZE 64 | |
#define CONFIG_MMC2_BUS_WIDTH 8 | |
#define CONFIG_MMC_SUNXI_HAS_NEW_MODE | |
#define CONFIG_ARCH_FIXUP_FDT_MEMORY | |
#define FDT_ASSUME_MASK 0xff | |
#define u8 uint8_t | |
#define u16 uint16_t | |
#define u32 uint32_t | |
#define u64 uint64_t | |
#define __u8 uint8_t | |
#define __u16 uint16_t | |
#define __u32 uint32_t | |
#define __u64 uint64_t | |
#define __le16 __u16 | |
#define __be16 __u16 | |
#define __le32 __u32 | |
#define __be32 __u32 | |
#define __le64 __u64 | |
#define __be64 __u64 | |
#define __sum16 __u16 | |
#define __wsum __u32 | |
// sizeof(long)=8 | |
// sizeof(long long)=8 | |
#define BITS_PER_LONG 64 | |
#define BITS_PER_LONG_LONG 64 | |
#define noinline | |
#define __force | |
#define udelay(us) usleep(us) | |
//#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) | |
//#define BIT(n) (0x1U << (n)) | |
#define min(x, y) ( \ | |
(x) < (y) ? (x) : (y) ) | |
#define max(x, y) ( \ | |
(x) > (y) ? (x) : (y) ) | |
////TODO: Implement barriers. From p-boot/src/uboot/arch/arm/include/asm/io.h | |
////TODO: #define mb() dsb() | |
////TODO: #define __iormb() dmb() | |
////TODO: #define __iowmb() dmb() | |
#define mb() | |
#define __iormb() | |
#define __iowmb() | |
////TODO | |
static ulong timer_get_boot_us(void) { | |
usleep(1); | |
static ulong microsecs = 0; | |
return microsecs++; | |
} | |
////TODO | |
#define hang display_hang | |
#define malloc display_malloc | |
#define zalloc display_zalloc | |
static void display_hang(void) { | |
puts("***display_hang"); | |
for(;;) {} | |
} | |
////TODO | |
static void *display_malloc(size_t size) { | |
printf("display_malloc: size=%ld\n", size); | |
static uint8_t buf[2330]; | |
assert(size <= sizeof(buf)); | |
memset(buf, 0, sizeof(buf)); | |
return buf; | |
} | |
////TODO | |
void *display_zalloc(size_t size) { | |
printf("display_zalloc: size=%ld\n", size); | |
static uint8_t buf[1024]; | |
assert(size <= sizeof(buf)); | |
memset(buf, 0, sizeof(buf)); | |
return buf; | |
} | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/clock.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/clock_sun6i.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/display2.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/gpio.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/lcdc.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/arch-sunxi/pwm.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/io.h" | |
#include "../../p-boot/src/uboot/arch/arm/include/asm/posix_types.h" | |
#include "../../p-boot/src/uboot/include/linux/byteorder/little_endian.h" | |
#include "../../p-boot/src/uboot/include/linux/byteorder/generic.h" | |
#include "../../p-boot/src/uboot/include/linux/bitops.h" | |
#include "../../p-boot/src/uboot/include/linux/kernel.h" | |
#include "../../p-boot/src/uboot/include/linux/kconfig.h" | |
#include "../../p-boot/src/ccu.h" | |
#include "../../p-boot/src/display.h" | |
#include "../../p-boot/src/pmic.h" | |
#include "../../p-boot/src/uboot/arch/arm/mach-sunxi/pinmux.c" | |
#include "../../p-boot/src/uboot/drivers/gpio/sunxi_gpio.c" | |
#include "../../p-boot/src/uboot/arch/arm/mach-sunxi/clock_sun6i.c" | |
#include "../../p-boot/src/pmic.c" | |
#include "../../p-boot/src/display.c" | |
// From p-boot/src/dtest.c | |
static void test_display(void) { | |
// Allocate display | |
static struct display disp; | |
memset(&disp, 0, sizeof(disp)); | |
struct display* d = &disp; | |
// Allocate framebuffer, init with pattern | |
static uint8_t fb[4 * 720 * 1440]; | |
for (int i = 0; i < sizeof(fb); i++) { | |
fb[i] = i; | |
} | |
// int ret; | |
// ulong dram_size; | |
// green_led_set(1); | |
// ccu_init(); | |
// console_init(); | |
// lradc_enable(); | |
// wdog_ping(8); // 10s | |
// puts("p-boot display program (version " VERSION " built " BUILD_DATE ")\n"); | |
// ret = rsb_init(); | |
// if (ret) | |
// panic(9, "rsb init failed %d\n", ret); | |
pmic_init(); | |
udelay(500); | |
// dram_size = sunxi_dram_init(); | |
// if (!dram_size) | |
// panic(3, "DRAM not detected"); | |
// icache_enable(); | |
// mmu_setup(dram_size); | |
// struct mmc* mmc = mmc_probe(0); | |
// if (mmc) { | |
// struct bootfs* fs = bootfs_open(mmc); | |
// if (fs) { | |
// printf("OK!\n"); | |
// bootfs_load_file(fs, 0x48000000, "pboot2.argb"); | |
// bootfs_load_file(fs, 0x49000000, "off.argb"); | |
// } | |
// } | |
// ccu_upclock(); | |
// udelay(160); | |
// clock_set_pll1(1152000000); | |
// sys_console = zalloc(sizeof *sys_console); | |
// vidconsole_init(sys_console, 45, 45, 2, 0xffffeecc, 0xff000000); | |
// puts("p-boot display program\n (version " VERSION "\n built " BUILD_DATE ")\n"); | |
// // 45x45 or 90x90 | |
// struct vidconsole* tconsole = zalloc(sizeof *tconsole); | |
// vidconsole_init(tconsole, 45, 45, 2, 0xffffeecc, 0xff104010); | |
// for (unsigned x = 0; x < 45; x++) | |
// for (unsigned y = 0; y < 45; y++) | |
// vidconsole_set_xy(tconsole, x, y, 'q', 0xffffff33, 0); | |
// vidconsole_redraw(tconsole); | |
display_init(); | |
// vidconsole_redraw(sys_console); | |
udelay(160000); | |
backlight_enable(90); | |
// uint32_t* fb = malloc(4 * 600 * 600); | |
// for (int i = 0; i < 600 * 600; i++) | |
// fb[i] = 0xff000000 | (i * 3); | |
// struct display* d = zalloc(sizeof *d); | |
// struct gui* g = zalloc(sizeof *g); | |
// gui_init(g, d); | |
d->planes[0].fb_start = (uintptr_t)fb; | |
d->planes[0].fb_pitch = 720 * 4; | |
d->planes[0].src_w = 720; | |
d->planes[0].src_h = 1440; | |
d->planes[0].dst_w = 720; | |
d->planes[0].dst_h = 1440; | |
d->planes[1].fb_start = (uintptr_t)fb; | |
d->planes[1].fb_pitch = 600 * 4; | |
d->planes[1].src_w = 600; | |
d->planes[1].src_h = 600; | |
d->planes[1].dst_w = 600; | |
d->planes[1].dst_h = 600; | |
d->planes[1].dst_x = 52; | |
d->planes[1].dst_y = 52; | |
d->planes[2].fb_start = (uintptr_t)fb; | |
d->planes[2].fb_pitch = 720 * 4; | |
d->planes[2].src_w = 720; | |
d->planes[2].src_h = 1440; | |
d->planes[2].dst_w = 720; | |
d->planes[2].dst_h = 1440; | |
d->planes[2].dst_x = 0; | |
d->planes[2].dst_y = 0; | |
d->planes[2].alpha = 255; | |
display_commit(d); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment