Skip to content

Commit 23d4749

Browse files
author
nlaredo
committed
new review:
owner: [email protected] summary: build cleanup including proper checksum and image padding git-svn-id: http://sgabios.googlecode.com/svn/trunk@8 ca484b36-2546-0410-af21-7957cbf944c2
1 parent 8eb5346 commit 23d4749

File tree

5 files changed

+1697
-1433
lines changed

5 files changed

+1697
-1433
lines changed

Makefile

+56-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2007 Google Inc.
1+
# Copyright 2010 Google Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -14,22 +14,65 @@
1414
#
1515
# $Id$
1616

17-
CFLAGS = -Wall -O2 -s
17+
BUILD_DATE = \"$(shell date -u)\"
18+
BUILD_SHORT_DATE = \"$(shell date -u +%D)\"
19+
BUILD_HOST = \"$(shell hostname)\"
20+
BUILD_USER = \"$(shell whoami)\"
1821

19-
.SUFFIXES: .bin
22+
CFLAGS := -Wall -Os -m32 -nostdlib
2023

21-
all: sgabios.bin
24+
ASFLAGS := $(CFLAGS)
25+
ASFLAGS += -DBUILD_DATE="$(BUILD_DATE)"
26+
ASFLAGS += -DBUILD_SHORT_DATE="$(BUILD_SHORT_DATE)"
27+
ASFLAGS += -DBUILD_HOST="$(BUILD_HOST)"
28+
ASFLAGS += -DBUILD_USER="$(BUILD_USER)"
2229

23-
sgabios.bin: sgabios.S version.h
30+
LDSCRIPT := rom16.ld
31+
LDFLAGS := -T $(LDSCRIPT) -nostdlib
32+
OBJCOPY := objcopy
2433

25-
version.h: Makefile sgabios.S
26-
@echo '#define BIOS_BUILD_DATE "'`date -u +%D`'"' >version.h
27-
@echo '#define BIOS_FULL_DATE "'`date -u`'"' >>version.h
28-
@echo '#define BIOS_BUILD_HOST "'`echo $$LOGNAME@$$HOSTNAME`'"' >>version.h
34+
ASRCS = sgabios.S
2935

30-
.S.bin:
31-
$(CC) -c $(CFLAGS) $*.S -o $*.o
32-
$(LD) -Ttext 0x0 -s --oformat binary $*.o -o $*.bin
36+
CSRCS =
3337

38+
SRCS = $(CSRCS) $(ASRCS)
39+
40+
OBJS = ${CSRCS:.c=.o} ${ASRCS:.S=.o}
41+
INCS = ${CSRCS:.c=.h} ${ASRCS:.S=.h}
42+
43+
PROGS = sgabios.bin csum8
44+
45+
.SUFFIXES: .bin .elf
46+
.PHONY: buildinfo
47+
48+
all: $(PROGS)
49+
50+
sgabios.bin: sgabios.elf
51+
$(OBJCOPY) -O binary $< $@
52+
./csum8 $@
53+
54+
sgabios.elf: .depend $(OBJS) $(LDSCRIPT) csum8
55+
$(LD) $(LDFLAGS) $(OBJS) -o $@
56+
57+
csum8: csum8.c
58+
$(CC) -Wall -O2 -o $@ $<
59+
60+
sgabios.o: buildinfo
61+
62+
63+
buildinfo:
64+
touch sgabios.S
3465
clean:
35-
$(RM) *.s *.o *.bin *.srec *.com version.h
66+
$(RM) $(PROGS) $(OBJS) *.elf *.srec *.com version.h
67+
68+
.depend:: $(INCS) $(SRCS) Makefile
69+
$(RM) .depend
70+
$(CPP) -M $(CFLAGS) $(SRCS) >.tmpdepend && mv .tmpdepend .depend
71+
72+
ifeq (.depend, $(wildcard .depend))
73+
include .depend
74+
else
75+
# if no .depend file existed, add a make clean to the end of building .depend
76+
.depend::
77+
$(MAKE) clean
78+
endif

csum8.c

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2010 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* compute rom checksum byte
17+
*/
18+
19+
#include <stdio.h>
20+
#include <unistd.h>
21+
#include <stdlib.h>
22+
#include <fcntl.h>
23+
#include <sys/types.h>
24+
25+
#define MAX_SIZE 65536
26+
unsigned char buf[MAX_SIZE];
27+
28+
int main(int argc, char **argv)
29+
{
30+
ssize_t fsize;
31+
int i, sum, fd;
32+
unsigned char csum;
33+
34+
if (argc < 2) {
35+
fprintf(stderr, "usage: %s filename\n", argv[0]);
36+
exit(1);
37+
}
38+
if ((fd = open(argv[1], O_RDWR)) < 0) {
39+
perror(argv[1]);
40+
exit(1);
41+
}
42+
if ((fsize = read(fd, buf, MAX_SIZE)) < 0) {
43+
perror(argv[1]);
44+
exit(1);
45+
}
46+
if (fsize >= MAX_SIZE && read(fd, &buf[MAX_SIZE - 1], 1) > 0) {
47+
fprintf(stderr, "FAIL: %s is larger than %d bytes\n", argv[1], MAX_SIZE);
48+
exit(1);
49+
}
50+
i = fsize - 2048 * (fsize / 2048);
51+
if (i != 2047) {
52+
fprintf(stderr, "FAIL: %s is %zd bytes, need 2K pad-1\n", argv[1], fsize);
53+
exit(1);
54+
}
55+
for (i = sum = 0; i < fsize; i++) {
56+
sum += buf[i];
57+
}
58+
sum &= 0xff;
59+
csum = -sum & 0xff;
60+
write(fd, &csum, 1);
61+
close(fd);
62+
fprintf(stderr, "%s: sum = 0x%02x, wrote byte 0x%02x\n", argv[1], sum, csum);
63+
return 0;
64+
}

