freemyipod r963 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r962‎ | r963 | r964 >
Date:21:15, 19 July 2014
Author:theseven
Status:new
Tags:
Comment:
emCORE: Allow booting if there's no battery present
Modified paths:
  • /emcore/trunk/init.c (modified) (history)

Diff [purge]

Index: emcore/trunk/init.c
@@ -54,6 +54,11 @@
5555 #endif
5656
5757
 58+#ifndef BATTERY_BOOT_LOCKOUT_THRESHOLD
 59+#define BATTERY_BOOT_LOCKOUT_THRESHOLD 0
 60+#endif
 61+
 62+
5863 extern int _poolstart; // Not an int at all, but gcc complains about void types being
5964 // used here, and we only need the address, so just make it happy...
6065
@@ -119,25 +124,35 @@
120125 void storageinitthread(void* arg0, void* arg1, void* arg2, void* arg3)
121126 {
122127 struct initbss* ib = (struct initbss*)arg0;
123 - int threshold = 0;
124 - DEBUGF("Battery state: %d mV, %d mAh", read_battery_voltage(0), read_battery_mwh_current(0));
125 - if (read_battery_mwh_current(0) <= threshold)
 128+ DEBUGF("Battery state: %d, %d mV, %d mAh", read_battery_state(0),
 129+ read_battery_voltage(0), read_battery_mwh_current(0));
 130+ switch (read_battery_state(0))
126131 {
127 - backlight_set_brightness(50);
128 - cputs(CONSOLE_BOOT, "The battery is discharged.\n"
129 - "Please connect to a power supply\n"
130 - "and wait a few minutes.\n");
131 - while (read_battery_mwh_current(0) <= threshold)
 132+ case BATTERY_STATE_NONPRESENT:
 133+ cputs(CONSOLE_BOOT, "No battery connected.\n");
 134+ break;
 135+ case BATTERY_STATE_IDLE:
 136+ case BATTERY_STATE_CHARGING:
 137+ case BATTERY_STATE_DISCHARGING:
 138+ if (read_battery_mwh_current(0) <= BATTERY_BOOT_LOCKOUT_THRESHOLD)
132139 {
133 - DEBUGF("Battery state: %d mV, %d mAh", read_battery_voltage(0), read_battery_mwh_current(0));
134 - sleep(10000000);
135 - if (read_input_state(0) != INPUT_STATE_ACTIVE)
 140+ backlight_set_brightness(50);
 141+ cputs(CONSOLE_BOOT, "The battery is discharged.\n"
 142+ "Please connect to a power supply\n"
 143+ "and wait a few minutes.\n");
 144+ while (read_battery_mwh_current(0) <= BATTERY_BOOT_LOCKOUT_THRESHOLD)
136145 {
137 - shutdown(true);
138 - power_off();
 146+ DEBUGF("Battery state: %d, %d mV, %d mAh", read_battery_state(0),
 147+ read_battery_voltage(0), read_battery_mwh_current(0));
 148+ sleep(10000000);
 149+ if (read_battery_state(0) != BATTERY_STATE_CHARGING)
 150+ {
 151+ shutdown(true);
 152+ power_off();
 153+ }
139154 }
 155+ backlight_set_brightness(100);
140156 }
141 - backlight_set_brightness(100);
142157 }
143158 DEBUGF("Initializing storage drivers...");
144159 int rc = storage_init();
@@ -148,10 +163,13 @@
149164 }
150165 DEBUGF("Initializing storage subsystem...");
151166 disk_init_subsystem();
152 - DEBUGF("Reading partition tables...");
153 - disk_init();
154167 DEBUGF("Mounting partitions...");
155 - disk_mount_all();
 168+ rc = disk_mount_all();
 169+ if (IS_ERR(rc))
 170+ {
 171+ DEBUGF("FS mount error: %08X\n", rc);
 172+ cprintf(CONSOLE_BOOT, "FS mount error: %08X\n", rc);
 173+ }
156174 DEBUGF("Storage init finished.");
157175 wakeup_signal(&(ib->storagewakeup));
158176 }