summaryrefslogtreecommitdiffstats
path: root/Src/osmocom-bb/src/target/firmware/apps
diff options
context:
space:
mode:
Diffstat (limited to 'Src/osmocom-bb/src/target/firmware/apps')
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/chainload/main.c53
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/compal_dsp_dump/main.c62
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/hello_world/main.c149
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/l1test/main.c276
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/layer1/main.c162
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/loader/main.c444
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/loader/protocol.h37
-rw-r--r--Src/osmocom-bb/src/target/firmware/apps/loader_mtk/main.c366
-rwxr-xr-xSrc/osmocom-bb/src/target/firmware/apps/simtest/main.c307
9 files changed, 0 insertions, 1856 deletions
diff --git a/Src/osmocom-bb/src/target/firmware/apps/chainload/main.c b/Src/osmocom-bb/src/target/firmware/apps/chainload/main.c
deleted file mode 100644
index 5121837..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/chainload/main.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Compal ramloader -> Calypso romloader Chainloading application */
-
-/* (C) 2010 by Steve Markgraf <steve@steve-m.de>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-
-#include <calypso/clock.h>
-
-/* Main Program */
-
-static void device_enter_loader(unsigned char bootrom) {
- calypso_bootrom(bootrom);
- void (*entry)( void ) = (void (*)(void))0;
- entry();
-}
-
-int main(void)
-{
- /* Always disable wdt (some platforms enable it on boot) */
- wdog_enable(0);
-
- /* enable Calypso romloader mapping and jump there */
- delay_ms(200);
- device_enter_loader(1);
-
- /* Not reached */
- while(1) {
- }
-}
diff --git a/Src/osmocom-bb/src/target/firmware/apps/compal_dsp_dump/main.c b/Src/osmocom-bb/src/target/firmware/apps/compal_dsp_dump/main.c
deleted file mode 100644
index c823d0a..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/compal_dsp_dump/main.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* main program of Free Software for Calypso Phone */
-
-/* (C) 2010 Harald Welte <laforge@gnumonks.org>
- * (C) 2010 Sylvain Munaut <tnt@246tNt.com>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <memory.h>
-#include <delay.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-#include <abb/twl3025.h>
-#include <rf/trf6151.h>
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/dsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-#include <comm/timer.h>
-
-/* Main Program */
-const char *hr = "======================================================================\n";
-
-int main(void)
-{
- board_init();
-
- puts("\n\nOSMOCOM Compal DSP Dumper (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Dump device identification */
- dump_dev_id();
- puts(hr);
-
- /* Dump DSP content */
- dsp_dump();
-
- while (1) {
- update_timers();
- }
-}
-
diff --git a/Src/osmocom-bb/src/target/firmware/apps/hello_world/main.c b/Src/osmocom-bb/src/target/firmware/apps/hello_world/main.c
deleted file mode 100644
index 5e3ed85..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/hello_world/main.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* main program of Free Software for Calypso Phone */
-
-/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-#include <abb/twl3025.h>
-#include <display.h>
-#include <rf/trf6151.h>
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/dsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-#include <comm/sercomm.h>
-#include <comm/timer.h>
-
-/* Main Program */
-const char *hr = "======================================================================\n";
-
-void key_handler(enum key_codes code, enum key_states state);
-
-static void console_rx_cb(uint8_t dlci, struct msgb *msg)
-{
- if (dlci != SC_DLCI_CONSOLE) {
- printf("Message for unknown DLCI %u\n", dlci);
- return;
- }
-
- printf("Message on console DLCI: '%s'\n", msg->data);
- display_puts((char *) msg->data);
- msgb_free(msg);
-}
-
-static void l1a_l23_rx_cb(uint8_t dlci, struct msgb *msg)
-{
- int i;
- puts("l1a_l23_rx_cb: ");
- for (i = 0; i < msg->len; i++)
- printf("%02x ", msg->data[i]);
- puts("\n");
-}
-
-int main(void)
-{
- board_init();
-
- puts("\n\nOSMOCOM Hello World (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Dump device identification */
- dump_dev_id();
- puts(hr);
-
- /* Dump clock config before PLL set */
- calypso_clk_dump();
- puts(hr);
-
- keypad_set_handler(&key_handler);
-
- /* Dump clock config after PLL set */
- calypso_clk_dump();
- puts(hr);
-
- /* Dump all memory */
- //dump_mem();
-#if 0
- /* Dump Bootloader */
- memdump_range((void *)0x00000000, 0x2000);
- puts(hr);
-#endif
-
- display_set_attr(DISP_ATTR_INVERT);
- display_puts("Hello World");
-
- sercomm_register_rx_cb(SC_DLCI_CONSOLE, console_rx_cb);
- sercomm_register_rx_cb(SC_DLCI_L1A_L23, l1a_l23_rx_cb);
-
- /* beyond this point we only react to interrupts */
- puts("entering interrupt loop\n");
- while (1) {
- update_timers();
- }
-
- twl3025_power_off();
-
- while (1) {}
-}
-
-void key_handler(enum key_codes code, enum key_states state)
-{
- char test[16];
-
- if (state != PRESSED)
- return;
-
- switch (code) {
- case KEY_0:
- case KEY_1:
- case KEY_2:
- case KEY_3:
- case KEY_4:
- case KEY_5:
- case KEY_6:
- case KEY_7:
- case KEY_8:
- case KEY_9:
- sprintf(test, "%d", code - KEY_0);
- display_puts(test);
- break;
- case KEY_STAR:
- sprintf(test, "*", 0);
- display_puts(test);
- break;
- case KEY_HASH:
- sprintf(test, "#", 0);
- display_puts(test);
- break;
- default:
- break;
- }
-}
diff --git a/Src/osmocom-bb/src/target/firmware/apps/l1test/main.c b/Src/osmocom-bb/src/target/firmware/apps/l1test/main.c
deleted file mode 100644
index 97bc528..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/l1test/main.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/* main program of Free Software for Calypso Phone */
-
-/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-
-#include <abb/twl3025.h>
-#include <display.h>
-#include <rf/trf6151.h>
-
-#include <comm/sercomm.h>
-#include <comm/timer.h>
-
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-
-#include <layer1/sync.h>
-#include <layer1/tpu_window.h>
-
-#define SCAN
-
-#ifdef SCAN
-/* if scanning is enabled, scan from 0 ... 124 */
-#define BASE_ARFCN 0
-#else
-/* fixed ARFCN in GSM1800 at which Harald has his GSM test license */
-#define BASE_ARFCN 871
-#endif
-
-/* Main Program */
-const char *hr = "======================================================================\n";
-
-/* Best ARFCN MAP ************************************************************/
-
-struct arfcn_map {
- uint16_t arfcn;
- int16_t dbm8;
-};
-
-static struct arfcn_map best_arfcn_map[10];
-static void best_arfcn_update(uint16_t arfcn, int16_t dbm8)
-{
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(best_arfcn_map); i++) {
- if (best_arfcn_map[i].dbm8 < dbm8 ||
- best_arfcn_map[i].dbm8 == 0) {
- best_arfcn_map[i].dbm8 = dbm8;
- best_arfcn_map[i].arfcn = arfcn;
- return;
- }
- }
-}
-
-static void best_arfcn_dump(void)
-{
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(best_arfcn_map); i++) {
- if (best_arfcn_map[i].dbm8 == 0)
- continue;
- printf("ARFCN %3d: %d dBm\n",
- best_arfcn_map[i].arfcn,
- best_arfcn_map[i].dbm8/8);
- }
-}
-
-
-/* MAIN program **************************************************************/
-
-enum l1test_state {
- STATE_NONE,
- STATE_PM,
- STATE_FB,
-};
-
-static void l1test_state_change(enum l1test_state new_state)
-{
- switch (new_state) {
- case STATE_PM:
- puts("Performing power measurement over GSM900\n");
- l1s_pm_test(1, BASE_ARFCN);
- break;
- case STATE_FB:
- puts("Starting FCCH Recognition\n");
- l1s_fb_test(1, 0);
- break;
- case STATE_NONE:
- /* disable frame interrupts */
- tpu_frame_irq_en(0, 0);
- break;
- }
-}
-
-/* completion call-back for the L1 Sync Power Measurement */
-static void l1s_signal_cb(struct l1_signal *sig)
-{
- uint16_t i, next_arfcn;
-
- switch (sig->signum) {
- case L1_SIG_PM:
- best_arfcn_update(sig->arfcn, sig->pm.dbm8[0]);
- next_arfcn = sig->arfcn + 1;
-
- if (next_arfcn >= 124) {
- puts("ARFCN Top 10 Rx Level\n");
- best_arfcn_dump();
-
- trf6151_rx_window(0, best_arfcn_map[0].arfcn, 40, 0);
- tpu_end_scenario();
-
- /* PM phase completed, do FB det */
- l1test_state_change(STATE_FB);
-
- break;
- }
-
- /* restart Power Measurement */
- l1s_pm_test(1, next_arfcn);
- break;
- case L1_SIG_NB:
- puts("NB SNR ");
- for (i = 0; i < 4; i++) {
- uint16_t snr = sig->nb.meas[i].snr;
- printf("%d.%03u ", l1s_snr_int(snr), l1s_snr_fract(snr));
- }
- putchar('\n');
- printf("--> Frame %d %d 0x%04X ", sig->nb.fire, sig->nb.crc, sig->nb.num_biterr);
- for (i = 0; i < ARRAY_SIZE(sig->nb.frame); i++)
- printf("%02X ", sig->nb.frame[i]);
- putchar('\n');
- break;
- }
-}
-
-static void key_handler(enum key_codes code, enum key_states state);
-
-int main(void)
-{
- board_init();
-
- puts("\n\nHello World from " __FILE__ " program code\n");
-
- puts(hr);
- /* Dump device identification */
- dump_dev_id();
- puts(hr);
-
- keypad_set_handler(&key_handler);
-
- /* Dump clock config after PLL set */
- calypso_clk_dump();
- puts(hr);
-
- display_set_attr(DISP_ATTR_INVERT);
- display_puts("l1test.bin");
-
- layer1_init();
- l1s_set_handler(&l1s_signal_cb);
-
- //dsp_checksum_task();
-#ifdef SCAN
- l1test_state_change(STATE_PM);
-#else
- l1test_state_change(STATE_FB);
-#endif
- tpu_frame_irq_en(1, 1);
-
- while (1) {
- update_timers();
- }
-
- /* NOT REACHED */
-
- twl3025_power_off();
-}
-
-static int8_t vga_gain = 40;
-static int high_gain = 0;
-static int afcout = 0;
-
-static void update_vga_gain(void)
-{
- printf("VGA Gain: %u %s\n", vga_gain, high_gain ? "HIGH" : "LOW");
- trf6151_set_gain(vga_gain, high_gain);
- tpu_enq_sleep();
- tpu_enable(1);
- tpu_wait_idle();
-}
-
-static void tspact_toggle(uint8_t num)
-{
- printf("TSPACT%u toggle\n", num);
- tsp_act_toggle((1 << num));
- tpu_enq_sleep();
- tpu_enable(1);
- tpu_wait_idle();
-}
-
-static void key_handler(enum key_codes code, enum key_states state)
-{
- if (state != PRESSED)
- return;
-
- switch (code) {
- case KEY_1: /* VGA gain decrement */
- vga_gain -= 2;
- if (vga_gain < 14)
- vga_gain = 14;
- update_vga_gain();
- break;
- case KEY_2: /* High/Low Rx gain */
- high_gain ^= 1;
- update_vga_gain();
- break;
- case KEY_3: /* VGA gain increment */
- vga_gain += 2;
- if (vga_gain > 40)
- vga_gain = 40;
- update_vga_gain();
- break;
- case KEY_4:
- tspact_toggle(6); /* TRENA (RFFE) */
- break;
- case KEY_5:
- tspact_toggle(8); /* GSM_TXEN (RFFE) */
- break;
- case KEY_6:
- tspact_toggle(1); /* PAENA (RFFE) */
- break;
- case KEY_7: /* decrement AFC OUT */
- afcout -= 100;
- if (afcout < -4096)
- afcout = -4096;
- twl3025_afc_set(afcout);
- printf("AFC OUT: %u\n", twl3025_afcout_get());
- break;
- case KEY_9: /* increase AFC OUT */
- afcout += 100;
- if (afcout > 4095)
- afcout = 4095;
- twl3025_afc_set(afcout);
- printf("AFC OUT: %u\n", twl3025_afcout_get());
- break;
- default:
- break;
- }
-}
diff --git a/Src/osmocom-bb/src/target/firmware/apps/layer1/main.c b/Src/osmocom-bb/src/target/firmware/apps/layer1/main.c
deleted file mode 100644
index 385278f..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/layer1/main.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/* main program of Free Software for Calypso Phone */
-
-/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-
-#include <abb/twl3025.h>
-#include <display.h>
-#include <rf/trf6151.h>
-
-#include <comm/sercomm.h>
-#include <comm/timer.h>
-
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-
-#include <layer1/sync.h>
-#include <layer1/tpu_window.h>
-
-const char *hr = "======================================================================\n";
-
-/* MAIN program **************************************************************/
-
-static void key_handler(enum key_codes code, enum key_states state);
-
-int main(void)
-{
- board_init();
-
- puts("\n\nOSMOCOM Layer 1 (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Dump device identification */
- dump_dev_id();
- puts(hr);
-
- keypad_set_handler(&key_handler);
-
- /* Dump clock config after PLL set */
- calypso_clk_dump();
- puts(hr);
-
- display_puts("layer1.bin");
-
- layer1_init();
-
- display_unset_attr(DISP_ATTR_INVERT);
-
- tpu_frame_irq_en(1, 1);
-
- while (1) {
- l1a_compl_execute();
- update_timers();
- }
-
- /* NOT REACHED */
-
- twl3025_power_off();
-}
-
-static int8_t vga_gain = 40;
-static int high_gain = 0;
-static int afcout = 0;
-
-static void update_vga_gain(void)
-{
- printf("VGA Gain: %u %s\n", vga_gain, high_gain ? "HIGH" : "LOW");
- trf6151_set_gain(vga_gain, high_gain);
- tpu_enq_sleep();
- tpu_enable(1);
- tpu_wait_idle();
-}
-
-static void tspact_toggle(uint8_t num)
-{
- printf("TSPACT%u toggle\n", num);
- tsp_act_toggle((1 << num));
- tpu_enq_sleep();
- tpu_enable(1);
- tpu_wait_idle();
-}
-
-static void key_handler(enum key_codes code, enum key_states state)
-{
- if (state != PRESSED)
- return;
-
- switch (code) {
- case KEY_1: /* VGA gain decrement */
- vga_gain -= 2;
- if (vga_gain < 14)
- vga_gain = 14;
- update_vga_gain();
- break;
- case KEY_2: /* High/Low Rx gain */
- high_gain ^= 1;
- update_vga_gain();
- break;
- case KEY_3: /* VGA gain increment */
- vga_gain += 2;
- if (vga_gain > 40)
- vga_gain = 40;
- update_vga_gain();
- break;
- case KEY_4:
- tspact_toggle(6); /* TRENA (RFFE) */
- break;
- case KEY_5:
- tspact_toggle(8); /* GSM_TXEN (RFFE) */
- break;
- case KEY_6:
- tspact_toggle(1); /* PAENA (RFFE) */
- break;
- case KEY_7: /* decrement AFC OUT */
- afcout -= 100;
- if (afcout < -4096)
- afcout = -4096;
- twl3025_afc_set(afcout);
- printf("AFC OUT: %u\n", twl3025_afcout_get());
- break;
- case KEY_9: /* increase AFC OUT */
- afcout += 100;
- if (afcout > 4095)
- afcout = 4095;
- twl3025_afc_set(afcout);
- printf("AFC OUT: %u\n", twl3025_afcout_get());
- break;
- default:
- break;
- }
-}
-
-
diff --git a/Src/osmocom-bb/src/target/firmware/apps/loader/main.c b/Src/osmocom-bb/src/target/firmware/apps/loader/main.c
deleted file mode 100644
index 2ff6f9c..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/loader/main.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/* boot loader for Calypso phones */
-
-/* (C) 2010 by Ingo Albrecht <prom@berlin.ccc.de>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-#include <console.h>
-#include <manifest.h>
-
-#include <osmocom/core/crc16.h>
-
-#include <abb/twl3025.h>
-#include <rf/trf6151.h>
-
-#include <comm/sercomm.h>
-
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-#include <uart.h>
-#include <calypso/timer.h>
-
-#include <flash/cfi_flash.h>
-
-#include "protocol.h"
-
-/* Main Program */
-const char *hr =
- "======================================================================\n";
-
-static void key_handler(enum key_codes code, enum key_states state);
-static void cmd_handler(uint8_t dlci, struct msgb *msg);
-
-int flag = 0;
-
-static void flush_uart(void)
-{
- unsigned i;
- for (i = 0; i < 500; i++) {
- uart_poll(SERCOMM_UART_NR);
- delay_ms(1);
- }
-}
-
-static void device_poweroff(void)
-{
- flush_uart();
- twl3025_power_off();
-}
-
-static void device_reset(void)
-{
- flush_uart();
- wdog_reset();
-}
-
-static void device_enter_loader(unsigned char bootrom)
-{
- flush_uart();
-
- calypso_bootrom(bootrom);
- void (*entry) (void) = (void (*)(void))0;
- entry();
-}
-
-static void device_jump(void *entry)
-{
- flush_uart();
-
- void (*f) (void) = (void (*)(void))entry;
- f();
-}
-
-static void loader_send_simple(struct msgb *msg, uint8_t dlci, uint8_t command)
-{
- msgb_put_u8(msg, command);
- sercomm_sendmsg(dlci, msg);
-}
-
-extern unsigned char _start;
-
-static void loader_send_init(uint8_t dlci)
-{
- struct msgb *msg = sercomm_alloc_msgb(9);
- msgb_put_u8(msg, LOADER_INIT);
- msgb_put_u32(msg, 0);
- msgb_put_u32(msg, &_start);
- sercomm_sendmsg(dlci, msg);
-}
-
-flash_t the_flash;
-
-extern void putchar_asm(uint32_t c);
-
-static const uint8_t phone_ack[] = { 0x1b, 0xf6, 0x02, 0x00, 0x41, 0x03, 0x42 };
-
-int main(void)
-{
- /* Simulate a compal loader saying "ACK" */
- int i = 0;
- for (i = 0; i < sizeof(phone_ack); i++) {
- putchar_asm(phone_ack[i]);
- }
-
- /* Always disable wdt (some platforms enable it on boot) */
- wdog_enable(0);
-
- /* Disable the bootrom mapping */
- calypso_bootrom(0);
-
- /* Initialize TWL3025 for power control */
- twl3025_init();
-
- /* Backlight */
- bl_mode_pwl(1);
- bl_level(50);
-
- /* Initialize UART without interrupts */
- uart_init(SERCOMM_UART_NR, 0);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
-
- /* Initialize HDLC subsystem */
- sercomm_init();
-
- /* Say hi */
- puts("\n\nOSMOCOM Loader (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Identify environment */
- printf("Running on %s in environment %s\n", manifest_board,
- manifest_environment);
-
- /* Initialize flash driver */
- if (flash_init(&the_flash, 0)) {
- puts("Failed to initialize flash!\n");
- } else {
- printf("Found flash of %d bytes at 0x%x with %d regions\n",
- the_flash.f_size, the_flash.f_base,
- the_flash.f_nregions);
-
- int i;
- for (i = 0; i < the_flash.f_nregions; i++) {
- printf(" Region %d of %d pages with %d bytes each.\n",
- i,
- the_flash.f_regions[i].fr_bnum,
- the_flash.f_regions[i].fr_bsize);
- }
-
- }
-
- /* Set up a key handler for powering off */
- keypad_set_handler(&key_handler);
-
- /* Set up loader communications */
- sercomm_register_rx_cb(SC_DLCI_LOADER, &cmd_handler);
-
- /* Notify any running osmoload about our startup */
- loader_send_init(SC_DLCI_LOADER);
-
- /* Wait for events */
- while (1) {
- keypad_poll();
- uart_poll(SERCOMM_UART_NR);
- }
-
- /* NOT REACHED */
-
- twl3025_power_off();
-}
-
-static void cmd_handler(uint8_t dlci, struct msgb *msg)
-{
- if (msg->data_len < 1) {
- return;
- }
-
- uint8_t command = msgb_get_u8(msg);
-
- int res;
-
- flash_lock_t lock;
-
- void *data;
-
- uint8_t chip;
- uint8_t nbytes;
- uint16_t crc, mycrc;
- uint32_t address;
-
- struct msgb *reply = sercomm_alloc_msgb(256); // XXX
-
- if (!reply) {
- printf("Failed to allocate reply buffer!\n");
- goto out;
- }
-
- switch (command) {
-
- case LOADER_PING:
- loader_send_simple(reply, dlci, LOADER_PING);
- break;
-
- case LOADER_RESET:
- loader_send_simple(reply, dlci, LOADER_RESET);
- device_reset();
- break;
-
- case LOADER_POWEROFF:
- loader_send_simple(reply, dlci, LOADER_POWEROFF);
- device_poweroff();
- break;
-
- case LOADER_ENTER_ROM_LOADER:
- loader_send_simple(reply, dlci, LOADER_ENTER_ROM_LOADER);
- device_enter_loader(1);
- break;
-
- case LOADER_ENTER_FLASH_LOADER:
- loader_send_simple(reply, dlci, LOADER_ENTER_FLASH_LOADER);
- device_enter_loader(0);
- break;
-
- case LOADER_MEM_READ:
-
- nbytes = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- crc = osmo_crc16(0, (void *)address, nbytes);
-
- msgb_put_u8(reply, LOADER_MEM_READ);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, crc);
- msgb_put_u32(reply, address);
-
- memcpy(msgb_put(reply, nbytes), (void *)address, nbytes);
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_MEM_WRITE:
-
- nbytes = msgb_get_u8(msg);
- crc = msgb_get_u16(msg);
- address = msgb_get_u32(msg);
-
- data = msgb_get(msg, nbytes);
-
- mycrc = osmo_crc16(0, data, nbytes);
-
- if (mycrc == crc) {
- memcpy((void *)address, data, nbytes);
- }
-
- msgb_put_u8(reply, LOADER_MEM_WRITE);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, mycrc);
- msgb_put_u32(reply, address);
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_JUMP:
-
- address = msgb_get_u32(msg);
-
- msgb_put_u8(reply, LOADER_JUMP);
- msgb_put_u32(reply, address);
-
- sercomm_sendmsg(dlci, reply);
-
- device_jump((void *)address);
-
- break;
-
- case LOADER_FLASH_INFO:
-
- msgb_put_u8(reply, LOADER_FLASH_INFO);
- msgb_put_u8(reply, 1); // nchips
-
- // chip 1
- msgb_put_u32(reply, the_flash.f_base);
- msgb_put_u32(reply, the_flash.f_size);
- msgb_put_u8(reply, the_flash.f_nregions);
-
- int i;
- for (i = 0; i < the_flash.f_nregions; i++) {
- msgb_put_u32(reply, the_flash.f_regions[i].fr_bnum);
- msgb_put_u32(reply, the_flash.f_regions[i].fr_bsize);
- }
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_ERASE:
- case LOADER_FLASH_UNLOCK:
- case LOADER_FLASH_LOCK:
- case LOADER_FLASH_LOCKDOWN:
-
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- if (command == LOADER_FLASH_ERASE) {
- res = flash_block_erase(&the_flash, address);
- }
- if (command == LOADER_FLASH_UNLOCK) {
- res = flash_block_unlock(&the_flash, address);
- }
- if (command == LOADER_FLASH_LOCK) {
- res = flash_block_lock(&the_flash, address);
- }
- if (command == LOADER_FLASH_LOCKDOWN) {
- res = flash_block_lockdown(&the_flash, address);
- }
-
- msgb_put_u8(reply, command);
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
- msgb_put_u32(reply, (res != 0));
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_GETLOCK:
-
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- lock = flash_block_getlock(&the_flash, address);
-
- msgb_put_u8(reply, command);
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
-
- switch (lock) {
- case FLASH_UNLOCKED:
- msgb_put_u32(reply, LOADER_FLASH_UNLOCKED);
- break;
- case FLASH_LOCKED:
- msgb_put_u32(reply, LOADER_FLASH_LOCKED);
- break;
- case FLASH_LOCKED_DOWN:
- msgb_put_u32(reply, LOADER_FLASH_LOCKED_DOWN);
- break;
- default:
- msgb_put_u32(reply, 0xFFFFFFFF);
- break;
- }
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_PROGRAM:
-
- nbytes = msgb_get_u8(msg);
- crc = msgb_get_u16(msg);
- msgb_get_u8(msg); // XXX align
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- data = msgb_get(msg, nbytes);
-
- mycrc = osmo_crc16(0, data, nbytes);
-
- if (mycrc == crc) {
- res = flash_program(&the_flash, address, data, nbytes);
- }
-
- msgb_put_u8(reply, LOADER_FLASH_PROGRAM);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, mycrc);
- msgb_put_u8(reply, 0); // XXX align
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
-
- msgb_put_u32(reply, (uint32_t) res); // XXX
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- default:
- printf("unknown command %d\n", command);
-
- msgb_free(reply);
-
- break;
- }
-
- out:
-
- msgb_free(msg);
-}
-
-static void key_handler(enum key_codes code, enum key_states state)
-{
- if (state != PRESSED)
- return;
-
- switch (code) {
- case KEY_POWER:
- puts("Powering off due to keypress.\n");
- device_poweroff();
- break;
- case KEY_OK:
- puts("Resetting due to keypress.\n");
- device_reset();
- break;
- default:
- break;
- }
-}
diff --git a/Src/osmocom-bb/src/target/firmware/apps/loader/protocol.h b/Src/osmocom-bb/src/target/firmware/apps/loader/protocol.h
deleted file mode 100644
index 0a61c89..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/loader/protocol.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-enum loader_command {
- /* init message from loader */
- LOADER_INIT,
-
- /* ping / pong */
- LOADER_PING,
-
- /* lifecycle requests */
- LOADER_RESET,
- LOADER_POWEROFF,
-
- /* jumps */
- LOADER_JUMP,
- LOADER_ENTER_ROM_LOADER,
- LOADER_ENTER_FLASH_LOADER,
-
- /* generic memory ops */
- LOADER_MEM_READ,
- LOADER_MEM_WRITE,
-
- /* flash operations */
- LOADER_FLASH_INFO,
- LOADER_FLASH_ERASE,
- LOADER_FLASH_UNLOCK,
- LOADER_FLASH_LOCK,
- LOADER_FLASH_LOCKDOWN,
- LOADER_FLASH_GETLOCK,
- LOADER_FLASH_PROGRAM,
-
-};
-
-enum loader_flash_lock {
- LOADER_FLASH_UNLOCKED = 0,
- LOADER_FLASH_LOCKED,
- LOADER_FLASH_LOCKED_DOWN,
-};
diff --git a/Src/osmocom-bb/src/target/firmware/apps/loader_mtk/main.c b/Src/osmocom-bb/src/target/firmware/apps/loader_mtk/main.c
deleted file mode 100644
index 9bfaa7e..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/loader_mtk/main.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * boot loader for MTK phones (based on the calypso-version)
- *
- * (C) 2010 by Ingo Albrecht <prom@berlin.ccc.de>
- * (C) 2011 by Wolfram Sang <wolfram@the-dreams.de>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <keypad.h>
-#include <board.h>
-#include <console.h>
-#include <defines.h>
-#include <manifest.h>
-
-#include <osmocom/core/crc16.h>
-
-#include <comm/sercomm.h>
-
-#include <uart.h>
-
-#include <flash/cfi_flash.h>
-
-#include <mtk/emi.h>
-#include <mtk/mt6235.h>
-#include <mtk/system.h>
-
-#include "../loader/protocol.h"
-
-/* Main Program */
-const char *hr =
- "======================================================================\n";
-
-static void cmd_handler(uint8_t dlci, struct msgb *msg);
-
-int flag = 0;
-
-static void flush_uart(void)
-{
- unsigned i;
- for (i = 0; i < 500; i++) {
- uart_poll(SERCOMM_UART_NR);
- delay_ms(1);
- }
-}
-
-static void device_poweroff(void)
-{
- flush_uart();
- writew(BBPU_MAGIC | RTC_BBPU_WRITE_EN,
- MTK_RTC_BBPU);
- writew(1, MTK_RTC_WRTGR);
-}
-
-static void device_reset(void)
-{
- flush_uart();
-}
-
-static void device_enter_loader(__unused unsigned char bootrom)
-{
- flush_uart();
- delay_ms(2000);
- void (*entry)( void ) = (void (*)(void))0;
- entry();
-}
-
-static void device_jump(void *entry)
-{
- flush_uart();
-
- void (*f) (void) = (void (*)(void))entry;
- f();
-}
-
-static void loader_send_simple(struct msgb *msg, uint8_t dlci, uint8_t command)
-{
- msgb_put_u8(msg, command);
- sercomm_sendmsg(dlci, msg);
-}
-
-extern unsigned char _start;
-
-flash_t the_flash;
-
-extern void putchar_asm(uint32_t c);
-
-static const uint8_t phone_ack[] = { 0x1b, 0xf6, 0x02, 0x00, 0x41, 0x03, 0x42 };
-
-int main(void)
-{
- board_init ();
-
- /* Initialize HDLC subsystem */
- sercomm_init();
-
- /* Say hi */
- puts("\n\nOSMOCOM Loader (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Identify environment */
- printf("\nRunning on %s in environment %s\n", manifest_board,
- manifest_environment);
-
- printf("\nHW_CODE = 0x%04x", readw(MTK_CONFG_HW_CODE));
-
- /* Set up loader communications */
- sercomm_register_rx_cb(SC_DLCI_LOADER, &cmd_handler);
-
- /* Wait for events */
-
- while (1) {
- uart_poll(SERCOMM_UART_NR);
- }
-
-}
-
-static void cmd_handler(uint8_t dlci, struct msgb *msg)
-{
- if (msg->data_len < 1) {
- return;
- }
-
- uint8_t command = msgb_get_u8(msg);
-
- int res;
-
- flash_lock_t lock;
-
- void *data;
-
- uint8_t chip;
- uint8_t nbytes;
- uint16_t crc, mycrc;
- uint32_t address;
-
- struct msgb *reply = sercomm_alloc_msgb(256); // XXX
-
- if (!reply) {
- printf("Failed to allocate reply buffer!\n");
- goto out;
- }
-
- switch (command) {
-
- case LOADER_PING:
- loader_send_simple(reply, dlci, LOADER_PING);
- break;
-
- case LOADER_RESET:
- loader_send_simple(reply, dlci, LOADER_RESET);
- device_reset();
- break;
-
- case LOADER_POWEROFF:
- loader_send_simple(reply, dlci, LOADER_POWEROFF);
- device_poweroff();
- break;
-
- case LOADER_ENTER_ROM_LOADER:
- loader_send_simple(reply, dlci, LOADER_ENTER_ROM_LOADER);
- device_enter_loader(1);
- break;
-
- case LOADER_ENTER_FLASH_LOADER:
- loader_send_simple(reply, dlci, LOADER_ENTER_FLASH_LOADER);
- device_enter_loader(0);
- break;
-
- case LOADER_MEM_READ:
-
- nbytes = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- crc = osmo_crc16(0, (void *)address, nbytes);
-
- msgb_put_u8(reply, LOADER_MEM_READ);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, crc);
- msgb_put_u32(reply, address);
-
- memcpy(msgb_put(reply, nbytes), (void *)address, nbytes);
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_MEM_WRITE:
-
- nbytes = msgb_get_u8(msg);
- crc = msgb_get_u16(msg);
- address = msgb_get_u32(msg);
-
- data = msgb_get(msg, nbytes);
-
- mycrc = osmo_crc16(0, data, nbytes);
-
- if (mycrc == crc) {
- memcpy((void *)address, data, nbytes);
- }
-
- msgb_put_u8(reply, LOADER_MEM_WRITE);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, mycrc);
- msgb_put_u32(reply, address);
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_JUMP:
-
- address = msgb_get_u32(msg);
-
- msgb_put_u8(reply, LOADER_JUMP);
- msgb_put_u32(reply, address);
-
- sercomm_sendmsg(dlci, reply);
-
- device_jump((void *)address);
-
- break;
-
- case LOADER_FLASH_INFO:
-
- msgb_put_u8(reply, LOADER_FLASH_INFO);
- msgb_put_u8(reply, 1); // nchips
-
- // chip 1
- msgb_put_u32(reply, the_flash.f_base);
- msgb_put_u32(reply, the_flash.f_size);
- msgb_put_u8(reply, the_flash.f_nregions);
-
- unsigned i;
- for (i = 0; i < the_flash.f_nregions; i++) {
- msgb_put_u32(reply, the_flash.f_regions[i].fr_bnum);
- msgb_put_u32(reply, the_flash.f_regions[i].fr_bsize);
- }
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_ERASE:
- case LOADER_FLASH_UNLOCK:
- case LOADER_FLASH_LOCK:
- case LOADER_FLASH_LOCKDOWN:
-
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- if (command == LOADER_FLASH_ERASE) {
- res = flash_block_erase(&the_flash, address);
- }
- if (command == LOADER_FLASH_UNLOCK) {
- res = flash_block_unlock(&the_flash, address);
- }
- if (command == LOADER_FLASH_LOCK) {
- res = flash_block_lock(&the_flash, address);
- }
- if (command == LOADER_FLASH_LOCKDOWN) {
- res = flash_block_lockdown(&the_flash, address);
- }
-
- msgb_put_u8(reply, command);
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
- msgb_put_u32(reply, (res != 0));
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_GETLOCK:
-
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- lock = flash_block_getlock(&the_flash, address);
-
- msgb_put_u8(reply, command);
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
-
- switch (lock) {
- case FLASH_UNLOCKED:
- msgb_put_u32(reply, LOADER_FLASH_UNLOCKED);
- break;
- case FLASH_LOCKED:
- msgb_put_u32(reply, LOADER_FLASH_LOCKED);
- break;
- case FLASH_LOCKED_DOWN:
- msgb_put_u32(reply, LOADER_FLASH_LOCKED_DOWN);
- break;
- default:
- msgb_put_u32(reply, 0xFFFFFFFF);
- break;
- }
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- case LOADER_FLASH_PROGRAM:
-
- nbytes = msgb_get_u8(msg);
- crc = msgb_get_u16(msg);
- msgb_get_u8(msg); // XXX align
- chip = msgb_get_u8(msg);
- address = msgb_get_u32(msg);
-
- data = msgb_get(msg, nbytes);
-
- mycrc = osmo_crc16(0, data, nbytes);
-
- if (mycrc == crc) {
- res = flash_program(&the_flash, address, data, nbytes);
- }
-
- msgb_put_u8(reply, LOADER_FLASH_PROGRAM);
- msgb_put_u8(reply, nbytes);
- msgb_put_u16(reply, mycrc);
- msgb_put_u8(reply, 0); // XXX align
- msgb_put_u8(reply, chip);
- msgb_put_u32(reply, address);
-
- msgb_put_u32(reply, (uint32_t) res); // XXX
-
- sercomm_sendmsg(dlci, reply);
-
- break;
-
- default:
- printf("unknown command %d\n", command);
-
- msgb_free(reply);
-
- break;
- }
-
- out:
-
- msgb_free(msg);
-}
diff --git a/Src/osmocom-bb/src/target/firmware/apps/simtest/main.c b/Src/osmocom-bb/src/target/firmware/apps/simtest/main.c
deleted file mode 100755
index 83f708e..0000000
--- a/Src/osmocom-bb/src/target/firmware/apps/simtest/main.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/* SIM test application */
-
-/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <debug.h>
-#include <memory.h>
-#include <delay.h>
-#include <rffe.h>
-#include <keypad.h>
-#include <board.h>
-#include <abb/twl3025.h>
-#include <display.h>
-#include <rf/trf6151.h>
-#include <calypso/clock.h>
-#include <calypso/tpu.h>
-#include <calypso/tsp.h>
-#include <calypso/dsp.h>
-#include <calypso/irq.h>
-#include <calypso/misc.h>
-#include <comm/sercomm.h>
-#include <comm/timer.h>
-
-#include <calypso/sim.h>
-
-#define DEBUG
-
-/* Dump bytes in hex on the console */
-static void myHexdump(uint8_t *data, int len)
-{
- int i;
-
- for(i=0;i<len;i++)
- printf("%x ",data[i]);
-
- printf("(%i bytes)\n", len);
-
- return;
-}
-
-/* SIM instructions
- All instructions a standard sim card must feature: */
-#define SIM_CLASS 0xA0 /* Class that contains the following instructions */
-#define SIM_SELECT 0xA4 /* Select a file on the card */
-#define SIM_STATUS 0xF2 /* Get the status of the currently selected file */
-#define SIM_READ_BINARY 0xB0 /* Read file in binary mode */
-#define SIM_UPDATE_BINARY 0xD6 /* Write file in binary mode */
-#define SIM_READ_RECORD 0xB2 /* Read record of a record based file */
-#define SIM_UPDATE_RECORD 0xDC /* Write record of a record based file */
-#define SIM_SEEK 0xA2 /* Seek in a record based file */
-#define SIM_INCREASE 0x32 /* Increase a record in a record based file */
-#define SIM_VERIFY_CHV 0x20 /* Authenticate with card (enter pin) */
-#define SIM_CHANGE_CHV 0x24 /* Change pin */
-#define SIM_DISABLE_CHV 0x26 /* Disable pin so that no authentication is needed anymore */
-#define SIM_ENABLE_CHV 0x28 /* Enable pin, authentication is now needed again */
-#define SIM_UNBLOCK_CHV 0x2C /* Unblock pin when it is blocked by entering a wrong pin three times */
-#define SIM_INVALIDATE 0x04 /* Invalidate the current elementry file (file in a subdirectory) */
-#define SIM_REHABILITATE 0x44 /* Rehabilitate the current elementry file (file in a subdirectory) */
-#define SIM_RUN_GSM_ALGORITHM 0x88 /* Run the GSM A3 authentication algorithm in the card */
-#define SIM_SLEEP 0xFA /* Sleep command (only used in Phase 1 GSM) */
-#define SIM_GET_RESPONSE 0xC0 /* Get the response of a command from the card */
-
-/* File identifiers (filenames)
- The file identifiers are the standardized file identifiers mentioned in the
- GSM-11-11 specification. */
-#define SIM_MF 0x3F00
-#define SIM_EF_ICCID 0x2FE2
-#define SIM_DF_TELECOM 0x7F10
-#define SIM_EF_ADN 0x6F3A
-#define SIM_EF_FDN 0x6F3B
-#define SIM_EF_SMS 0x6F3C
-#define SIM_EF_CCP 0x6F3D
-#define SIM_EF_MSISDN 0x6F40
-#define SIM_EF_SMSP 0x6F42
-#define SIM_EF_SMSS 0x6F43
-#define SIM_EF_LND 0x6F44
-#define SIM_EF_EXT1 0x6F4A
-#define SIM_EF_EXT2 0x6F4B
-#define SIM_DF_GSM 0x7F20
-#define SIM_EF_LP 0x6F05
-#define SIM_EF_IMSI 0x6F07
-#define SIM_EF_KC 0x6F20
-#define SIM_EF_PLMNsel 0x6F30
-#define SIM_EF_HPLMN 0x6F31
-#define SIM_EF_ACMmax 0x6F37
-#define SIM_EF_SST 0x6F38
-#define SIM_EF_ACM 0x6F39
-#define SIM_EF_GID1 0x6F3E
-#define SIM_EF_GID2 0x6F3F
-#define SIM_EF_PUCT 0x6F41
-#define SIM_EF_CBMI 0x6F45
-#define SIM_EF_SPN 0x6F46
-#define SIM_EF_BCCH 0x6F74
-#define SIM_EF_ACC 0x6F78
-#define SIM_EF_FPLMN 0x6F7B
-#define SIM_EF_LOCI 0x6F7E
-#define SIM_EF_AD 0x6FAD
-#define SIM_EF_PHASE 0x6FAE
-
-/* Select a file on the card */
-uint16_t sim_select(uint16_t fid)
-{
- uint8_t txBuffer[2];
- uint8_t status_word[2];
-
- txBuffer[1] = (uint8_t) fid;
- txBuffer[0] = (uint8_t) (fid >> 8);
-
- if(calypso_sim_transceive(SIM_CLASS, SIM_SELECT, 0x00, 0x00, 0x02,
- txBuffer, status_word, SIM_APDU_PUT) != 0)
- return 0xFFFF;
-
- return (status_word[0] << 8) | status_word[1];
-}
-
-/* Get the status of the currently selected file */
-uint16_t sim_status(void)
-{
- uint8_t status_word[2];
-
- if(calypso_sim_transceive(SIM_CLASS, SIM_STATUS, 0x00, 0x00, 0x00, 0,
- status_word, SIM_APDU_PUT) != 0)
- return 0xFFFF;
-
- return (status_word[0] << 8) | status_word[1];
-}
-
-/* Read file in binary mode */
-uint16_t sim_readbinary(uint8_t offset_high, uint8_t offset_low, uint8_t length, uint8_t *data)
-{
- uint8_t status_word[2];
- if(calypso_sim_transceive(SIM_CLASS, SIM_READ_BINARY, offset_high,
- offset_low, length, data ,status_word,
- SIM_APDU_GET) != 0)
- return 0xFFFF;
-
- return (status_word[0] << 8) | status_word[1];
-}
-
-/* Execute my (dexter's) personal test */
-void do_sim_test(void)
-{
- uint8_t testBuffer[20];
- uint8_t testtxBuffer[20];
-
- uint8_t testDataBody[257];
- uint8_t testStatusWord[2];
- int recivedChars;
- int i;
-
- uint8_t atr[20];
- uint8_t atrLength = 0;
-
- memset(atr,0,sizeof(atr));
-
-
-
- uint8_t buffer[20];
-
-
- memset(testtxBuffer,0,sizeof(testtxBuffer));
-
- puts("----------------SIMTEST----8<-----------------\n");
-
- /* Initialize Sim-Controller driver */
- puts("Initializing driver:\n");
- calypso_sim_init();
-
- /* Power up sim and display ATR */
- puts("Power up simcard:\n");
- memset(atr,0,sizeof(atr));
- atrLength = calypso_sim_powerup(atr);
- myHexdump(atr,atrLength);
-
- /* Reset sim and display ATR */
- puts("Reset simcard:\n");
- memset(atr,0,sizeof(atr));
- atrLength = calypso_sim_reset(atr);
- myHexdump(atr,atrLength);
-
-
-
- testDataBody[0] = 0x3F;
- testDataBody[1] = 0x00;
- calypso_sim_transceive(0xA0, 0xA4, 0x00, 0x00, 0x02, testDataBody,0, SIM_APDU_PUT);
- calypso_sim_transceive(0xA0, 0xC0, 0x00, 0x00, 0x0f, testDataBody,0, SIM_APDU_GET);
- myHexdump(testDataBody,0x0F);
-
- puts("Test Phase 1: Testing bare sim commands...\n");
-
- puts(" * Testing SELECT: Selecting MF\n");
- printf(" ==> Status word: %x\n", sim_select(SIM_MF));
-
- puts(" * Testing SELECT: Selecting DF_GSM\n");
- printf(" ==> Status word: %x\n", sim_select(SIM_DF_GSM));
-
- puts(" * Testing SELECT: Selecting EF_IMSI\n");
- printf(" ==> Status word: %x\n", sim_select(SIM_EF_IMSI));
-
- puts(" * Testing STATUS:\n");
- printf(" ==> Status word: %x\n", sim_status());
-
- memset(buffer,0,sizeof(buffer));
- puts(" * Testing READ BINARY:\n");
- printf(" ==> Status word: %x\n", sim_readbinary(0,0,9,buffer));
- printf(" Data: ");
- myHexdump(buffer,9);
-
- delay_ms(5000);
-
- calypso_sim_powerdown();
-
- puts("------------END SIMTEST----8<-----------------\n");
-}
-
-/* Main Program */
-const char *hr = "======================================================================\n";
-
-void key_handler(enum key_codes code, enum key_states state);
-
-static void *console_rx_cb(uint8_t dlci, struct msgb *msg)
-{
- if (dlci != SC_DLCI_CONSOLE) {
- printf("Message for unknown DLCI %u\n", dlci);
- return;
- }
-
- printf("Message on console DLCI: '%s'\n", msg->data);
- msgb_free(msg);
-}
-
-int main(void)
-{
- board_init();
-
- puts("\n\nOSMOCOM SIM Test (revision " GIT_REVISION ")\n");
- puts(hr);
-
- /* Dump device identification */
- dump_dev_id();
- puts(hr);
-
- /* Dump clock config before PLL set */
- calypso_clk_dump();
- puts(hr);
-
- keypad_set_handler(&key_handler);
-
- /* Dump clock config after PLL set */
- calypso_clk_dump();
- puts(hr);
-
- /* Dump all memory */
- //dump_mem();
-#if 0
- /* Dump Bootloader */
- memdump_range((void *)0x00000000, 0x2000);
- puts(hr);
-#endif
-
- display_set_attr(DISP_ATTR_INVERT);
- display_puts("SIM-TEST");
-
- sercomm_register_rx_cb(SC_DLCI_CONSOLE, console_rx_cb);
-
- do_sim_test();
-
- /* beyond this point we only react to interrupts */
- puts("entering interrupt loop\n");
- while (1) {
- }
-
- twl3025_power_off();
- while (1) {}
-}
-
-void key_handler(enum key_codes code, enum key_states state)
-{
- if (state != PRESSED)
- return;
-
- switch (code) {
- default:
- break;
- }
-}