allow coexistance of N build and AC build.
[tomato.git] / release / src / router / rc / mmc.c
blob44e9d416e6ae891d04c444f8e111eb7dfa529a66
1 /*
3 Tomato Firmware modified - AKA: ugly hacks
4 Copyright (C) 2007 Augusto Bott
5 Modified by Tomasz S³odkowicz for SDHC/MMC driver v2.0.1
7 */
9 #include "rc.h"
11 #include <sys/mount.h>
13 static void error(const char *message)
15 char s[512];
17 snprintf(s, sizeof(s), "Error %s SDHC/MMC. Check the logs to see if they contain more details about this error.", message);
18 notice_set("mmc", s);
21 void start_mmc(void)
23 char s[32];
24 char p[4][10];
25 const char *mmc_cs;
26 const char *mmc_cl;
27 const char *mmc_di;
28 const char *mmc_do;
29 const char *mmc_fs_type;
30 const char *mmc_part_number;
31 const char *mmc_exec_mount;
33 if (!nvram_match("mmc_on", "1")) {
34 notice_set("mmc", "");
35 return;
37 if (((mmc_cs = nvram_get("mmc_cs")) != NULL) && (*mmc_cs != 0) &&
38 ((mmc_cl = nvram_get("mmc_clk")) != NULL) && (*mmc_cl != 0) &&
39 ((mmc_di = nvram_get("mmc_din")) != NULL) && (*mmc_di != 0) &&
40 ((mmc_do = nvram_get("mmc_dout")) != NULL) && (*mmc_do != 0)) {
41 snprintf(p[0], sizeof(p[0]), "cs=%s", mmc_cs);
42 snprintf(p[1], sizeof(p[1]), "clk=%s", mmc_cl);
43 snprintf(p[2], sizeof(p[2]), "din=%s", mmc_di);
44 snprintf(p[3], sizeof(p[3]), "dout=%s", mmc_do);
45 } else *p[0]=*p[1]=*p[2]=*p[3]=0;
46 if (eval("modprobe", "-s", "mmc", "major=121", "dbg=1", p[0], p[1], p[2], p[3]) != 0) {
47 error("loading module for");
48 return;
50 if (((mmc_fs_type = nvram_get("mmc_fs_type")) != NULL) && (*mmc_fs_type != 0) &&
51 ((mmc_part_number = nvram_get("mmc_fs_partition")) != NULL) && (*mmc_part_number != 0)) {
52 if (modprobe(mmc_fs_type) != 0 ) {
53 modprobe_r("mmc");
54 error("loading filesystem module for");
55 return;
57 snprintf(s, sizeof(s), "/dev/mmc/disc0/part%s", mmc_part_number);
58 if (mount(s, "/opt", mmc_fs_type, MS_NOATIME|MS_NODIRATIME, "") != 0) {
59 modprobe_r(mmc_fs_type);
60 modprobe_r("mmc");
61 error("mounting");
62 return;
64 if (((mmc_exec_mount = nvram_get("mmc_exec_mount")) != NULL) && (*mmc_exec_mount != 0)) {
65 chdir("/opt");
66 xstart(mmc_exec_mount);
67 chdir("/");
70 notice_set("mmc", "");
73 void stop_mmc(void)
75 if (!wait_action_idle(10)) return;
76 eval(nvram_safe_get("mmc_exec_umount"));
77 notice_set("mmc", "");
78 eval("/bin/sync");
79 if (umount ("/opt") != 0) {
80 error("unmounting");
81 return;
82 } else {
83 modprobe_r("mmc");
84 modprobe_r(nvram_safe_get("mmc_fs_type"));