Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it usable on non-x86-64 systems #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions linux-3.4/arch/arm/mach-sunxi/power/brom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
always := resumes.code
targets := resumes.elf

hostprogs-y := mksunxichecksum
#always += $(hostprogs-y)

#use "-Os" flags.
#Don't use "-O2" flags.
KBUILD_CFLAGS := -g -c -nostdlib -march=armv7-a -marm -fno-unwind-tables -fno-asynchronous-unwind-tables -mlittle-endian -O2 --min_array_alignment=4 --no_unaligned_access
KBUILD_CFLAGS := -g -c -nostdlib -march=armv7-a -marm \
-fno-unwind-tables -fno-asynchronous-unwind-tables -mlittle-endian -Os
# --min_array_alignment=4 --no_unaligned_acces

#Include the cur dir.
KBUILD_CPPFLAGS += -I.
Expand All @@ -22,21 +27,21 @@ resumes-y := resumes.o \

resumes-y := $(addprefix $(obj)/,$(resumes-y))

$(obj)/resumes.code: $(obj)/resumes.bin
$(Q)$(obj)/gen_check_code $(obj)/resumes.bin $(obj)/resumes.code
$(obj)/resumes.code: $(obj)/resumes.bin $(obj)/mksunxichecksum
$(obj)/mksunxichecksum $(obj)/resumes.bin $(obj)/resumes.code

$(obj)/resumes.bin: $(obj)/resumes.elf FORCE
$(Q)$(CROSS_COMPILE)objcopy -O binary $(obj)/resumes.elf $(obj)/resumes.bin

ifneq ($(strip $(CONFIG_ARCH_SUN9I)),)
$(obj)/resumes.elf: $(obj)/sun9i_brom_scatter.scat $(resumes-y)
$(Q)$(CROSS_COMPILE)ld -T $(obj)/sun9i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
$(obj)/resumes.elf: $(srctree)/$(src)/sun9i_brom_scatter.scat $(resumes-y)
$(Q)$(CROSS_COMPILE)ld -T $(srctree)/$(src)/sun9i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
$(Q)$(CROSS_COMPILE)objdump -D $(obj)/resumes.elf > $(obj)/resumes.lst
endif

ifneq ($(strip $(CONFIG_ARCH_SUN8I)),)
$(obj)/resumes.elf: $(obj)/sun8i_brom_scatter.scat $(resumes-y)
$(Q)$(CROSS_COMPILE)ld -T $(obj)/sun8i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
$(obj)/resumes.elf: $(srctree)/$(src)/sun8i_brom_scatter.scat $(resumes-y)
$(Q)$(CROSS_COMPILE)ld -T $(srctree)/$(src)/sun8i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
$(Q)$(CROSS_COMPILE)objdump -D $(obj)/resumes.elf > $(obj)/resumes.lst
endif

Expand Down
Binary file not shown.
98 changes: 98 additions & 0 deletions linux-3.4/arch/arm/mach-sunxi/power/brom/mksunxichecksum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* (C) Copyright 2015 Jean-Francois Moine
* (C) Copyright 2014 Henrik Nordstrom
*
* Based on mksunxiboot
*
* (C) Copyright 2007-2011
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>

/* boot head definition from sun4i boot code */
struct boot_file_head {
uint32_t b_instruction; /* one intruction jumping to real code */
uint8_t magic[8]; /* ="eGON.BT0" or "eGON.BT1", not C-style str */
uint32_t check_sum; /* generated by PC */
uint32_t length; /* generated by PC */
/*
* We use a simplified header, only filling in what is needed
* for checksum calculation.
*/
};

#define STAMP_VALUE 0x5F0A6C39

/* check sum functon from sun4i boot code */
static int gen_check_sum(struct boot_file_head *head_p)
{
uint32_t length;
uint32_t *buf;
uint32_t loop;
uint32_t i;
uint32_t sum;

length = head_p->length;
// if ((length & 0x3) != 0) /* must 4-byte-aligned */
// return -1;
buf = (uint32_t *)head_p;
head_p->check_sum = STAMP_VALUE; /* fill stamp */
loop = length >> 2;

/* calculate the sum */
for (i = 0, sum = 0; i < loop; i++)
sum += buf[i];

/* write back check sum */
head_p->check_sum = sum;

return 0;
}

int main(int argc, char *argv[])
{
struct boot_file_head h, *buf;
unsigned file_size;
FILE *f;

if (argc != 3) {
printf("Usage: %s file.bin file.code\n"
"calculates BROM checksum in boot header of given .bin file and writes to .code file\n"
"", argv[0]);
exit(1);
}

f = fopen(argv[1], "rb");
if (!f) {
perror("Open input file");
exit(1);
}

fread(&h, 1, sizeof h, f);
file_size = h.length; // wanted length

buf = malloc(file_size);
memset(buf, 0xff, file_size);
rewind(f);

fread(buf, 1, file_size, f);
fclose(f);

gen_check_sum(buf);

f = fopen(argv[2], "wb");
if (!f) {
perror("Open output file");
exit(1);
}
fwrite(buf, 1, file_size, f);
fclose(f);

return 0;
}