2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 sprintf (buf
, "%04X ", 0);
34 for (i
= 0; i
< data (); i
++)
36 sprintf (buf
, "%02x ", data
[i
]);
40 sprintf (buf
, "\n%04X ", i
+ 1);
49 STR_Stream::fromArray (const CArray
& c
)
52 assert (((c
[0] << 8) | c
[1]) + 2 == c ());
55 switch (c
[2] << 8 | c
[3])
58 i
= new STR_StringParameter ();
61 i
= new STR_IntParameter ();
64 i
= new STR_FloatParameter ();
67 i
= new STR_ListParameter ();
70 i
= new STR_GroupObject ();
73 i
= new STR_BCUType ();
76 i
= new STR_BCU2Start ();
82 i
= new STR_BCU1Size ();
85 i
= new STR_BCU2Size ();
88 i
= new STR_BCU2Key ();
91 i
= new STR_Unknown ();
97 i
= new STR_Invalid ();
102 STR_Invalid::STR_Invalid ()
107 STR_Invalid::init (const CArray
& c
)
114 STR_Invalid::toArray ()
120 STR_Invalid::decode ()
124 sprintf (buf
, "Invalid:\n");
126 return s
+ HexDump (data
);
130 STR_Unknown::STR_Unknown ()
136 STR_Unknown::init (const CArray
& c
)
138 data
.set (c
.array () + 4, c () - 4);
139 type
= c
[2] << 8 | c
[3];
144 STR_Unknown::toArray ()
147 uint16_t len
= 2 + data ();
149 d
[0] = (len
>> 8) & 0xff;
151 d
[2] = (type
>> 8) & 0xff;
152 d
[3] = (type
) & 0xff;
158 STR_Unknown::decode ()
162 sprintf (buf
, "Unknown %04x:\n", type
);
164 return s
+ HexDump (data
);
167 STR_BCUType::STR_BCUType ()
173 STR_BCUType::init (const CArray
& c
)
177 bcutype
= c
[4] << 8 | c
[5];
182 STR_BCUType::toArray ()
187 d
[0] = (len
>> 8) & 0xff;
189 d
[2] = (L_BCU_TYPE
>> 8) & 0xff;
190 d
[3] = (L_BCU_TYPE
) & 0xff;
191 d
[4] = (bcutype
>> 8) & 0xff;
192 d
[5] = (bcutype
) & 0xff;
197 STR_BCUType::decode ()
200 sprintf (buf
, "Maskversion: %04x\n", bcutype
);
204 STR_Code::STR_Code ()
209 STR_Code::init (const CArray
& c
)
211 code
.set (c
.array () + 4, c () - 4);
219 uint16_t len
= 2 + code ();
221 d
[0] = (len
>> 8) & 0xff;
223 d
[2] = (L_CODE
>> 8) & 0xff;
224 d
[3] = (L_CODE
) & 0xff;
235 sprintf (buf
, "Code:\n");
237 return s
+ HexDump (code
);
240 STR_StringParameter::STR_StringParameter ()
247 STR_StringParameter::init (const CArray
& c
)
252 addr
= c
[4] << 8 | c
[5];
253 length
= c
[6] << 8 | c
[7];
259 if (d
!= &c
[c () - 1])
261 name
= (const char *) c
.array () + 8;
266 STR_StringParameter::toArray ()
269 uint16_t len
= 7 + strlen (name ());
271 d
[0] = (len
>> 8) & 0xff;
273 d
[2] = (L_STRING_PAR
>> 8) & 0xff;
274 d
[3] = (L_STRING_PAR
) & 0xff;
275 d
[4] = (addr
>> 8) & 0xff;
276 d
[5] = (addr
) & 0xff;
277 d
[6] = (length
>> 8) & 0xff;
278 d
[7] = (length
) & 0xff;
279 d
.setpart ((const uchar
*) name (), 8, strlen (name ()) + 1);
284 STR_StringParameter::decode ()
287 sprintf (buf
, "StringParameter: addr=%04x id=%s length=%d\n", addr
, name (),
292 STR_IntParameter::STR_IntParameter ()
299 STR_IntParameter::init (const CArray
& c
)
304 addr
= c
[4] << 8 | c
[5];
305 type
= (int8_t) c
[6];
311 if (d
!= &c
[c () - 1])
313 name
= (const char *) c
.array () + 7;
318 STR_IntParameter::toArray ()
321 uint16_t len
= 6 + strlen (name ());
323 d
[0] = (len
>> 8) & 0xff;
325 d
[2] = (L_INT_PAR
>> 8) & 0xff;
326 d
[3] = (L_INT_PAR
) & 0xff;
327 d
[4] = (addr
>> 8) & 0xff;
328 d
[5] = (addr
) & 0xff;
329 d
[6] = (type
) & 0xff;
330 d
.setpart ((const uchar
*) name (), 7, strlen (name ()) + 1);
335 STR_IntParameter::decode ()
338 sprintf (buf
, "IntParameter: addr=%04x id=%s type=%s %d bytes\n", addr
,
339 name (), type
< 0 ? "signed" : "unsigned", 1 << (abs (type
) - 1));
343 STR_FloatParameter::STR_FloatParameter ()
349 STR_FloatParameter::init (const CArray
& c
)
354 addr
= c
[4] << 8 | c
[5];
360 if (d
!= &c
[c () - 1])
362 name
= (const char *) c
.array () + 6;
367 STR_FloatParameter::toArray ()
370 uint16_t len
= 5 + strlen (name ());
372 d
[0] = (len
>> 8) & 0xff;
374 d
[2] = (L_FLOAT_PAR
>> 8) & 0xff;
375 d
[3] = (L_FLOAT_PAR
) & 0xff;
376 d
[4] = (addr
>> 8) & 0xff;
377 d
[5] = (addr
) & 0xff;
378 d
.setpart ((const uchar
*) name (), 6, strlen (name ()) + 1);
383 STR_FloatParameter::decode ()
386 sprintf (buf
, "FloatParameter: addr=%04x id=%s\n", addr
, name ());
390 STR_ListParameter::STR_ListParameter ()
396 STR_ListParameter::init (const CArray
& c
)
402 addr
= c
[4] << 8 | c
[5];
403 el
= c
[6] << 8 | c
[7];
410 if (d
> &c
[c () - 1])
412 name
= (const char *) d1
;
414 if (d
> &c
[c () - 1])
416 elements
.resize (el
);
417 for (i
= 0; i
< el
; i
++)
421 if (d
> &c
[c () - 1])
423 elements
[i
] = (const char *) d1
;
434 STR_ListParameter::toArray ()
438 uint16_t len
= 7 + strlen (name ());
439 for (i
= 0; i
< elements (); i
++)
440 len
+= strlen (elements
[i
] ()) + 1;
442 d
[0] = (len
>> 8) & 0xff;
444 d
[2] = (L_LIST_PAR
>> 8) & 0xff;
445 d
[3] = (L_LIST_PAR
) & 0xff;
446 d
[4] = (addr
>> 8) & 0xff;
447 d
[5] = (addr
) & 0xff;
448 d
[6] = (elements () >> 8) & 0xff;
449 d
[7] = (elements ()) & 0xff;
450 d
.setpart ((const uchar
*) name (), 8, strlen (name ()) + 1);
451 p
= 8 + strlen (name ()) + 1;
452 for (i
= 0; i
< elements (); p
+= strlen (elements
[i
] ()) + 1, i
++)
453 d
.setpart ((const uchar
*) elements
[i
] (), p
,
454 strlen (elements
[i
] ()) + 1);
459 STR_ListParameter::decode ()
463 sprintf (buf
, "ListParameter: addr=%04x id=%s elements=", addr
, name ());
465 for (int i
= 0; i
< elements (); i
++)
467 sprintf (buf
, "%s,", elements
[i
] ());
474 STR_GroupObject::STR_GroupObject ()
480 STR_GroupObject::init (const CArray
& c
)
491 if (d
!= &c
[c () - 1])
493 name
= (const char *) c
.array () + 5;
498 STR_GroupObject::decode ()
501 sprintf (buf
, "GROUP_OBJECT %d: id=%s\n", no
, name ());
506 STR_GroupObject::toArray ()
509 uint16_t len
= 4 + strlen (name ());
511 d
[0] = (len
>> 8) & 0xff;
513 d
[2] = (L_GROUP_OBJECT
>> 8) & 0xff;
514 d
[3] = (L_GROUP_OBJECT
) & 0xff;
516 d
.setpart ((const uchar
*) name (), 5, strlen (name ()) + 1);
520 STR_BCU1Size::STR_BCU1Size ()
529 STR_BCU1Size::init (const CArray
& c
)
533 textsize
= c
[4] << 8 | c
[5];
534 stacksize
= c
[6] << 8 | c
[7];
535 datasize
= c
[8] << 8 | c
[9];
536 bsssize
= c
[10] << 8 | c
[11];
541 STR_BCU1Size::toArray ()
546 d
[0] = (len
>> 8) & 0xff;
548 d
[2] = (L_BCU1_SIZE
>> 8) & 0xff;
549 d
[3] = (L_BCU1_SIZE
) & 0xff;
550 d
[4] = (textsize
>> 8) & 0xff;
551 d
[5] = (textsize
) & 0xff;
552 d
[6] = (stacksize
>> 8) & 0xff;
553 d
[7] = (stacksize
) & 0xff;
554 d
[8] = (datasize
>> 8) & 0xff;
555 d
[9] = (datasize
) & 0xff;
556 d
[10] = (bsssize
>> 8) & 0xff;
557 d
[11] = (bsssize
) & 0xff;
562 STR_BCU1Size::decode ()
565 sprintf (buf
, "BCU1_SIZE: text:%d stack:%d data:%d bss:%d\n", textsize
,
566 stacksize
, datasize
, bsssize
);
570 STR_BCU2Size::STR_BCU2Size ()
581 STR_BCU2Size::init (const CArray
& c
)
585 textsize
= c
[4] << 8 | c
[5];
586 stacksize
= c
[6] << 8 | c
[7];
587 lo_datasize
= c
[8] << 8 | c
[9];
588 lo_bsssize
= c
[10] << 8 | c
[11];
589 hi_datasize
= c
[12] << 8 | c
[13];
590 hi_bsssize
= c
[14] << 8 | c
[15];
595 STR_BCU2Size::toArray ()
600 d
[0] = (len
>> 8) & 0xff;
602 d
[2] = (L_BCU2_SIZE
>> 8) & 0xff;
603 d
[3] = (L_BCU2_SIZE
) & 0xff;
604 d
[4] = (textsize
>> 8) & 0xff;
605 d
[5] = (textsize
) & 0xff;
606 d
[6] = (stacksize
>> 8) & 0xff;
607 d
[7] = (stacksize
) & 0xff;
608 d
[8] = (lo_datasize
>> 8) & 0xff;
609 d
[9] = (lo_datasize
) & 0xff;
610 d
[10] = (lo_bsssize
>> 8) & 0xff;
611 d
[11] = (lo_bsssize
) & 0xff;
612 d
[12] = (hi_datasize
>> 8) & 0xff;
613 d
[13] = (hi_datasize
) & 0xff;
614 d
[14] = (hi_bsssize
>> 8) & 0xff;
615 d
[15] = (hi_bsssize
) & 0xff;
620 STR_BCU2Size::decode ()
624 "BCU2_SIZE: text:%d stack:%d lo_data:%d lo_bss:%d hi_data:%d hi_bss:%d\n",
625 textsize
, stacksize
, lo_datasize
, lo_bsssize
, hi_datasize
,
630 STR_BCU2Start::STR_BCU2Start ()
658 STR_BCU2Start::init (const CArray
& c
)
662 addrtab_start
= c
[4] << 8 | c
[5];
663 addrtab_size
= c
[6] << 8 | c
[7];
664 assoctab_start
= c
[8] << 8 | c
[9];
665 assoctab_size
= c
[10] << 8 | c
[11];
666 readonly_start
= c
[12] << 8 | c
[13];
667 readonly_end
= c
[14] << 8 | c
[15];
668 param_start
= c
[16] << 8 | c
[17];
669 param_end
= c
[18] << 8 | c
[19];
670 obj_ptr
= c
[20] << 8 | c
[21];
671 obj_count
= c
[22] << 8 | c
[23];
672 appcallback
= c
[24] << 8 | c
[25];
673 groupobj_ptr
= c
[26] << 8 | c
[27];
674 seg0
= c
[28] << 8 | c
[29];
675 seg1
= c
[30] << 8 | c
[31];
676 sphandler
= c
[32] << 8 | c
[33];
677 initaddr
= c
[34] << 8 | c
[35];
678 runaddr
= c
[36] << 8 | c
[37];
679 saveaddr
= c
[38] << 8 | c
[39];
680 eeprom_start
= c
[40] << 8 | c
[41];
681 eeprom_end
= c
[42] << 8 | c
[43];
682 poll_addr
= c
[44] << 8 | c
[45];
688 STR_BCU2Start::toArray ()
693 d
[0] = (len
>> 8) & 0xff;
695 d
[2] = (L_BCU2_INIT
>> 8) & 0xff;
696 d
[3] = (L_BCU2_INIT
) & 0xff;
697 d
[4] = (addrtab_start
>> 8) & 0xff;
698 d
[5] = (addrtab_start
) & 0xff;
699 d
[6] = (addrtab_size
>> 8) & 0xff;
700 d
[7] = (addrtab_size
) & 0xff;
701 d
[8] = (assoctab_start
>> 8) & 0xff;
702 d
[9] = (assoctab_start
) & 0xff;
703 d
[10] = (assoctab_size
>> 8) & 0xff;
704 d
[11] = (assoctab_size
) & 0xff;
705 d
[12] = (readonly_start
>> 8) & 0xff;
706 d
[13] = (readonly_start
) & 0xff;
707 d
[14] = (readonly_end
>> 8) & 0xff;
708 d
[15] = (readonly_end
) & 0xff;
709 d
[16] = (param_start
>> 8) & 0xff;
710 d
[17] = (param_start
) & 0xff;
711 d
[18] = (param_end
>> 8) & 0xff;
712 d
[19] = (param_end
) & 0xff;
713 d
[20] = (obj_ptr
>> 8) & 0xff;
714 d
[21] = (obj_ptr
) & 0xff;
715 d
[22] = (obj_count
>> 8) & 0xff;
716 d
[23] = (obj_count
) & 0xff;
717 d
[24] = (appcallback
>> 8) & 0xff;
718 d
[25] = (appcallback
) & 0xff;
719 d
[26] = (groupobj_ptr
>> 8) & 0xff;
720 d
[27] = (groupobj_ptr
) & 0xff;
721 d
[28] = (seg0
>> 8) & 0xff;
722 d
[29] = (seg0
) & 0xff;
723 d
[30] = (seg1
>> 8) & 0xff;
724 d
[31] = (seg1
) & 0xff;
725 d
[32] = (sphandler
>> 8) & 0xff;
726 d
[33] = (sphandler
) & 0xff;
727 d
[34] = (initaddr
>> 8) & 0xff;
728 d
[35] = (initaddr
) & 0xff;
729 d
[36] = (runaddr
>> 8) & 0xff;
730 d
[37] = (runaddr
) & 0xff;
731 d
[38] = (saveaddr
>> 8) & 0xff;
732 d
[39] = (saveaddr
) & 0xff;
733 d
[40] = (eeprom_start
>> 8) & 0xff;
734 d
[41] = (eeprom_start
) & 0xff;
735 d
[42] = (eeprom_end
>> 8) & 0xff;
736 d
[43] = (eeprom_end
) & 0xff;
737 d
[44] = (poll_addr
>> 8) & 0xff;
738 d
[45] = (poll_addr
) & 0xff;
739 d
[46] = (poll_slot
) & 0xff;
744 STR_BCU2Start::decode ()
748 "BCU2_INIT: init:%04X run:%04X save:%04X addr_tab:%04X(%d) assoc_tab:%04X(%d) text:%04X-%04X\n"
749 " param:%04X-%04X obj:%04X(%d) appcallback:%04X\n"
750 " groupobj:%04X seg0:%04X seg1:%04X sphandler:%04X eeprom:%04X-%04X poll_addr:%04X poll_slot:%d\n",
751 initaddr
, runaddr
, saveaddr
, addrtab_start
, addrtab_size
,
752 assoctab_start
, assoctab_size
, readonly_start
, readonly_end
,
753 param_start
, param_end
, obj_ptr
, obj_count
, appcallback
,
754 groupobj_ptr
, seg0
, seg1
, sphandler
, eeprom_start
, eeprom_end
,
755 poll_addr
, poll_slot
);
759 STR_BCU2Key::STR_BCU2Key ()
761 installkey
= 0xFFFFFFFF;
765 STR_BCU2Key::init (const CArray
& c
)
772 installkey
= (c
[4] << 24) | (c
[5] << 16) | (c
[6] << 8) | (c
[7]);
773 for (i
= 8; i
< c (); i
+= 4)
774 keys
.add ((c
[i
] << 24) | (c
[i
+ 1] << 16) | (c
[i
+ 2] << 8) | (c
[i
+ 3]));
779 STR_BCU2Key::toArray ()
783 uint16_t len
= keys () * 4 + 4 + 2;
785 d
[0] = (len
>> 8) & 0xff;
787 d
[2] = (L_BCU2_KEY
>> 8) & 0xff;
788 d
[3] = (L_BCU2_KEY
) & 0xff;
789 d
[4] = (installkey
>> 24) & 0xff;
790 d
[5] = (installkey
>> 16) & 0xff;
791 d
[6] = (installkey
>> 8) & 0xff;
792 d
[7] = (installkey
>> 0) & 0xff;
793 for (i
= 0; i
< keys (); i
++)
795 d
[8 + 4 * i
] = (keys
[i
] >> 24) & 0xff;
796 d
[9 + 4 * i
] = (keys
[i
] >> 16) & 0xff;
797 d
[10 + 4 * i
] = (keys
[i
] >> 8) & 0xff;
798 d
[11 + 4 * i
] = (keys
[i
] >> 0) & 0xff;
805 STR_BCU2Key::decode ()
810 sprintf (buf
, "BCU2_KEY: install:%08X ", installkey
);
812 for (i
= 0; i
< keys (); i
++)
814 sprintf (buf
, "level%d: %08X ", i
, keys
[i
]);
826 for (int i
= 0; i
< str (); i
++)
834 String s
= "BCU Memory Image\n";
835 for (int i
= 0; i
< str (); i
++)
836 s
+= str
[i
]->decode ();
853 for (int i
= 0; i
< str (); i
++)
854 data
.setpart (str
[i
]->toArray (), data ());
855 data
[8] = (data () >> 8) & 0xff;
856 data
[9] = (data ()) & 0xff;
861 Image::findStreamNumber (STR_Type t
)
863 for (int i
= 0; i
< str (); i
++)
864 if (str
[i
]->getType () == t
)
870 Image::findStream (STR_Type t
)
872 int i
= findStreamNumber (t
);
880 Image::fromArray (CArray c
)
902 if (c
[8] != ((c () >> 8) & 0xff))
904 if (c
[9] != ((c ()) & 0xff))
906 Image
*i
= new Image
;
914 len
= c
[pos
] << 8 | c
[pos
+ 1];
915 if (pos
+ 2 + len
> c () || len
< 2)
920 i
->str
.add (STR_Stream::fromArray (CArray (&c
[pos
], len
+ 2)));
929 return findStreamNumber (S_Invalid
) == -1;