mirror of
https://github.com/brain-hackers/boot4u
synced 2025-11-08 16:38:36 +09:00
Compare commits
5 Commits
main
...
show-pictu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08ad49b627 | ||
|
|
4b5601c738 | ||
| 4cb07e77bb | |||
| cbf1b89241 | |||
| 0a091e3515 |
15
Makefile
15
Makefile
@@ -4,12 +4,19 @@ CC:=$(CROSS_COMPILE)gcc
|
|||||||
STRIP:=$(CROSS_COMPILE)strip
|
STRIP:=$(CROSS_COMPILE)strip
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
all: AppMain.bin
|
all: AppMain.bin m4_loader.bin
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
clean:
|
clean:
|
||||||
@rm -f *.bin *.elf
|
@rm -f *.bin *.elf pixels.c
|
||||||
|
|
||||||
AppMain.bin:
|
pixels.c:
|
||||||
@$(AS) main.S -o main.elf
|
@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
|
@./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
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -1,11 +1,22 @@
|
|||||||
# boot4u
|
# boot4u
|
||||||
U-Boot loader for PW-x1
|
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
|
# Build
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
apt install gcc-arm-linux-gnueabihf
|
|
||||||
pip3 install pyelftools
|
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
34
img2c.py
Normal file
34
img2c.py
Normal 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
40
m4_loader.S
Normal 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
|
||||||
60
main.S
60
main.S
@@ -3,6 +3,55 @@
|
|||||||
.global _start
|
.global _start
|
||||||
|
|
||||||
_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
|
//preload U-Boot from sd
|
||||||
ldr r4, =0x60006400 //fopen addr
|
ldr r4, =0x60006400 //fopen addr
|
||||||
adr r0, [.LC0] //file name
|
adr r0, [.LC0] //file name
|
||||||
@@ -20,6 +69,10 @@ _start:
|
|||||||
.ascii "SD0:\\u-boot.bin\000"
|
.ascii "SD0:\\u-boot.bin\000"
|
||||||
.LC1:
|
.LC1:
|
||||||
.ascii "r\000"
|
.ascii "r\000"
|
||||||
|
.LC2:
|
||||||
|
.ascii "SD0:\\m4_loader.bin\000"
|
||||||
|
.LC3:
|
||||||
|
.ascii "SD0:\\m4_rtos.bin\000"
|
||||||
.align 4
|
.align 4
|
||||||
continue:
|
continue:
|
||||||
cpsid if //disable interrupt
|
cpsid if //disable interrupt
|
||||||
@@ -46,6 +99,13 @@ _start:
|
|||||||
str r1,[r2],#4
|
str r1,[r2],#4
|
||||||
beq clear_loop
|
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
|
ldr r0, =0x60000000
|
||||||
|
|
||||||
mrc p15, 0, r8, c14, c2, 1
|
mrc p15, 0, r8, c14, c2, 1
|
||||||
|
|||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pyelftools
|
||||||
|
pillow
|
||||||
Reference in New Issue
Block a user