/* get ptbl from rsv area from emmc */ static int get_ptbl_rsv(struct mmc *mmc, struct _iptbl *rsv) { struct ptbl_rsv * ptbl_rsv = NULL; uchar * buffer = NULL; ulong size, offset; int checksum, version, ret = 0; struct virtual_partition *vpart = aml_get_virtual_partition_by_name(MMC_TABLE_NAME); size = (sizeof(struct ptbl_rsv) + 511) / 512 * 512; if (vpart->size < size) { apt_err("too much partitons\n"); ret = -1; goto _out; } buffer = malloc(size); if (NULL == buffer) { apt_err("no enough memory for ptbl rsv\n"); ret = -2; goto _out; } /* read it from emmc. */ offset = _get_inherent_offset(MMC_RESERVED_NAME) + vpart->offset; if (size != _mmc_rsv_read(mmc, offset, size, buffer)) { apt_err("read ptbl from rsv failed\n"); ret = -3; goto _out; } ptbl_rsv = (struct ptbl_rsv *) buffer; apt_info("magic %3.3s, version %8.8s, checksum %x\n", ptbl_rsv->magic, ptbl_rsv->version, ptbl_rsv->checksum); /* fixme, check magic ?*/ if (strcmp(ptbl_rsv->magic, MMC_PARTITIONS_MAGIC)) { apt_err("magic faild %s, %3.3s\n", MMC_PARTITIONS_MAGIC, ptbl_rsv->magic); ret = -4; goto _out; } /* check version*/ version = _get_version(ptbl_rsv->version); if (version < 0) { apt_err("version faild %s, %3.3s\n", MMC_PARTITIONS_MAGIC, ptbl_rsv->magic); ret = -5; goto _out; } /* check sum */ checksum = _calc_iptbl_check(ptbl_rsv->partitions, ptbl_rsv->count, version); if (checksum != ptbl_rsv->checksum) { apt_err("checksum faild 0x%x, 0x%x\n", ptbl_rsv->checksum, checksum); ret = -6; goto _out; } rsv->count = ptbl_rsv->count; memcpy(rsv->partitions, ptbl_rsv->partitions, rsv->count * sizeof(struct partitions)); _out: if (buffer) free (buffer); return ret; }
/* update partition tables from src if success, return 0; else, return 1 */ static int update_ptbl_rsv(struct mmc *mmc, struct _iptbl *src) { struct ptbl_rsv *ptbl_rsv = NULL; uchar *buffer; ulong size, offset; int ret = 0, version; struct virtual_partition *vpart = aml_get_virtual_partition_by_name(MMC_TABLE_NAME); size = (sizeof(struct ptbl_rsv) + 511) / 512 * 512; buffer = malloc(size); if (NULL == buffer) { apt_err("no enough memory for ptbl rsv\n"); return -1; } memset(buffer, 0 , size); /* version, magic and checksum */ ptbl_rsv = (struct ptbl_rsv *) buffer; strcpy((char *)ptbl_rsv->version, MMC_MPT_VERSION); strcpy(ptbl_rsv->magic, MMC_PARTITIONS_MAGIC); ptbl_rsv->count = src->count; memcpy(ptbl_rsv->partitions, src->partitions, sizeof(struct partitions)*src->count); version = _get_version(ptbl_rsv->version); ptbl_rsv->checksum = _calc_iptbl_check(src->partitions, src->count, version); /* write it to emmc. */ apt_info("magic %3.3s, version %8.8s, checksum %x\n", ptbl_rsv->magic, ptbl_rsv->version, ptbl_rsv->checksum); offset = _get_inherent_offset(MMC_RESERVED_NAME) + vpart->offset; if (_mmc_rsv_write(mmc, offset, size, buffer) != size) { apt_err("write ptbl to rsv failed\n"); ret = -1; goto _err; } _err: free (buffer); return ret; }
int8_t RogueSD::sync(void) { // procedure: // 1. sync (send ESC, clear prompt) // 2. get version ("v"), and module type // 3. change settings as needed // 4. check status // 5. close files (if needed - E08, or other error, not needed) // 0. empty any data in the serial buffer _comm_flush(); // 1. sync _comm_write(0x1b); // send ESC to clear buffer on uMMC _read_blocked(); // consume prompt // 2. get version (ignore prompt - just drop it) _get_version(); // 3. change settings as needed // OLD: write timeout setting = 10 ms timeout // NEW: listing style = old style (0) if ((_moduletype == uMMC && _fwversion < UMMC_MIN_FW_VERSION_FOR_NEW_COMMANDS) || (_moduletype == uMP3 && _fwversion < UMP3_MIN_FW_VERSION_FOR_NEW_COMMANDS)) { // we need to set the write timeout to allow us to control when a line is finished // in writeln. changesetting('1', 1); // 10 ms timeout } else { // we're using the new version // Let's make sure the Listing Style setting is set to the old style if (getsetting('L') != 0) { changesetting('L', 0); } // get the prompt char print('S'); if (_moduletype != uMMC) { print('T'); }; print('P'); print('\r'); // get our prompt (if possible) _promptchar = _getnumber(10); _read_blocked(); // consume prompt } // 4. check status if (_moduletype != uMMC) { print("FC"); }; print('Z'); print('\r'); // Get status if (_get_response()) return -1; else { // good _read_blocked(); // consume prompt // 5. close all files closeall(); // ensure all handles are closed return 0; } }
/** Load the XML rule set for a resource and store attributes, constructing a new resource_t structure. @param filename File name to load rules from @param rules Rule list to add new rules to @return 0 */ static int load_resource_rulefile(char *filename, resource_rule_t ** rules) { resource_rule_t *rr = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr ctx = NULL; int ruleid = 0; char *type; char base[256]; doc = read_resource_agent_metadata(filename); if (!doc) return 0; ctx = xmlXPathNewContext(doc); do { /* Look for resource types */ snprintf(base, sizeof(base), "/resource-agent[%d]/@name", ++ruleid); type = xpath_get_one(doc, ctx, base); if (!type) break; if (!strcasecmp(type, "action")) { fprintf(stderr, "Error: Resource type '%s' is reserved", type); free(type); break; } rr = malloc(sizeof(*rr)); if (!rr) break; memset(rr, 0, sizeof(*rr)); rr->rr_flags = RF_INIT | RF_DESTROY; rr->rr_type = type; snprintf(base, sizeof(base), "/resource-agent[%d]", ruleid); /* First, grab the global attributes if existent */ _get_version(doc, ctx, base, rr); snprintf(base, sizeof(base), "/resource-agent[%d]/special[@tag=\"rgmanager\"]", ruleid); _get_maxparents(doc, ctx, base, rr); _get_rule_flag(doc, ctx, base, rr, "init_on_add", RF_INIT); _get_rule_flag(doc, ctx, base, rr, "destroy_on_delete", RF_DESTROY); rr->rr_agent = strdup(filename); /* Second, add the children fields */ _get_childtypes(doc, ctx, base, rr); /* Get the OCF status check intervals/monitor. */ snprintf(base, sizeof(base), "/resource-agent[%d]/actions", ruleid); _get_actions(doc, ctx, base, rr); /* Last, load the attributes from our XML file and their respective instantiations from CCS */ snprintf(base, sizeof(base), "/resource-agent[%d]/parameters", ruleid); if (_get_rule_attrs(doc, ctx, base, rr) < 0) { destroy_resource_rule(rr); rr = NULL; } if (!rr) continue; if (store_rule(rules, rr) != 0) { destroy_resource_rule(rr); rr = NULL; } } while (1); if (ctx) xmlXPathFreeContext(ctx); if (doc) xmlFreeDoc(doc); return 0; }