Skip to content

Commit

Permalink
fixup! HACK: tools: amlimage: Add support for GXBB eMMC header
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwiboo committed Aug 30, 2023
1 parent 8807554 commit 37f9564
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions tools/amlimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,38 +216,56 @@ static int amlimage_check_image_type(uint8_t type)
/*
* AArch64 assembly to relocate payload when booting from eMMC on GXBB.
* Payload is relocated from offset 0x1200 to 0x1000 in TZRAM, similar to:
* memcpy(0xd9001000, 0xd9001200, 0xb000)
* flush_dcache_range(0xd9001000, 0xd900c000)
* memmove(0xd9001000, 0xd9001200, 0xb000)
* goto 0xd9001000
*/
static const uint8_t gxbb_relocate[] = {
0xF4, 0x03, 0x00, 0xAA, 0xF5, 0x03, 0x01, 0xAA, 0xA0, 0x00, 0x38, 0xD5,
0x35, 0x00, 0x00, 0x94, 0x40, 0x01, 0x00, 0xB4, 0x00, 0x10, 0x38, 0xD5,
0x00, 0x00, 0x74, 0xB2, 0x00, 0x10, 0x18, 0xD5, 0xDF, 0x3F, 0x03, 0xD5,
0xA0, 0x00, 0x38, 0xD5, 0x22, 0x00, 0x00, 0x94, 0xA0, 0x00, 0x38, 0xD5,
0x26, 0x00, 0x00, 0x94, 0x12, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x14,
0xFD, 0x7B, 0xBF, 0xA9, 0x01, 0x40, 0x82, 0xD2, 0x00, 0x00, 0x82, 0xD2,
0xFD, 0x03, 0x00, 0x91, 0x02, 0x00, 0x96, 0xD2, 0x01, 0x20, 0xBB, 0xF2,
0x00, 0x20, 0xBB, 0xF2, 0x0D, 0x00, 0x00, 0x94, 0x00, 0x00, 0x82, 0xD2,
0x01, 0x00, 0x96, 0xD2, 0x00, 0x20, 0xBB, 0xF2, 0x22, 0x00, 0x00, 0x94,
0x00, 0x00, 0x82, 0xD2, 0xFD, 0x7B, 0xC1, 0xA8, 0x00, 0x20, 0xBB, 0xF2,
0x00, 0x00, 0x1F, 0xD6, 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91,
0xEE, 0xFF, 0xFF, 0x97, 0x00, 0x00, 0x00, 0x14, 0x03, 0x00, 0x80, 0xD2,
0x7F, 0x00, 0x02, 0xEB, 0xA0, 0x00, 0x00, 0x54, 0x24, 0x68, 0x63, 0x38,
0x04, 0x68, 0x23, 0x38, 0x63, 0x04, 0x00, 0x91, 0xFB, 0xFF, 0xFF, 0x17,
0xC0, 0x03, 0x5F, 0xD6, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x58,
0x1F, 0x00, 0x00, 0x91, 0xC0, 0x03, 0x5F, 0xD6, 0x00, 0x00, 0x00, 0x00,
0x40, 0x0C, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x58,
0x1F, 0x00, 0x00, 0x91, 0xC0, 0x03, 0x5F, 0xD6, 0x00, 0x00, 0x00, 0x00,
0x40, 0x09, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x92,
0x1F, 0x00, 0x00, 0xF1, 0xE0, 0x17, 0x9F, 0x9A, 0xC0, 0x03, 0x5F, 0xD6,
0x23, 0x00, 0x3B, 0xD5, 0x63, 0x4C, 0x50, 0xD3, 0x82, 0x00, 0x80, 0xD2,
0x42, 0x20, 0xC3, 0x9A, 0x01, 0x00, 0x01, 0x8B, 0x43, 0x04, 0x00, 0xD1,
0x00, 0x00, 0x23, 0x8A, 0x20, 0x7E, 0x0B, 0xD5, 0x00, 0x00, 0x02, 0x8B,
0x1F, 0x00, 0x01, 0xEB, 0xA3, 0xFF, 0xFF, 0x54, 0x9F, 0x3F, 0x03, 0xD5,
0xC0, 0x03, 0x5F, 0xD6,
0x00, 0x40, 0x82, 0xD2, 0x00, 0x20, 0xBB, 0xF2, 0x01, 0x2C, 0x40, 0x91,
0x02, 0x20, 0x40, 0xD1, 0x00, 0x20, 0x00, 0x91, 0x03, 0x80, 0x5F, 0xF8,
0x43, 0x00, 0x3F, 0xF9, 0x1F, 0x00, 0x01, 0xEB, 0x61, 0xFF, 0xFF, 0x54,
0x00, 0x00, 0x82, 0xD2, 0x00, 0x20, 0xBB, 0xF2, 0x00, 0x00, 0x1F, 0xD6,
};

/*
cat <<EOF | aarch64-linux-gnu-gcc -ffreestanding -Os -S -o- -xc -
void main(void)
{
unsigned long *src = (void*)0xd9001200, *dst = (void*)0xd9001000;
for (int i = 0; i < (0xb000 / sizeof(unsigned long)); i++)
*(dst + i) = *(src + i);
goto *dst;
}
EOF
cat <<EOF | aarch64-linux-gnu-as -o gxbb-relocate.o -
_start:
mov x0, 4608
movk x0, 0xd900, lsl 16
add x1, x0, 45056
.loop:
sub x2, x0, #32768
add x0, x0, 8
ldr x3, [x0, -8]
str x3, [x2, 32256]
cmp x0, x1
bne .loop
mov x0, 4096
movk x0, 0xd900, lsl 16
br x0
EOF
aarch64-linux-gnu-objcopy -O binary -j .text gxbb-relocate.o gxbb-relocate.bin
hexdump gxbb-relocate.bin
00000000 00 40 82 d2 00 20 bb f2 01 2c 40 91 02 20 40 d1 |.@... ...,@.. @.|
00000010 00 20 00 91 03 80 5f f8 43 00 3f f9 1f 00 01 eb |. ...._.C.?.....|
00000020 61 ff ff 54 00 00 82 d2 00 20 bb f2 00 00 1f d6 |a..T..... ......|
00000030
*/

static int amlimage_vrec_header(struct image_tool_params *params,
struct image_type_params *tparams)
{
Expand Down

0 comments on commit 37f9564

Please sign in to comment.