cregit-Linux how code gets into the kernel

Release 4.10 scripts/dtc/data.c

Directory: scripts/dtc
/*
 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
 *
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *                                                                   USA
 */

#include "dtc.h"


void data_free(struct data d) { struct marker *m, *nm; m = d.markers; while (m) { nm = m->next; free(m->ref); free(m); m = nm; } if (d.val) free(d.val); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson64100.00%1100.00%
Total64100.00%1100.00%


struct data data_grow_for(struct data d, int xlen) { struct data nd; int newsize; if (xlen == 0) return d; nd = d; newsize = xlen; while ((d.len + xlen) > newsize) newsize *= 2; nd.val = xrealloc(d.val, newsize); return nd; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson69100.00%1100.00%
Total69100.00%1100.00%


struct data data_copy_mem(const char *mem, int len) { struct data d; d = data_grow_for(empty_data, len); d.len = len; memcpy(d.val, mem, len); return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson47100.00%1100.00%
Total47100.00%1100.00%


struct data data_copy_escape_string(const char *s, int len) { int i = 0; struct data d; char *q; d = data_grow_for(empty_data, len + 1); q = d.val; while (i < len) { char c = s[i++]; if (c == '\\') c = get_escape_char(s, &i); q[d.len++] = c; } q[d.len++] = '\0'; return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson9797.00%133.33%
stephen warrenstephen warren22.00%133.33%
rob herringrob herring11.00%133.33%
Total100100.00%3100.00%


struct data data_copy_file(FILE *f, size_t maxlen) { struct data d = empty_data; while (!feof(f) && (d.len < maxlen)) { size_t chunksize, ret; if (maxlen == -1) chunksize = 4096; else chunksize = maxlen - d.len; d = data_grow_for(d, chunksize); ret = fread(d.val + d.len, 1, chunksize, f); if (ferror(f)) die("Error reading file into data: %s", strerror(errno)); if (d.len + ret < d.len) die("Overflow reading file into data\n"); d.len += ret; } return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson133100.00%2100.00%
Total133100.00%2100.00%


struct data data_append_data(struct data d, const void *p, int len) { d = data_grow_for(d, len); memcpy(d.val + d.len, p, len); d.len += len; return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson51100.00%1100.00%
Total51100.00%1100.00%


struct data data_insert_at_marker(struct data d, struct marker *m, const void *p, int len) { d = data_grow_for(d, len); memmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset); memcpy(d.val + m->offset, p, len); d.len += len; /* Adjust all markers after the one we're inserting at */ m = m->next; for_each_marker(m) m->offset += len; return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson102100.00%1100.00%
Total102100.00%1100.00%


static struct data data_append_markers(struct data d, struct marker *m) { struct marker **mp = &d.markers; /* Find the end of the markerlist */ while (*mp) mp = &((*mp)->next); *mp = m; return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson5298.11%150.00%
josh triplettjosh triplett11.89%150.00%
Total53100.00%2100.00%


struct data data_merge(struct data d1, struct data d2) { struct data d; struct marker *m2 = d2.markers; d = data_append_markers(data_append_data(d1, d2.val, d2.len), m2); /* Adjust for the length of d1 */ for_each_marker(m2) m2->offset += d1.len; d2.markers = NULL; /* So data_free() doesn't clobber them */ data_free(d2); return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson75100.00%1100.00%
Total75100.00%1100.00%


struct data data_append_integer(struct data d, uint64_t value, int bits) { uint8_t value_8; uint16_t value_16; uint32_t value_32; uint64_t value_64; switch (bits) { case 8: value_8 = value; return data_append_data(d, &value_8, 1); case 16: value_16 = cpu_to_fdt16(value); return data_append_data(d, &value_16, 2); case 32: value_32 = cpu_to_fdt32(value); return data_append_data(d, &value_32, 4); case 64: value_64 = cpu_to_fdt64(value); return data_append_data(d, &value_64, 8); default: die("Invalid literal size (%d)\n", bits); } }

Contributors

PersonTokensPropCommitsCommitProp
stephen warrenstephen warren9980.49%133.33%
david gibsondavid gibson2419.51%266.67%
Total123100.00%3100.00%


struct data data_append_re(struct data d, const struct fdt_reserve_entry *re) { struct fdt_reserve_entry bere; bere.address = cpu_to_fdt64(re->address); bere.size = cpu_to_fdt64(re->size); return data_append_data(d, &bere, sizeof(bere)); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson56100.00%2100.00%
Total56100.00%2100.00%


struct data data_append_cell(struct data d, cell_t word) { return data_append_integer(d, word, sizeof(word) * 8); }

Contributors

PersonTokensPropCommitsCommitProp
stephen warrenstephen warren28100.00%1100.00%
Total28100.00%1100.00%


struct data data_append_addr(struct data d, uint64_t addr) { return data_append_integer(d, addr, sizeof(addr) * 8); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson2382.14%266.67%
stephen warrenstephen warren517.86%133.33%
Total28100.00%3100.00%


struct data data_append_byte(struct data d, uint8_t byte) { return data_append_data(d, &byte, 1); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson24100.00%1100.00%
Total24100.00%1100.00%


struct data data_append_zeroes(struct data d, int len) { d = data_grow_for(d, len); memset(d.val + d.len, 0, len); d.len += len; return d; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson46100.00%1100.00%
Total46100.00%1100.00%


struct data data_append_align(struct data d, int align) { int newlen = ALIGN(d.len, align); return data_append_zeroes(d, newlen - d.len); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson37100.00%1100.00%
Total37100.00%1100.00%


struct data data_add_marker(struct data d, enum markertype type, char *ref) { struct marker *m; m = xmalloc(sizeof(*m)); m->offset = d.len; m->type = type; m->ref = ref; m->next = NULL; return data_append_markers(d, m); }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson68100.00%1100.00%
Total68100.00%1100.00%


bool data_is_one_string(struct data d) { int i; int len = d.len; if (len == 0) return false; for (i = 0; i < len-1; i++) if (d.val[i] == '\0') return false; if (d.val[len-1] != '\0') return false; return true; }

Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson7193.42%150.00%
rob herringrob herring56.58%150.00%
Total76100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
david gibsondavid gibson104388.09%240.00%
stephen warrenstephen warren13411.32%120.00%
rob herringrob herring60.51%120.00%
josh triplettjosh triplett10.08%120.00%
Total1184100.00%5100.00%
Directory: scripts/dtc
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.