8 Commits

Author SHA1 Message Date
Takumi Sueda
08ad49b627 Update README / merge Python requirements 2022-02-21 06:35:35 +09:00
Takumi Sueda
4b5601c738 Show image.jpg when switching fb address 2022-02-21 06:29:21 +09:00
4cb07e77bb Add framebuffer address change 2022-02-20 04:54:23 +09:00
cbf1b89241 add stop LPTMR 2022-02-19 22:47:16 +09:00
0a091e3515 M4 RTOS loader ready 2022-02-19 22:47:16 +09:00
Chiharu Shirasaka
3de439eb6f Merge pull request #1 from brain-hackers/u-boot_sizefix
U-boot size calculation fix
2022-01-23 04:39:37 +09:00
17cc2d2278 fix branch condition for non multiple of 4Byte size 2022-01-23 04:28:21 +09:00
3744630abf Fix U-Boot copy size calculation 2022-01-15 22:51:42 +09:00
6 changed files with 162 additions and 8 deletions

View File

@@ -4,12 +4,19 @@ CC:=$(CROSS_COMPILE)gcc
STRIP:=$(CROSS_COMPILE)strip
.PHONY:
all: AppMain.bin
all: AppMain.bin m4_loader.bin
.PHONY:
clean:
@rm -f *.bin *.elf
@rm -f *.bin *.elf pixels.c
AppMain.bin:
@$(AS) main.S -o main.elf
pixels.c:
@python3 img2c.py image.jpg pixels.c
AppMain.bin: pixels.c
@$(CC) -nostdlib -static -fPIC -mcpu=cortex-a7 main.S pixels.c -o main.elf
@./extract.py -p main.elf AppMain.bin
m4_loader.bin:
@$(AS) m4_loader.S -mcpu=cortex-m4 -o m4_loader.elf
@./extract.py -p m4_loader.elf m4_loader.bin

View File

@@ -1,11 +1,22 @@
# boot4u
U-Boot loader for PW-x1
# Preparation
1. Install requirements
```shellsession
$ apt install gcc-arm-linux-gnueabihf
$ pip3 install -r requirements.txt
```
2. Put image.jpg in this directory
- The size must be 480x854 (rotate the picture 90 deg clockwise)
# Build
```sh
apt install gcc-arm-linux-gnueabihf
pip3 install pyelftools
make
```

34
img2c.py Normal file
View File

@@ -0,0 +1,34 @@
import sys
from PIL import Image
template = '''void load_pixels() {{
{lines}
}};
'''
im = Image.open(sys.argv[-2]).convert('RGB')
with open(sys.argv[-1], 'w') as f:
pixels = []
lines = []
count = 0
for y in range(im.size[1]):
for x in range(0, im.size[0], 2):
r, g, b = im.getpixel((x, y))
rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
pixels.append(rgb565 >> 8)
pixels.append(rgb565 & 0xff)
r, g, b = im.getpixel((x+1, y))
rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
pixels.append(rgb565 >> 8)
pixels.append(rgb565 & 0xff)
u32 = (pixels[0] << 24) + (pixels[1] << 16) + (pixels[2] << 8) + pixels[3]
lines.append(f'\t*(unsigned int *)(0x62000000 + {count:7d}) = {u32:#08x};')
pixels = []
count += 4;
f.write(template.format(lines='\n'.join(lines)))

40
m4_loader.S Normal file
View File

@@ -0,0 +1,40 @@
.text
.thumb
.syntax unified
.align 2
.global _start
_start:
cpsid i
//LPTMR0 interrupt stop
ldr r0, =0x4102e000
eor r1, r1, r1
str r1, [r0]
//M4 RTOS loader
ldr r0, =0x1FFD2000 //M4 SRAM start addr
ldr r1, =0x67400000 //M4 RTOS preload addr
ldr r2, =0 //increment register
ldr r4, [r1, #-4] //M4 RTOS size
loop:
ldr r3, [r1, r2] //load from dram
str r3, [r0, r2] //store to sram
add r2, #4 //increment
cmp r2, r4 //does copy end?
ble loop
//return address override
mrs r4, psp
adr r5, jumper
orr r5, r5, #1
str r5, [r4,#24]
bx lr //exit interrupt handler
jumper: //M4 RTOS image jumper
mrs r0, control
bic r0, #2
msr control, r0
isb
ldr r0, =0x1ffd2000 //M4 RTOS image head addr
ldr r1, [r0] //initial stack addr
mov sp, r1
ldr r2, [r0,#4] //reset vector
bx r2

64
main.S
View File

@@ -3,6 +3,55 @@
.global _start
_start:
bl load_pixels
//M4 RTOS loader snipet prep
ldr r4, =0x60006400 //fopen addr
adr r0, [.LC2] //file name
adr r1, [.LC1] //open mode
blx r4
add r5, r4, #0xc //fread addr
mov r3, r0 //file descriptor
ldr r0, =0x1ffe4000 //fread destination
mov r1, #1 //read unit size
mov r2, r0 //read unit count(over size)
blx r5
//M4 RTOS preload
ldr r4, =0x60006400 //fopen addr
adr r0, [.LC3] //file name
adr r1, [.LC1] //open mode
blx r4
add r5, r4, #0xc //fread addr
mov r3, r0 //file descriptor
ldr r0, =0x37400000 //fread destination
mov r1, #1 //read unit size
mov r2, r0 //read unit count(over size)
blx r5
//M4 RTOS size get
ldr r4, =0x60006444 //stat addr
adr r0, [.LC3] //file name
sub sp, sp, #0x14
mov r1, sp
blx r4
ldr r0, =0x373ffffc //store size before data
ldr r1, [sp,#0x10]
str r1, [r0]
//M4 interrupt prep
ldr r4, =0x1ffd20d0 //NVIC MCM vector
ldr r5, =0x1ffe4001 //loader addr | 0x1(thumb)
str r5, [r4] //override interrupt handler
//wait until M4 RTOS copied
ldr r4, =0x1ffd2000 //get sram img start addr
add r0, r0, #4 //get dram rtos addr
ldr r3, [r0, r1] //get last word of rtos on dram
rtos_loop:
ldr r2, [r4,r1] //get last word of rtos on sram
cmp r2,r3
bne rtos_loop
//preload U-Boot from sd
ldr r4, =0x60006400 //fopen addr
adr r0, [.LC0] //file name
@@ -20,13 +69,17 @@ _start:
.ascii "SD0:\\u-boot.bin\000"
.LC1:
.ascii "r\000"
.LC2:
.ascii "SD0:\\m4_loader.bin\000"
.LC3:
.ascii "SD0:\\m4_rtos.bin\000"
.align 4
continue:
cpsid if //disable interrupt
//copy U-Boot to head of RAM
ldr r3, =0x37500000 //copy start
ldr r1, =0x37540000 //copy end
add r1, r3, r0 //copy end
copy_loop:
mov r2, r3
sub r3, r3, #0x7500000 //copy distination
@@ -34,7 +87,7 @@ _start:
cmp r2, r1
str r0, [r3]
mov r3, r2
bne copy_loop
blt copy_loop
//RAM clear
ldr r2,=0x60200000 //clear start
@@ -46,6 +99,13 @@ _start:
str r1,[r2],#4
beq clear_loop
//LCDIF CUR_BUF change
ldr r1,=0x40aa0000 //LCDIF_CTRL
ldr r3,=0x62000000 //new framebuffer addr
str r3,[r1,#0x50]
ldr r0, =0x60000000
mrc p15, 0, r8, c14, c2, 1

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
pyelftools
pillow