Add default libpayload build, xcompile, and lpgcc setup to tint.
[coreboot.git] / payloads / external / tint / libpayload_tint.patch
1 Patch tint 0.03b to be usable as coreboot payload, linked against
2 the libpayload library. 
3
4 Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
5
6
7 Add default libpayload build, xcompile, and lpgcc setup to tint.
8
9 Signed-off-by: Marc Jones <marc.jones@gmail.com>
10
11 diff -rupN tintorig/Makefile tint/Makefile
12 --- tintorig/Makefile   2005-07-17 05:30:54.000000000 -0600
13 +++ tint/Makefile       2010-08-23 18:06:24.671875000 -0600
14 @@ -28,6 +28,65 @@
15  #  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16  #  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  
18 +$(if $(wildcard .xcompile),,$(eval $(shell bash ./xcompile.sh &> .xcompile)))
19 +include .xcompile
20 +
21 +LIBCONFIG_PATH := ../libpayload
22 +LIBPAYLOAD_DIR := ./libpayloadbin
23 +LPCC := $(LIBPAYLOAD_DIR)/libpayload/bin/lpgcc
24 +LPAS := $(LIBPAYLOAD_DIR)/libpayload/bin/lpas
25 +HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_DIR)/libpayload/lib/libpayload.a)
26 +LIB_CONFIG ?= defconfig 
27 +
28 +# CFLAGS := -Wall -Werror -Os
29 +CFLAGS := -Wall -g -Os
30 +TARGET := tint
31 +OBJS := $(TARGET).o engine.o io.o utils.o
32 +
33 +# Make is silent per default, but 'make V=1' will show all compiler calls.
34 +ifneq ($(V),1)
35 +Q := @
36 +endif
37 +
38 +all: $(TARGET).elf
39 +#      printf" CC   $(CC)\n"
40 +       
41 +$(TARGET).elf: $(OBJS) libpayload
42 +       $(Q)printf "  LPCC      $(subst $(shell pwd)/,,$(@))\n"
43 +       $(Q)$(LPCC) -o $@ $(OBJS)
44 +       $(Q)$(OBJCOPY) --only-keep-debug $@ tint.debug
45 +       $(Q)$(OBJCOPY) --strip-debug $@
46 +       $(Q)$(OBJCOPY) --add-gnu-debuglink=tint.debug $@
47 +       
48 +%.o: %.c libpayload
49 +       $(Q)printf "  LPCC      $(subst $(shell pwd)/,,$(@))\n"
50 +       $(Q)$(LPCC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
51 +
52 +%.S.o: %.S libpayload
53 +       $(Q)printf "  LPAS      $(subst $(shell pwd)/,,$(@))\n"
54 +       $(Q)$(LPAS) $(ASFLAGS) --32 -o $@ $<
55 +
56 +ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
57 +libpayload:
58 +       $(Q)printf "Found Libpayload $(LIBPAYLOAD_DIR).\n"
59 +else
60 +libpayload:
61 +       $(Q)printf "Building libpayload @ $(LIBCONFIG_PATH).\n"
62 +       $(Q)make -C $(LIBCONFIG_PATH) distclean
63 +       $(Q)make -C $(LIBCONFIG_PATH) $(LIB_CONFIG)
64 +       $(Q)make -C $(LIBCONFIG_PATH) DESTDIR=$(shell pwd)/$(LIBPAYLOAD_DIR) install
65 +endif
66 +
67 +clean:
68 +       $(Q)rm -f $(TARGET).elf $(TARGET).debug *.o 
69 +       $(Q)rm .xcompile
70 +
71 +distclean: clean
72 +       $(Q)rm -rf $(LIBPAYLOAD_DIR)
73 +
74 +# Original tint targets
75 +ifdef $(UNUSED)
76 +
77  #CROSS = arm-linux-
78  
79  bindir = $(DESTDIR)/usr/games
80 @@ -110,3 +169,4 @@ clean:
81  distclean: clean
82         $(MAKE) -C debian clean
83  
84 +endif
85 diff -rupN tintorig/config.h tint/config.h
86 --- tintorig/config.h   2001-12-07 16:03:24.000000000 -0700
87 +++ tint/config.h       2010-01-27 13:59:18.000000000 -0700
88 @@ -29,7 +29,16 @@
89   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90   */
91  
92 +#include <libpayload.h>
93 +#include <curses.h>
94 +#define random(x) rand(x)
95 +#define srandom(x) srand(x)
96 +#define curs_set(x)
97 +
98 +
99  /* Score file */
100 +#if 0
101  const char scorefile[] = SCOREFILE;
102 +#endif
103  
104  #endif /* #ifndef CONFIG_H */
105 diff -rupN tintorig/engine.c tint/engine.c
106 --- tintorig/engine.c   2005-07-17 05:26:22.000000000 -0600
107 +++ tint/engine.c       2010-01-27 13:59:18.000000000 -0700
108 @@ -27,8 +27,12 @@
109   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110   */
111  
112 +#include "config.h"
113 +
114 +#if 0
115  #include <stdlib.h>
116  #include <string.h>
117 +#endif
118  
119  #include "typedefs.h"
120  #include "utils.h"
121 diff -rupN tintorig/io.c tint/io.c
122 --- tintorig/io.c       2001-12-07 08:48:20.000000000 -0700
123 +++ tint/io.c   2010-01-27 13:59:18.000000000 -0700
124 @@ -27,9 +27,13 @@
125   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126   */
127  
128 +#include "config.h"
129 +
130 +#if 0
131  #include <stdarg.h>            /* va_list(), va_start(), va_end() */
132  #include <sys/time.h>  /* gettimeofday() */
133  #include <unistd.h>            /* gettimeofday() */
134 +#endif
135  
136  #include <curses.h>
137  
138 @@ -70,7 +74,11 @@ static int in_timeleft;
139  /* Initialize screen */
140  void io_init ()
141  {
142 +   curses_enable_serial(0);
143 +   curses_enable_vga(1);
144     initscr ();
145 +   halfdelay(1);
146 +   timeout(1);
147     start_color ();
148     curs_set (CURSOR_INVISIBLE);
149     out_attr = A_NORMAL;
150 @@ -176,11 +184,17 @@ void out_beep ()
151  /* Read a character. Please note that you MUST call in_timeout() before in_getch() */
152  int in_getch ()
153  {
154 +#if 0
155     struct timeval starttv,endtv;
156 +#endif
157     int ch;
158 +#if 0
159     timeout (in_timeleft / 1000);
160     gettimeofday (&starttv,NULL);
161 +#endif
162     ch = getch ();
163 +   mdelay(150);
164 +#if 0
165     gettimeofday (&endtv,NULL);
166     /* Timeout? */
167     if (ch == ERR)
168 @@ -198,6 +212,7 @@ int in_getch ()
169                 in_timeleft -= endtv.tv_usec;
170                 if (in_timeleft <= 0) in_timeleft = in_timetotal;
171          }
172 +#endif
173     return ch;
174  }
175  
176 diff -rupN tintorig/tint.c tint/tint.c
177 --- tintorig/tint.c     2005-07-17 05:26:43.000000000 -0600
178 +++ tint/tint.c 2010-08-23 18:13:53.281250000 -0600
179 @@ -1,4 +1,3 @@
180 -
181  /*
182   * Copyright (c) Abraham vd Merwe <abz@blio.net>
183   * All rights reserved.
184 @@ -27,6 +26,7 @@
185   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186   */
187  
188 +#if 0
189  #include <stdlib.h>
190  #include <stdio.h>
191  #include <string.h>
192 @@ -34,6 +34,7 @@
193  #include <pwd.h>
194  #include <sys/types.h>
195  #include <unistd.h>
196 +#endif
197  
198  #include "typedefs.h"
199  #include "utils.h"
200 @@ -321,6 +322,7 @@ typedef struct
201     time_t timestamp;
202  } score_t;
203  
204 +#if 0
205  static void getname (char *name)
206  {
207     struct passwd *pw = getpwuid (geteuid ());
208 @@ -337,7 +339,9 @@ static void getname (char *name)
209                 name[NAMELEN - 1] = '\0';
210          }
211  }
212 +#endif
213  
214 +#if 0
215  static void err1 ()
216  {
217     fprintf (stderr,"Error creating %s\n",scorefile);
218 @@ -349,10 +353,11 @@ static void err2 ()
219     fprintf (stderr,"Error writing to %s\n",scorefile);
220     exit (EXIT_FAILURE);
221  }
222 +#endif
223  
224  void showplayerstats (engine_t *engine)
225  {
226 -   fprintf (stderr,
227 +   printf (
228                         "\n\t   PLAYER STATISTICS\n\n\t"
229                         "Score       %11d\n\t"
230                         "Efficiency  %11d\n\t"
231 @@ -360,6 +365,7 @@ void showplayerstats (engine_t *engine)
232                         GETSCORE (engine->score),engine->status.efficiency,GETSCORE (engine->score) / getsum ());
233  }
234  
235 +#if 0
236  static void createscores (int score)
237  {
238     FILE *handle;
239 @@ -394,7 +400,9 @@ static void createscores (int score)
240     fprintf (stderr,"%s",scoretitle);
241     fprintf (stderr,"\t  1* %7d        %s\n\n",score,scores[0].name);
242  }
243 +#endif
244  
245 +#if 0
246  static int cmpscores (const void *a,const void *b)
247  {
248     int result;
249 @@ -412,7 +420,9 @@ static int cmpscores (const void *a,cons
250     /* timestamps is equal */
251     return 0;
252  }
253 +#endif
254  
255 +#if 0
256  static void savescores (int score)
257  {
258     FILE *handle;
259 @@ -490,11 +500,13 @@ static void savescores (int score)
260          }
261     fprintf (stderr,"\n");
262  }
263 +#endif
264  
265            /***************************************************************************/
266            /***************************************************************************/
267            /***************************************************************************/
268  
269 +#if 0
270  static void showhelp ()
271  {
272     fprintf (stderr,"USAGE: tint [-h] [-l level] [-n]\n");
273 @@ -504,9 +516,11 @@ static void showhelp ()
274     fprintf (stderr,"  -d           Draw vertical dotted lines\n");
275     exit (EXIT_FAILURE);
276  }
277 +#endif
278  
279  static void parse_options (int argc,char *argv[])
280  {
281 +#if 0
282     int i = 1;
283     while (i < argc)
284          {
285 @@ -536,10 +550,12 @@ static void parse_options (int argc,char
286                   }
287                 i++;
288          }
289 +#endif
290  }
291  
292  static void choose_level ()
293  {
294 +#if 0
295     char buf[NAMELEN];
296  
297     do
298 @@ -549,6 +565,8 @@ static void choose_level ()
299                 buf[strlen (buf) - 1] = '\0';
300          }
301     while (!str2int (&level,buf) || level < MINLEVEL || level > MAXLEVEL);
302 +#endif
303 +       level = 1;
304  }
305  
306            /***************************************************************************/
307 @@ -663,8 +681,15 @@ int main (int argc,char *argv[])
308     if (ch != 'q')
309          {
310                 showplayerstats (&engine);
311 +#if 0
312                 savescores (GETSCORE (engine.score));
313 +#endif
314          }
315 +   printf("Bye.\n");
316 +   refresh();
317 +   for(;;); //halt();
318 +#if 0
319     exit (EXIT_SUCCESS);
320 +#endif
321  }
322  
323 diff -rupN tintorig/utils.c tint/utils.c
324 --- tintorig/utils.c    2001-12-07 08:49:19.000000000 -0700
325 +++ tint/utils.c        2010-01-27 13:59:18.000000000 -0700
326 @@ -27,9 +27,13 @@
327   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
328   */
329  
330 +#include "config.h"
331 +
332 +#if 0
333  #include <stdlib.h>
334  #include <time.h>
335  #include <limits.h>
336 +#endif
337  
338  #include "typedefs.h"
339  
340 @@ -41,8 +45,11 @@ void rand_init ()
341  #ifdef USE_RAND
342     srand (time (NULL));
343  #else
344 +#if 0
345     srandom (time (NULL));
346  #endif
347 +   srandom (123);
348 +#endif
349  }
350  
351  /*
352 @@ -61,6 +68,7 @@ int rand_value (int range)
353   * Convert an str to long. Returns TRUE if successful,
354   * FALSE otherwise.
355   */
356 +#if 0
357  bool str2int (int *i,const char *str)
358  {
359     char *endptr;
360 @@ -69,3 +77,4 @@ bool str2int (int *i,const char *str)
361     return TRUE;
362  }
363  
364 +#endif
365 diff -rupN tintorig/xcompile.sh tint/xcompile.sh
366 --- tintorig/xcompile.sh        1969-12-31 17:00:00.000000000 -0700
367 +++ tint/xcompile.sh    2010-03-10 15:34:51.421875000 -0700
368 @@ -0,0 +1,76 @@
369 +#!/bin/bash
370 +
371 +CONFIG=defconfig
372 +SCRIPT_DIR=`dirname "$0"`
373 +
374 +for make in make gmake gnumake; do
375 +       if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then
376 +               MAKE=$make
377 +               break
378 +       fi
379 +done
380 +
381 +GCCPREFIX=invalid
382 +for gccprefixes in `pwd`/$SCRIPT_DIR/../../util/crossgcc/xgcc/bin/i386-elf- i386-elf- ""; do
383 +       TMP=`mktemp /tmp/temp.XXXX`
384 +       echo "mov %eax, %eax" > ${TMP}.s
385 +       printf "\x7fELF" > ${TMP}.compare
386 +       if which ${gccprefixes}as 2>/dev/null >/dev/null; then
387 +               printf ""
388 +       else
389 +               continue
390 +       fi
391 +       if ${gccprefixes}as --32 -o ${TMP}.o ${TMP}.s; then
392 +               dd bs=4 count=1 if=${TMP}.o > ${TMP}.test 2>/dev/null
393 +               if cmp ${TMP}.test ${TMP}.compare; then
394 +                       GCCPREFIX=$gccprefixes
395 +                       rm -f $TMP ${TMP}.s ${TMP}.o ${TMP}.compare ${TMP}.test
396 +                       break
397 +               fi
398 +       fi
399 +       rm -f $TMP ${TMP}.s ${TMP}.o ${TMP}.compare ${TMP}.test
400 +done
401 +
402 +if [ "$GCCPREFIX" = "invalid" ]; then
403 +       echo no suitable gcc found
404 +       exit 1
405 +fi
406 +
407 +#MAKEFLAGS=" \
408 +#      AS=\"${GCCPREFIX}as --32\"              \
409 +#      CC=\"${GCCPREFIX}gcc -m32\"             \
410 +#      AR=\"${GCCPREFIX}ar\"                   \
411 +#      LD=\"${GCCPREFIX}ld -b elf32-i386\"     \
412 +#      STRIP=\"${GCCPREFIX}strip\"             \
413 +#      NM=\"${GCCPREFIX}nm\"                   \
414 +#      HOSTCC=gcc                              \
415 +#      -j                                      \
416 +#"
417 +
418 +cat << afteroptions
419 +export AS:=${GCCPREFIX}as --32
420 +export CC:=${GCCPREFIX}gcc -m32
421 +export CPP:=${GCCPREFIX}cpp
422 +export AR:=${GCCPREFIX}ar
423 +export LD:=${GCCPREFIX}ld -b elf32-i386
424 +export STRIP:=${GCCPREFIX}strip
425 +export NM:=${GCCPREFIX}nm
426 +export OBJCOPY:=${GCCPREFIX}objcopy
427 +export OBJDUMP:=${GCCPREFIX}objdump
428 +export HOSTCC:=gcc
429 +afteroptions
430 +
431 +# Should we let the payload build libpayload or do it for them?
432 +#test -d ./build || (
433 +#      BUILDDIR=$PWD
434 +#      cd ../libpayload
435 +#      $MAKE distclean
436 +#      cp configs/$CONFIG .config
437 +#      $MAKE oldconfig
438 +#      eval $MAKE $MAKEFLAGS
439 +#      eval $MAKE $MAKEFLAGS DESTDIR=$BUILDDIR/build install 
440 +#      cd ..
441 +#)
442 +
443 +# eval $MAKE -C $SCRIPT_DIR $MAKEFLAGS
444 +