rom16.ld

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Linker script for ROM16 binaries
3+
*/
4+
5+
/* Script for -z combreloc: combine and sort reloc sections */
6+
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
7+
"elf32-i386")
8+
OUTPUT_ARCH(i386)
9+
EXTERN(_start)
10+
ENTRY(_start)
11+
SECTIONS
12+
{
13+
/* Read-only sections, merged into text segment: */
14+
. = 0x0;
15+
PROVIDE (__executable_start = .);
16+
17+
.init :
18+
{
19+
KEEP (*(.init))
20+
} =0x90909090
21+
.text :
22+
{
23+
*(.text .stub .text.* .gnu.linkonce.t.*)
24+
/* .gnu.warning sections are handled specially by elf32.em. */
25+
*(.gnu.warning)
26+
} =0x90909090
27+
.fini :
28+
{
29+
KEEP (*(.fini))
30+
} =0x90909090
31+
PROVIDE (__etext = .);
32+
PROVIDE (_etext = .);
33+
PROVIDE (etext = .);
34+
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
35+
.rodata1 : { *(.rodata1) }
36+
37+
/* Ensure the __preinit_array_start label is properly aligned. We
38+
could instead move the label definition inside the section, but
39+
the linker would then create the section even if it turns out to
40+
be empty, which isn't pretty. */
41+
. = ALIGN(4);
42+
PROVIDE (__preinit_array_start = .);
43+
.preinit_array : { *(.preinit_array) }
44+
PROVIDE (__preinit_array_end = .);
45+
PROVIDE (__init_array_start = .);
46+
.init_array : { *(.init_array) }
47+
PROVIDE (__init_array_end = .);
48+
PROVIDE (__fini_array_start = .);
49+
.fini_array : { *(.fini_array) }
50+
PROVIDE (__fini_array_end = .);
51+
PROVIDE (__ctors_start = .);
52+
.ctors :
53+
{
54+
KEEP (*(SORT(.ctors.*)))
55+
KEEP (*(.ctors))
56+
}
57+
PROVIDE (__ctors_end = .);
58+
PROVIDE (__dtors_start = .);
59+
.dtors :
60+
{
61+
KEEP (*(SORT(.dtors.*)))
62+
KEEP (*(.dtors))
63+
}
64+
PROVIDE (__dtors_end = .);
65+
66+
/* Adjust the address for the data segment. Avoid mixing code and
67+
data within same 128-byte chunk. */
68+
. = ALIGN(128);
69+
70+
.data :
71+
{
72+
*(.data .data.* .gnu.linkonce.d.*)
73+
SORT(CONSTRUCTORS)
74+
}
75+
.data1 : { *(.data1) }
76+
_edata = .;
77+
PROVIDE (edata = .);
78+
__bss_start = .;
79+
.bss :
80+
{
81+
*(.dynbss)
82+
*(.bss .bss.* .gnu.linkonce.b.*)
83+
*(COMMON)
84+
/* Align here to ensure that the .bss section occupies space up to
85+
_end. Align after .bss to ensure correct alignment even if the
86+
.bss section disappears because there are no input sections. */
87+
. = ALIGN(32 / 8);
88+
}
89+
.csum :
90+
{
91+
. = ALIGN(2048) - 5;
92+
LONG(0xff4c494e);
93+
/* BYTE(_rom_size_byte); */
94+
} =0xffffffff
95+
_end = .;
96+
PROVIDE (end = .);
97+
PROVIDE(_rom_size_byte = (511 + end) / 512);
98+
99+
/* Stabs debugging sections. */
100+
.stab 0 : { *(.stab) }
101+
.stabstr 0 : { *(.stabstr) }
102+
.stab.excl 0 : { *(.stab.excl) }
103+
.stab.exclstr 0 : { *(.stab.exclstr) }
104+
.stab.index 0 : { *(.stab.index) }
105+
.stab.indexstr 0 : { *(.stab.indexstr) }
106+
.comment 0 : { *(.comment) }
107+
/* DWARF debug sections.
108+
Symbols in the DWARF debugging sections are relative to the beginning
109+
of the section so we begin them at 0. */
110+
/* DWARF 1 */
111+
.debug 0 : { *(.debug) }
112+
.line 0 : { *(.line) }
113+
/* GNU DWARF 1 extensions */
114+
.debug_srcinfo 0 : { *(.debug_srcinfo) }
115+
.debug_sfnames 0 : { *(.debug_sfnames) }
116+
/* DWARF 1.1 and DWARF 2 */
117+
.debug_aranges 0 : { *(.debug_aranges) }
118+
.debug_pubnames 0 : { *(.debug_pubnames) }
119+
/* DWARF 2 */
120+
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
121+
.debug_abbrev 0 : { *(.debug_abbrev) }
122+
.debug_line 0 : { *(.debug_line) }
123+
.debug_frame 0 : { *(.debug_frame) }
124+
.debug_str 0 : { *(.debug_str) }
125+
.debug_loc 0 : { *(.debug_loc) }
126+
.debug_macinfo 0 : { *(.debug_macinfo) }
127+
/* SGI/MIPS DWARF 2 extensions */
128+
.debug_weaknames 0 : { *(.debug_weaknames) }
129+
.debug_funcnames 0 : { *(.debug_funcnames) }
130+
.debug_typenames 0 : { *(.debug_typenames) }
131+
.debug_varnames 0 : { *(.debug_varnames) }
132+
/DISCARD/ : { *(.note.GNU-stack) }
133+
}

0 commit comments

Comments
 (0)